Only trigger when state is changed
Posted: Tuesday 16 October 2018 21:28
Hello,
I'm very new to DzVents, i have read the wiki.
Now i'm trying to set up a script to turn on my led strip in the kitchen.
Sow; I have a motion sensor (Motion Kitchen), who sends every 10 seconds an "on" command as long as there is motion. But it does not send a "off" command when there is no motion. So I set up the "OffDelay" in de device settings. So when there is no motion the "Motion Sensor" device goes "Off" after 30 seconds.
What i want is: When "Motion Kitchen" switch from "Off" to "On" the led strip (Kitchen Led) turnt "On". When "Motion Kitchen" Switch to "Off" the "Kitchen Led" turns off after 60 seconds.
But what i see in the log is that the event is triggerd every 10 seconds when the Motion sensor sends a "On" command. This is unnecessary in my opinion. Is it possible to only trigger if the state of the Motion Kitchen changes from "Off" to "On"?
Now i have the following code:
I'm very new to DzVents, i have read the wiki.
Now i'm trying to set up a script to turn on my led strip in the kitchen.
Sow; I have a motion sensor (Motion Kitchen), who sends every 10 seconds an "on" command as long as there is motion. But it does not send a "off" command when there is no motion. So I set up the "OffDelay" in de device settings. So when there is no motion the "Motion Sensor" device goes "Off" after 30 seconds.
What i want is: When "Motion Kitchen" switch from "Off" to "On" the led strip (Kitchen Led) turnt "On". When "Motion Kitchen" Switch to "Off" the "Kitchen Led" turns off after 60 seconds.
But what i see in the log is that the event is triggerd every 10 seconds when the Motion sensor sends a "On" command. This is unnecessary in my opinion. Is it possible to only trigger if the state of the Motion Kitchen changes from "Off" to "On"?
Now i have the following code:
Code: Select all
return {
on = {
devices = {
'Motion Kitchen'
}
},
execute = function(domoticz, switch)
if (switch.state == 'On') then
domoticz.devices('Kitchen Led').switchOn()
domoticz.log('Beweging in de keuken. Led AAN')
else
domoticz.devices('Kitchen Led').switchOff().afterMin(1)
domoticz.log('Geen beweging in de keuken. Led UIT over 1 minuut')
end
end
}