FOR 60 Minutes ( doesn't switch off after 2 commands )

Moderator: leecollings

Post Reply
User avatar
Sjefske85
Posts: 3
Joined: Tuesday 06 August 2019 17:17
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

FOR 60 Minutes ( doesn't switch off after 2 commands )

Post 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
tozzke
Posts: 135
Joined: Friday 02 January 2015 9:22
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: Netherlands
Contact:

Re: FOR 60 Minutes ( doesn't switch off after 2 commands )

Post 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
User avatar
Sjefske85
Posts: 3
Joined: Tuesday 06 August 2019 17:17
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: FOR 60 Minutes ( doesn't switch off after 2 commands )

Post by Sjefske85 »

Thnx I'll try this evening.
jake
Posts: 742
Joined: Saturday 30 May 2015 22:40
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Contact:

Re: FOR 60 Minutes ( doesn't switch off after 2 commands )

Post 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
tozzke
Posts: 135
Joined: Friday 02 January 2015 9:22
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: Netherlands
Contact:

Re: FOR 60 Minutes ( doesn't switch off after 2 commands )

Post 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
jake
Posts: 742
Joined: Saturday 30 May 2015 22:40
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Contact:

Re: FOR 60 Minutes ( doesn't switch off after 2 commands )

Post 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!
User avatar
Sjefske85
Posts: 3
Joined: Tuesday 06 August 2019 17:17
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: FOR 60 Minutes ( doesn't switch off after 2 commands )

Post by Sjefske85 »

Hi Guys thanks for your help :D

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
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 1 guest