Page 1 of 1

Auto Night Mode

Posted: Thursday 26 December 2019 20:40
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

Re: Auto Night Mode

Posted: Thursday 26 December 2019 21:02
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 ?

Re: Auto Night Mode

Posted: Thursday 26 December 2019 22:03
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
}

Re: Auto Night Mode

Posted: Thursday 26 December 2019 23:51
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?

Re: Auto Night Mode

Posted: Thursday 26 December 2019 23:56
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
}

Re: Auto Night Mode

Posted: Thursday 26 December 2019 23:59
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?

Re: Auto Night Mode

Posted: Friday 27 December 2019 0:05
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?

Re: Auto Night Mode

Posted: Friday 27 December 2019 0:21
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

Re: Auto Night Mode  [Solved]

Posted: Friday 27 December 2019 0:28
by djdevil
Thank you for help ;)