Auto Night Mode  [Solved]

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

Moderator: leecollings

Post Reply
User avatar
djdevil
Posts: 101
Joined: Friday 26 July 2019 18:19
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Contact:

Auto Night Mode

Post by djdevil »

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
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Auto Night Mode

Post by waaren »

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!
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 ?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
djdevil
Posts: 101
Joined: Friday 26 July 2019 18:19
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Contact:

Re: Auto Night Mode

Post by djdevil »

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
}
User avatar
djdevil
Posts: 101
Joined: Friday 26 July 2019 18:19
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Contact:

Re: Auto Night Mode

Post by djdevil »

waaren wrote: Thursday 26 December 2019 21:02
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!
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 ?
my code works, is the approach ok?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Auto Night Mode

Post by waaren »

djdevil wrote: Thursday 26 December 2019 22:03 hello waaren thanks for the answer, I tried to write some code what do you think?
Looks about OK to me. I would change one aspect because you don't need to run the scrip 24/7

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
User avatar
djdevil
Posts: 101
Joined: Friday 26 July 2019 18:19
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Contact:

Re: Auto Night Mode

Post by djdevil »

waaren wrote: Thursday 26 December 2019 23:56
djdevil wrote: Thursday 26 December 2019 22:03 hello waaren thanks for the answer, I tried to write some code what do you think?
Looks about OK to me. I would change one aspect because you don't need to run the scrip 24/7

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
}
in this case using

Code: Select all

timer = {"at 21: 30-01: 00"},
how often is the script triggered? do I always check every minute in this time slot?
User avatar
djdevil
Posts: 101
Joined: Friday 26 July 2019 18:19
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Contact:

Re: Auto Night Mode

Post by djdevil »

waaren wrote: Thursday 26 December 2019 23:56
djdevil wrote: Thursday 26 December 2019 22:03 hello waaren thanks for the answer, I tried to write some code what do you think?
Looks about OK to me. I would change one aspect because you don't need to run the scrip 24/7

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
}
From Wiki
"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?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Auto Night Mode

Post by waaren »

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
User avatar
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]

Post by djdevil »

Thank you for help ;)
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest