Auto Night Mode [Solved]
Moderator: leecollings
- djdevil
- Posts: 101
- Joined: Friday 26 July 2019 18:19
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2021.1
- Contact:
Auto Night Mode
Hi everyone I am looking for advice, I would like to create a script that when the presence switch is on and at a certain time like from 21:00 to 23:00 I check the latest update of my sensors and PIR and if after 20 minutes have not been updated automatically activated night mode! it's possible?
Thx
Thx
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Auto Night Mode
Yes that would be possible but the approach to choose is depending on the dzVents version you are on. What is you domoticz / dzVents level ?djdevil wrote: Thursday 26 December 2019 20:40 I would like to create a script that when the presence switch is on and at a certain time like from 21:00 to 23:00 I check the latest update of my sensors and PIR and if after 20 minutes have not been updated automatically activated night mode!
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
- djdevil
- Posts: 101
- Joined: Friday 26 July 2019 18:19
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2021.1
- Contact:
Re: Auto Night Mode
hello waaren thanks for the answer, I tried to write some code what do you think?
Code: Select all
return {
on = { timer = {"every 1 minutes"}
},
execute = function(domoticz, device)
local presenza = domoticz.devices('Presenza')
local ModalitaNotte = domoticz.devices('Modalità Notte')
local PIR1 = domoticz.devices('Sensore Corridoio')
local PIR2 = domoticz.devices('Sensore Living')
local Tramonto = domoticz.devices('Tramonto')
if presenza.state == 'On' and ModalitaNotte.state == 'Off'and Tramonto.state == 'On' and PIR1.lastUpdate.secondsAgo > 300 and PIR2.lastUpdate.secondsAgo > 300 then
if domoticz.time.matchesRule('at 21:30-01:00') then
ModalitaNotte.switchOn()
end
end
end
}- djdevil
- Posts: 101
- Joined: Friday 26 July 2019 18:19
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2021.1
- Contact:
Re: Auto Night Mode
my code works, is the approach ok?waaren wrote: Thursday 26 December 2019 21:02Yes that would be possible but the approach to choose is depending on the dzVents version you are on. What is you domoticz / dzVents level ?djdevil wrote: Thursday 26 December 2019 20:40 I would like to create a script that when the presence switch is on and at a certain time like from 21:00 to 23:00 I check the latest update of my sensors and PIR and if after 20 minutes have not been updated automatically activated night mode!
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Auto Night Mode
Looks about OK to me. I would change one aspect because you don't need to run the scrip 24/7djdevil wrote: Thursday 26 December 2019 22:03 hello waaren thanks for the answer, I tried to write some code what do you think?
Code: Select all
return
{
on =
{
timer = { "at 21:30-01:00" },
},
execute = function(domoticz, device)
local presenza = domoticz.devices('Presenza')
local ModalitaNotte = domoticz.devices('Modalità Notte')
local PIR1 = domoticz.devices('Sensore Corridoio')
local PIR2 = domoticz.devices('Sensore Living')
local Tramonto = domoticz.devices('Tramonto')
if presenza.state == 'On' and ModalitaNotte.state == 'Off' and Tramonto.state == 'On' and PIR1.lastUpdate.secondsAgo > 300 and PIR2.lastUpdate.secondsAgo > 300 then
ModalitaNotte.switchOn()
end
end
}Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
- djdevil
- Posts: 101
- Joined: Friday 26 July 2019 18:19
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2021.1
- Contact:
Re: Auto Night Mode
in this case usingwaaren wrote: Thursday 26 December 2019 23:56Looks about OK to me. I would change one aspect because you don't need to run the scrip 24/7djdevil wrote: Thursday 26 December 2019 22:03 hello waaren thanks for the answer, I tried to write some code what do you think?Code: Select all
return { on = { timer = { "at 21:30-01:00" }, }, execute = function(domoticz, device) local presenza = domoticz.devices('Presenza') local ModalitaNotte = domoticz.devices('Modalità Notte') local PIR1 = domoticz.devices('Sensore Corridoio') local PIR2 = domoticz.devices('Sensore Living') local Tramonto = domoticz.devices('Tramonto') if presenza.state == 'On' and ModalitaNotte.state == 'Off' and Tramonto.state == 'On' and PIR1.lastUpdate.secondsAgo > 300 and PIR2.lastUpdate.secondsAgo > 300 then ModalitaNotte.switchOn() end end }
Code: Select all
timer = {"at 21: 30-01: 00"},- djdevil
- Posts: 101
- Joined: Friday 26 July 2019 18:19
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2021.1
- Contact:
Re: Auto Night Mode
From Wikiwaaren wrote: Thursday 26 December 2019 23:56Looks about OK to me. I would change one aspect because you don't need to run the scrip 24/7djdevil wrote: Thursday 26 December 2019 22:03 hello waaren thanks for the answer, I tried to write some code what do you think?Code: Select all
return { on = { timer = { "at 21:30-01:00" }, }, execute = function(domoticz, device) local presenza = domoticz.devices('Presenza') local ModalitaNotte = domoticz.devices('Modalità Notte') local PIR1 = domoticz.devices('Sensore Corridoio') local PIR2 = domoticz.devices('Sensore Living') local Tramonto = domoticz.devices('Tramonto') if presenza.state == 'On' and ModalitaNotte.state == 'Off' and Tramonto.state == 'On' and PIR1.lastUpdate.secondsAgo > 300 and PIR2.lastUpdate.secondsAgo > 300 then ModalitaNotte.switchOn() end end }
"It is important to know that Domoticz timer events only trigger once every minute, so one minute is the smallest interval for your timer scripts."
'at 12:45-21:15', -- between 12:45 and 21:15. You cannot use '*'!
Trigger every minute right?
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Auto Night Mode
djdevil wrote: Friday 27 December 2019 0:05 'at 12:45-21:15', -- between 12:45 and 21:15. You cannot use '*'!
Trigger every minute right?
'at 12:45-21:15', -- between 12:45 and 21:15. You cannot use '*'! [/qoute]
This means that the script will trigger every minute between 12:45 and 21:45 and that you cannot use wildcards here.
So for example 'at *:45-*:55' will not work
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
- djdevil
- Posts: 101
- Joined: Friday 26 July 2019 18:19
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2021.1
- Contact:
Re: Auto Night Mode [Solved]
Thank you for help 
Who is online
Users browsing this forum: No registered users and 1 guest