Page 1 of 1
FOR 60 Minutes ( doesn't switch off after 2 commands )
Posted: Tuesday 06 August 2019 17:35
by Sjefske85
Hi All,
I'm struggling with some easy stuff.
All I want to do is switch a dummy to detect presence for an x time to control lights .
The code below works but if the switch is triggered for a second time within the countdown time the 'Presence' won't go to it's OFF state any more
every time there is movement it needs to be reset to 60 minutes and countdown again.
Using the 'Off after' doen't do the job, then the lights go off and you have to move your butt to trigger it again
hope you guys can help me out
Code: Select all
commandArray = {}
if (devicechanged['Motion 1 WK'] == 'On' and otherdevices['PowerOff'] == 'On') then
commandArray['Presence'] = 'On FOR 60' -- minutes
end
if (devicechanged['Motion 2 Hal'] == 'On' and otherdevices['PowerOff'] == 'On') then
commandArray['Presence'] = 'On FOR 60' -- minutes
end
return commandArray
Re: FOR 60 Minutes ( doesn't switch off after 2 commands )
Posted: Tuesday 06 August 2019 18:10
by tozzke
Sjefske85 wrote: ↑Tuesday 06 August 2019 17:35
Hi All,
I'm struggling with some easy stuff.
All I want to do is switch a dummy to detect presence for an x time to control lights .
The code below works but if the switch is triggered for a second time within the countdown time the 'Presence' won't go to it's OFF state any more
every time there is movement it needs to be reset to 60 minutes and countdown again.
Using the 'Off after' doen't do the job, then the lights go off and you have to move your butt to trigger it again
hope you guys can help me out
Code: Select all
commandArray = {}
if (devicechanged['Motion 1 WK'] == 'On' and otherdevices['PowerOff'] == 'On') then
commandArray['Presence'] = 'On FOR 60' -- minutes
end
if (devicechanged['Motion 2 Hal'] == 'On' and otherdevices['PowerOff'] == 'On') then
commandArray['Presence'] = 'On FOR 60' -- minutes
end
return commandArray
I've got the feeling that with the 'On For y minutes' Block it just switches "back" to the state it was just before the time of the trigger. If it was off, it'll turn off, it was on, it turns "back" on after the amount of time you set it to (watch your log).
To be sure you'd better use
Code: Select all
commandArray = {}
if (devicechanged['Motion 1 WK'] == 'On' and otherdevices['PowerOff'] == 'On') then
commandArray[1]={['Presence'] = 'On'}
commandArray[2]={['Presence'] = 'Off AFTER 3600'}
end
if (devicechanged['Motion 2 Hal'] == 'On' and otherdevices['PowerOff'] == 'On') then
commandArray[1]={['Presence'] = 'On'}
commandArray[2]={['Presence'] = 'Off AFTER 3600'}
end
return commandArray
Re: FOR 60 Minutes ( doesn't switch off after 2 commands )
Posted: Tuesday 06 August 2019 18:14
by Sjefske85
Thnx I'll try this evening.
Re: FOR 60 Minutes ( doesn't switch off after 2 commands )
Posted: Tuesday 06 August 2019 18:36
by jake
Sjefske85 wrote:Hi All,
I'm struggling with some easy stuff.
All I want to do is switch a dummy to detect presence for an x time to control lights .
The code below works but if the switch is triggered for a second time within the countdown time the 'Presence' won't go to it's OFF state any more
every time there is movement it needs to be reset to 60 minutes and countdown again.
Using the 'Off after' doen't do the job, then the lights go off and you have to move your butt to trigger it again
hope you guys can help me out
Code: Select all
commandArray = {}
if (devicechanged['Motion 1 WK'] == 'On' and otherdevices['PowerOff'] == 'On') then
commandArray['Presence'] = 'On FOR 60' -- minutes
end
if (devicechanged['Motion 2 Hal'] == 'On' and otherdevices['PowerOff'] == 'On') then
commandArray['Presence'] = 'On FOR 60' -- minutes
end
return commandArray
You're using dzvents, which is good

In the dzvents wiki, there is an example for your situation:
light.switchOff().checkFirst().afterMin(5) light.switchOn().checkFirst().forMin(5)
By using this, you will prevent your situation where a new activation kills the one before
Re: FOR 60 Minutes ( doesn't switch off after 2 commands )
Posted: Tuesday 06 August 2019 19:52
by tozzke
jake wrote: ↑Tuesday 06 August 2019 18:36
Sjefske85 wrote:Hi All,
I'm struggling with some easy stuff.
All I want to do is switch a dummy to detect presence for an x time to control lights .
The code below works but if the switch is triggered for a second time within the countdown time the 'Presence' won't go to it's OFF state any more
every time there is movement it needs to be reset to 60 minutes and countdown again.
Using the 'Off after' doen't do the job, then the lights go off and you have to move your butt to trigger it again
hope you guys can help me out
Code: Select all
commandArray = {}
if (devicechanged['Motion 1 WK'] == 'On' and otherdevices['PowerOff'] == 'On') then
commandArray['Presence'] = 'On FOR 60' -- minutes
end
if (devicechanged['Motion 2 Hal'] == 'On' and otherdevices['PowerOff'] == 'On') then
commandArray['Presence'] = 'On FOR 60' -- minutes
end
return commandArray
You're using dzvents, which is good

In the dzvents wiki, there is an example for your situation:
light.switchOff().checkFirst().afterMin(5) light.switchOn().checkFirst().forMin(5)
By using this, you will prevent your situation where a new activation kills the one before
This isn't dzVents but good ol' Lua
Re: FOR 60 Minutes ( doesn't switch off after 2 commands )
Posted: Tuesday 06 August 2019 22:50
by jake
Excusez moi, you're right. Well, on that case I would advise you to try dzvents. Dzvents has a little bit of a learning curve, but the much more standardized approach makes coding a lot easier afterwards!
Re: FOR 60 Minutes ( doesn't switch off after 2 commands )
Posted: Thursday 08 August 2019 13:33
by Sjefske85
Hi Guys thanks for your help
Just tested the code and it works like a charm
"PowerOff" is the harmony hub (remote) status.
So if the no media is playing the lights are controlled by "Motion sensors"
If the radio or whatever is switched on the "Presence" is forced to on despite sitting like a coach potato, overruling the motion sensors.
In the past i had to move again to get the lights back on.
This is what i came up with, with your help.
Used 60 seconds to test the code
Code: Select all
commandArray = {}
if (devicechanged['PowerOff'] == 'Off') then --Media is playing
commandArray[1]={['Presence'] = 'On'}
end
if (devicechanged['PowerOff'] == 'On') then --media is stopped
commandArray[1]={['Presence'] = 'Off AFTER 60'}
end
if (devicechanged['Motion 1 WK'] == 'On' and otherdevices['PowerOff'] == 'On') then --motion livingroom
commandArray[1]={['Presence'] = 'On'}
commandArray[2]={['Presence'] = 'Off AFTER 60'}
end
if (devicechanged['Motion 2 Hal'] == 'On' and otherdevices['PowerOff'] == 'On') then --motion hallway
commandArray[1]={['Presence'] = 'On'}
commandArray[2]={['Presence'] = 'Off AFTER 60'}
end
return commandArray
In the meantime i'll try to get it also working in dzvents