Motion Light Off after 2 minutes at Nighttime

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
dbmet
Posts: 2
Joined: Friday 27 January 2017 15:37
Target OS: -
Domoticz version:
Contact:

Motion Light Off after 2 minutes at Nighttime

Post 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..
pvm
Posts: 550
Joined: Tuesday 17 June 2014 22:14
Target OS: NAS (Synology & others)
Domoticz version: 4.10538
Location: NL
Contact:

Motion Light Off after 2 minutes at Nighttime

Post by pvm »

Sorry wrong answer
Synology NAS, slave PI3, ZWave (Fibaro), Xiaomi zigbee devices, BTLE plant sensor, DzVents, Dashticz on tablet, Logitech Media Server
dbmet
Posts: 2
Joined: Friday 27 January 2017 15:37
Target OS: -
Domoticz version:
Contact:

Re: Motion Light Off after 2 minutes at Nighttime

Post by dbmet »

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


Sent from my iPhone using Tapatalk
snellejellep
Posts: 241
Joined: Tuesday 16 May 2017 13:05
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: The Neterlands
Contact:

Re: Motion Light Off after 2 minutes at Nighttime

Post by snellejellep »

can you give some examples for others browsing the forum with a similar question?
raspberry pi | xiaomi vacuum | yeelight | philips hue | zwave | ubiquiti unifi | harmony | sonoff | zigbee2mqtt | https://www.youtube.com/channel/UC2Zidl ... m1OLuNldfQ
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Motion Light Off after 2 minutes at Nighttime

Post 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 .
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Motion Light Off after 2 minutes at Nighttime

Post 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 .
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Boredcat
Posts: 38
Joined: Friday 17 March 2017 9:31
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.9639
Location: Netherlands
Contact:

Re: Motion Light Off after 2 minutes at Nighttime

Post 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' ]}
RFXCom(E) - Yeelight Lights - KaKu / Alexa HA Bridge
Windows 2012 / Windows 2012R2 / Xpenology/ Pi 3 / Milight / Home build ESP8266 / Sonoff
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Motion Light Off after 2 minutes at Nighttime

Post 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.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
DomoRies
Posts: 14
Joined: Friday 25 November 2016 22:46
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Motion Light Off after 2 minutes at Nighttime

Post 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

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest