Jump to content

Welcome to Smart Home Forum by FIBARO

Dear Guest,

 

as you can notice parts of Smart Home Forum by FIBARO is not available for you. You have to register in order to view all content and post in our community. Don't worry! Registration is a simple free process that requires minimal information for you to sign up. Become a part of of Smart Home Forum by FIBARO by creating an account.

 

As a member you can:

  •     Start new topics and reply to others
  •     Follow topics and users to get email updates
  •     Get your own profile page and make new friends
  •     Send personal messages
  •     ... and learn a lot about our system!

 

Regards,

Smart Home Forum by FIBARO Team


  • 0

LUA: Why lights is not Turn Off after 10 sec.


Question

Posted

Hello

I make simple script in LUA. The idea is:

1. If Lux < 250 and have movemeng Light turn on.

2. If no Movement more then 10 seconds and lights is ON then Light turn off.

First part works ok, but second part Lights turn off after 45, 60 sec.

Can you help me please:

Please login or register to see this code.

4 answers to this question

Recommended Posts

  • 0
Posted

kmeta, what value is set in parameter 6 in your motion sensor?

  • 0
Posted

You scene only triggers on an event. So once triggered, it will run through and then exit. Then the next time it is run is when motion is cancelled (usually after 10 sec). But if motion is reset after i.e. 8 seconds, then the condition of no motion for 10 seconds won't be true. So now it has reset to 0 too soon, and the scene will only wake up on next motion event. You need to have a scene which triggers, turns on the light and then is kept alive until the light should be turned off. So basically:

- If motion true and lux<250, turn on light and set presence = 10

- repeat

-- Sleep 1 sec

-- If motion true, presence = 10

-- If motion false, presence = presence - 1

-- If light turned off, presence = 0

- Until presence = 0

- Turn light off

Now just do this as lua and then presence will be the period without motion until it should turn off.

Then you don't need to worry about source triggers or os.time or any of that either. Just make sure to include a check to only allow one alive instance at the start of your scene:

Please login or register to see this code.

In general, this is good programming customs to avoid the same scene launching over and over again, filling up memory and dragging down performance.

  • 0
  • Inquirer
  • Posted
    kmeta, what value is set in parameter 6 in your motion sensor?

    It's 30 sec

    Please login or register to see this image.

    /emoticons/default_sad.png" alt=":(" srcset="https://forum.fibaro.com/uploads/emoticons/[email protected] 2x" width="20" height="20" /> i now understand why i waiting 40 sec. Now decrease it to 10 seconds and will check again what is happened.

    [ Added: 2014-10-13, 17:13 ]

    You scene only triggers on an event. So once triggered, it will run through and then exit. Then the next time it is run is when motion is cancelled (usually after 10 sec). But if motion is reset after i.e. 8 seconds, then the condition of no motion for 10 seconds won't be true. So now it has reset to 0 too soon, and the scene will only wake up on next motion event. You need to have a scene which triggers, turns on the light and then is kept alive until the light should be turned off. So basically:

    Hi Dalle1985 your are right, but when i turned them manually they never not turn off. Another possibility is to add one more trigger (manually switch on) and to start countdown again.

    But if the shut down time is 1+ hours maybe is not good to use resource just to count down manually.

    I change this script like that and now is working correct. Do you have more recommendations ?

    Please login or register to see this code.

    • 0
    Posted

    Well... The discussion has been up before, and no, it isn't the best thing in the world to keep the scene running, but it is more or less the only solution if you want off on a timer. I have a bunch of dimmers running on a somewhat similar scene. They basically turn on when there is motion, is then kept on at a preset level for 120 seconds after last motion event (meaning they reset to 120 whenever motion is detected). They then start dimming out slowly (1% pr second). If you turn them off manually they will stay off. I have seven of these scenes and in the evening, at least 3 are almost constantly on, and I'm experiencing no resource problems. So yes, it might be bad programming to keep the program alive, but there is no other way (that I've found) which will allow you to monitor the light state regularly.

    Join the conversation

    You can post now and register later. If you have an account, sign in now to post with your account.

    Guest
    Answer this question...

    ×   Pasted as rich text.   Paste as plain text instead

      Only 75 emoji are allowed.

    ×   Your link has been automatically embedded.   Display as a link instead

    ×   Your previous content has been restored.   Clear editor

    ×   You cannot paste images directly. Upload or insert images from URL.

    ×
    ×
    • Create New...