return {
active = true,
on = {
devices = {'Motion Kamer'}
},
execute = function(domoticz, device)
if device.state == 'On' then
-- domoticz.devices('Lamp Kamer').setState(device.state)
domoticz.devices('Lamp Kamer').switchOn().forMin(2)
end
end
}
This works fine in case the motion detector switches on only once every 2+ minutes. However if a new motion is detected just once within 2 minutes the lamp will never switch off again although no further motion is detected. This could be prevented by using the .checkFirst() method but what I want is that the Lamp "On" time gets extended with 2 minutes each time the motion detector is switched on again. I would expect that the .forMin timer would restart like a retriggerable one-shot. In some earlier posts I read that cancelling a queued timer is not yet implemented with an API in dzVents but any new command to the switch should cancel the timer. I tried this specifically with the setState(device.state) command as suggested but this does not work.
Well, the thing is this: at first you do a switchOn().forMin(2). At that moment, domoticz checks the current state of the device (Off), switches the device On and queues a command to restore the current state (which is Off). Then, after 1 minute, new motion is detected and a new switchOn().forMin(2) command is sent to Domoticz. Domoticz receives the command, sees that there is a queued command (switch off) and ditches the command from the queue. Then it checks the current state of the device (On), executes the switchOn() and queues the command to bring the device back to the current state. At this point however, the current state is On so it queues the On-command. Which exactly causes the lamp never to go off again.
The logic behind the forXXX() command in Domoticz is that it restores the current state of the device after the given time. So, in your case it is clear what should happen however Domoticz cannot guess this. You will have to do it yourself in this case.
What you can do is check the current state. If the device is On then you do a switchOff().afterMin(2) and otherwise you do a switchOn().forMin(2).
That should work. (famous last words).
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
Well, the thing is that there can be a lot of items in the command queue for the same device and the state that you want to restore isn't always just on or off. It can be dimlevels, colors etc. But feel free to improve the algorithm in Domoticz code :-p. It's a challenge, believe me.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
Hi,
sorry for hijacking this thread, one more clarification:
"The logic behind the forXXX() command in Domoticz is that it restores the current state of the device after the given time." << - regarding this...is <dimTo> considered a state change as well? For example, dimTo (70).forMin(1) when the starting level is for example 30 - does this means that the switch will be restored to dim level 30 after one minute?
Thanks for your support, great work!
Works like a charm, just what I needed. Thank you for the explanation how the internals work on this.
dannybloe wrote: ↑Tuesday 02 January 2018 17:42
What you can do is check the current state. If the device is On then you do a switchOff().afterMin(2) and otherwise you do a switchOn().forMin(2).