Motion and light timer

chrispazz
Posts: 50
Joined: Friday 08 July 2016 10:38
Target OS: -
Domoticz version:
Contact:

Motion and light timer

Postby chrispazz » Friday 21 April 2017 14:44

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

DanM
Posts: 73
Joined: Thursday 23 October 2014 22:41
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Motion and light timer

Postby DanM » Friday 21 April 2017 18:31

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.

User avatar
mrf68
Posts: 200
Joined: Monday 23 February 2015 13:45
Target OS: Windows
Domoticz version: 3.4834
Location: Netherlands
Contact:

Re: Motion and light timer

Postby mrf68 » Saturday 22 April 2017 7:50

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".
----------
3x RPi
1x W2k12 (vm)
3x RFXcom433e
1x Razberry board
KAKU: 9x APA3-1500R, 2x ACDB-7000C, 3x AMST-606, 1x APIR-2150, 1x AWS-3500, 1x ATMT-502
Z-wave: 8x Everspring AN145
Misc: 2x wireless doorbells

Egregius
Posts: 2269
Joined: Thursday 09 April 2015 12:19
Target OS: Raspberry Pi
Domoticz version: BetaRPi2
Location: Beitem, BE
Contact:

Re: Motion and light timer

Postby Egregius » Saturday 22 April 2017 8:26

mrf68 wrote:You can bypass that problem by adding to the statement "more than 5 minutes" : "but no more than 6 minutes".

Why not just check the state of the light at that moment?
If pir = off and lasttime > 300 and light = on do switch light off.

User avatar
mrf68
Posts: 200
Joined: Monday 23 February 2015 13:45
Target OS: Windows
Domoticz version: 3.4834
Location: Netherlands
Contact:

Re: Motion and light timer

Postby mrf68 » Saturday 22 April 2017 9:53

Egregius wrote:
mrf68 wrote:You can bypass that problem by adding to the statement "more than 5 minutes" : "but no more than 6 minutes".

Why not just check the state of the light at that moment?
If pir = off and lasttime > 300 and light = on do switch light off.


And so we learn something every day. Thanks, Egregius. I can optimize my code now. ;)
----------
3x RPi
1x W2k12 (vm)
3x RFXcom433e
1x Razberry board
KAKU: 9x APA3-1500R, 2x ACDB-7000C, 3x AMST-606, 1x APIR-2150, 1x AWS-3500, 1x ATMT-502
Z-wave: 8x Everspring AN145
Misc: 2x wireless doorbells

chrispazz
Posts: 50
Joined: Friday 08 July 2016 10:38
Target OS: -
Domoticz version:
Contact:

Re: Motion and light timer

Postby chrispazz » Thursday 27 April 2017 11:45

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)....


Return to “LUA”

Who is online

Users browsing this forum: DarkAllMan and 2 guests