Page 1 of 1

Motion Light Off after 2 minutes at Nighttime

Posted: Wednesday 29 August 2018 2:45
by dbmet
I'm looking for a script that will turn the hallway light off after no motion for 2 minutes only when its nighttime out.

Searched the forums but didnt really see what I was looking for..

Motion Light Off after 2 minutes at Nighttime

Posted: Wednesday 29 August 2018 7:58
by pvm
Sorry wrong answer

Re: Motion Light Off after 2 minutes at Nighttime

Posted: Thursday 30 August 2018 17:35
by dbmet
Ehhh figured it out using smart lua scripts. I think.


Sent from my iPhone using Tapatalk

Re: Motion Light Off after 2 minutes at Nighttime

Posted: Thursday 30 August 2018 18:54
by snellejellep
can you give some examples for others browsing the forum with a similar question?

Re: Motion Light Off after 2 minutes at Nighttime

Posted: Friday 31 August 2018 19:37
by waaren
dbmet wrote: Wednesday 29 August 2018 2:45 I'm looking for a script that will turn the hallway light off after no motion for 2 minutes only when its nighttime out.

Searched the forums but didnt really see what I was looking for..
From the dzVents wiki:

"A device trigger can have a time-rule constraint: on = { devices = { ['myDevice'] = 'at nighttime' } }. This only triggers the script when myDevice was changed and the time is after sunset and before sunrise."

so if you use this as the on = section and something like

Code: Select all

if trigger.state == "On" then
  	domoticz.devices("hallway light").switchOn().checkFirst()	
else
	domoticz.devices("hallway light").switchOff()
end
in the execute = section (assuming the motion detector switches to "Off" after two minutes.) If that is not the case the script becomes a bit more compicate with either a uservar or openURL .

Re: Motion Light Off after 2 minutes at Nighttime

Posted: Friday 31 August 2018 19:37
by waaren
waaren wrote: Friday 31 August 2018 19:37
dbmet wrote: Wednesday 29 August 2018 2:45 I'm looking for a script that will turn the hallway light off after no motion for 2 minutes only when its nighttime out.

Searched the forums but didnt really see what I was looking for..
From the dzVents wiki:

"A device trigger can have a time-rule constraint: on = { devices = { ['myDevice'] = 'at nighttime' } }. This only triggers the script when myDevice was changed and the time is after sunset and before sunrise."

so if you use this as the on = section and something like

Code: Select all

if trigger.state == "On" then
  	domoticz.devices("hallway light").switchOn().checkFirst()	
else
	domoticz.devices("hallway light").switchOff()
end
in the execute = section (assuming the motion detector switches to "Off" after two minutes.) If that is not the case the script becomes a bit more complicated with either a uservar or openURL .

Re: Motion Light Off after 2 minutes at Nighttime

Posted: Saturday 15 September 2018 10:08
by Boredcat
@Warren : That solution will not work.

He wanted to switch off a light when there is no motoin (so no device trigger).

A solution that I use is to use a timed event (my PIR check runs every minute). So a solution might be.

Code: Select all

return {
    active = true,
    on = {
        timer = {'Every minute '}
    },
    execute = function(domoticz)
    
    if ( ( domoticz.devices('PIR Hallway').lastUpdate.minutesAgo => 2 ) and  (domoticz.devices('Hallway').state == 'On'  and domoticz.time.isNightTime)) then
    domoticz.devices('Hallway').switchOff()
    end
end
    

No sure if the time-rule works with a timer. (might try this)
on = {
timer = {'[Every minute ', 'at nighttime' ]}

Re: Motion Light Off after 2 minutes at Nighttime

Posted: Saturday 15 September 2018 11:13
by waaren
Boredcat wrote: Saturday 15 September 2018 10:08 @waaren : That solution will not work.
He wanted to switch off a light when there is no motoin (so no device trigger).
As always .. It depends :D That's why I wrote "(assuming the motion detector switches to "Off" after two minutes.)"

My motion detectors also trigger an event after the set time folowing a motiondetection passed.

Re: Motion Light Off after 2 minutes at Nighttime

Posted: Sunday 16 September 2018 12:34
by DomoRies
For me this works perfectly. Maybe u can use it. This way the lights stay on for 1 minute after motion sensor detected motion.

Code: Select all

return { on = { devices = {motion sensor} }, 

execute = function(domoticz, device)

local light = domoticz.devices(light u want to switch)

if ((not light.active and device.active) or (light.active and device.active)) then
light.switchOn() 

elseif (not device.active) then light.switchOff().checkFirst().afterMin(1) end 
end }
Verstuurd vanaf mijn Moto G (5) Plus met Tapatalk