Motion Light Off after 2 minutes at Nighttime

Easy to use, 100% Lua-based event scripting framework.
Post Reply
dbmet
Posts: 3
Joined: Friday 27 January 2017 16:37
Target OS: -
Domoticz version:
Contact:

Motion Light Off after 2 minutes at Nighttime

Post by dbmet » 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..

pvm
Posts: 962
Joined: Tuesday 17 June 2014 22:14
Target OS: NAS (Synology & others)
Domoticz version: Stable
Location: NL
Contact:

Motion Light Off after 2 minutes at Nighttime

Post by pvm » Wednesday 29 August 2018 7:58

Sorry wrong answer
Synology NAS, PI3, ZWave, Xiamo zigbee devices, BTLE plant sensor

dbmet
Posts: 3
Joined: Friday 27 January 2017 16:37
Target OS: -
Domoticz version:
Contact:

Re: Motion Light Off after 2 minutes at Nighttime

Post by dbmet » Thursday 30 August 2018 17:35

Ehhh figured it out using smart lua scripts. I think.


Sent from my iPhone using Tapatalk

snellejellep
Posts: 131
Joined: Tuesday 16 May 2017 13:05
Target OS: Raspberry Pi
Domoticz version: 4.1xxxx
Location: The Neterlands
Contact:

Re: Motion Light Off after 2 minutes at Nighttime

Post by snellejellep » Thursday 30 August 2018 18:54

can you give some examples for others browsing the forum with a similar question?
raspberry pi | xiaomi gateway/vacuum | yeelight | philips hue | zwave | ubiquiti unifi | harmony | sonoff | https://www.youtube.com/channel/UC2Zidl ... m1OLuNldfQ

User avatar
waaren
Posts: 1337
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Motion Light Off after 2 minutes at Nighttime

Post by waaren » 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 compicate with either a uservar or openURL .
Raspberry (debian stretch via berryboot on Synology DS916+) , Domoticz (almost) latest Beta, , dzVents 2.6, RFLink, RFXtrx433e, P1, Youless, Harmony, Hue, Yeelight, Xiaomi, HomeWizard, Zwave, Amazon echo

User avatar
waaren
Posts: 1337
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Motion Light Off after 2 minutes at Nighttime

Post by waaren » Friday 31 August 2018 19:37

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 .
Raspberry (debian stretch via berryboot on Synology DS916+) , Domoticz (almost) latest Beta, , dzVents 2.6, RFLink, RFXtrx433e, P1, Youless, Harmony, Hue, Yeelight, Xiaomi, HomeWizard, Zwave, Amazon echo

Boredcat
Posts: 46
Joined: Friday 17 March 2017 10:31
Target OS: Raspberry Pi
Domoticz version: 3.9639
Location: Netherlands
Contact:

Re: Motion Light Off after 2 minutes at Nighttime

Post by Boredcat » Saturday 15 September 2018 10:08

@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' ]}
RFXCom(E) - Yeelight Lights - KaKu / Alexa HA Bridge
Windows 2012 / Windows 2012R2 / Xpenology/ Pi 3 / Milight / Home build ESP8266 / Sonoff

User avatar
waaren
Posts: 1337
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Motion Light Off after 2 minutes at Nighttime

Post by waaren » Saturday 15 September 2018 11:13

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.
Raspberry (debian stretch via berryboot on Synology DS916+) , Domoticz (almost) latest Beta, , dzVents 2.6, RFLink, RFXtrx433e, P1, Youless, Harmony, Hue, Yeelight, Xiaomi, HomeWizard, Zwave, Amazon echo

DomoRies
Posts: 11
Joined: Friday 25 November 2016 23:46
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Motion Light Off after 2 minutes at Nighttime

Post by DomoRies » Sunday 16 September 2018 12:34

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


Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest