I have a script (blocky currently) that triggers a lamp on when motion is detected.
In the blocky I have "turn on lamp for 5 minutes".
What I need is that if someone cause again a motion within that 5 minutes, the timer should set again to 5 minutes from now, ignoring the previously cosumed minutes.....
In other words, I should have a timer that refresh the 5 minutes everytime someone cause motion and the light should remain ON all the time the timer is not expired....
How can I do this in LUA?
Thank you
Motion and light timer
Moderator: leecollings
-
- Posts: 79
- Joined: Thursday 23 October 2014 22:41
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Motion and light timer
I do this by having a timer variable for each room. All you then need is a timer script that runs every minute: this simply gets the variable and deducts one. If the new value is zero it turns off the light.
For setting the initial timer you can either track when the light it switched on via LUA, or you can use the 'on action' for the switch. I'd share my code directly but my actual setup is a lot more complex than this so wouldn't work for others.
For setting the initial timer you can either track when the light it switched on via LUA, or you can use the 'on action' for the switch. I'd share my code directly but my actual setup is a lot more complex than this so wouldn't work for others.
Re: Motion and light timer
I do this by checking the "otherdevices_lastupdate[sensor]". When the sensor is Off and more than 5 minutes have passed since the last update, it turns off the light. This script runs every minute. With only this it would turn the light off every minute after reaching the 5 minute limit. You can bypass that problem by adding to the statement "more than 5 minutes" : "but no more than 6 minutes".
- Egregius
- Posts: 2592
- Joined: Thursday 09 April 2015 12:19
- Target OS: Linux
- Domoticz version: v2024.7
- Location: Beitem, BE
- Contact:
Re: Motion and light timer
Why not just check the state of the light at that moment?mrf68 wrote:You can bypass that problem by adding to the statement "more than 5 minutes" : "but no more than 6 minutes".
If pir = off and lasttime > 300 and light = on do switch light off.
Re: Motion and light timer
And so we learn something every day. Thanks, Egregius. I can optimize my code now.Egregius wrote:Why not just check the state of the light at that moment?mrf68 wrote:You can bypass that problem by adding to the statement "more than 5 minutes" : "but no more than 6 minutes".
If pir = off and lasttime > 300 and light = on do switch light off.

Re: Motion and light timer
Thank you for all answers.
Now I am working to distinguish when the light is switched on by a motion sensor (and it should switch off with a timer) and when it is switched on by an explicit action (and it should remain switched on until someone switch it off)....
Now I am working to distinguish when the light is switched on by a motion sensor (and it should switch off with a timer) and when it is switched on by an explicit action (and it should remain switched on until someone switch it off)....
Who is online
Users browsing this forum: No registered users and 1 guest