Page 1 of 1

Add reset flag to switch timing options

Posted: Monday 04 September 2017 20:23
by jsiegmund
Hi there,

I've recently started coding my Domoticz install using DzVents. I really like the simplicity, especially compared to the other methods of scripting. But there's one thing I'm missing that should not be that hard to implement I think.

I'm trying to automate things after a period of inactivity. So you enter a room, light comes on (PIR detection) but it should switch off again after 15 minutes of inactivity (left the room but didn't kill the lights). Perfectly doable of course using a timer script and monitoring the last activity on the PIR, but then I have my "light on" and "light off" code in two different scripts.

What you'd really want is something like:

Code: Select all

device.switchOn()
device.switchOff().afterMin(15)
The problem is that when the PIR detects activity in the meantime, you want to reset that switchOff timer again. So my proposal would be to implement an optional reset flag on the afterMin (and the rest of them) methods. In code:

Code: Select all

device.switchOn()
device.switchOff().afterMin(15, true)
Behavior: when the reset flag is set, afterMin cancels any previously set afterMin events on the same device and replaces those with this one. For even more controlability another option would be to name the reset token using a string so you'd be able to only cancel out specific events by name. Or yet another option would be to have the afterMin return a handle or sorts that can be stored in a persistent var to be used by the same script later on. Multiple ways of getting to the same result.

Even fancier would be to have an inline method execute. So something like:

Code: Select all

device.do( (device) => {
    if (device.state == 'On') then
        device.switchOff()
    end
}).afterMin(15, true)
But I'm not sure LUA / DzVents supports syntax like that.

Let me know your thoughts!

Re: Add reset flag to switch timing options

Posted: Tuesday 05 September 2017 7:21
by DomoJev
I support this request. Makes things much easier!

Re: Add reset flag to switch timing options

Posted: Friday 15 December 2017 21:30
by niki_lauda
#metoo :-)