Page 1 of 1

if device = on and between specified time interval

Posted: Friday 04 August 2017 23:55
by TheCondor
Hello, i'm trying a very simple script but without success. I need to turn on a light "Bano Lampada" when the PIR is ON (Sensore Movimento) but only during the night, suppose an interval between 23:00 and 07:00.

That's what i do, but it doesn't works. If i remove the 'time' part works fine obviously... so i'm not using correctly the time function of dzvents.... any help is very appreciated, thanks in advance.

Code: Select all

return {
	active = true,
	
	on = {
		devices = {
            'Sensore Movimento'
        }
},
	execute = function(domoticz, Bagno)
			if domoticz.devices('Sensore Movimento').state == 'On' then
			    if (domoticz.time.hour > 23 and domoticz.time.hour < 7) then
                    domoticz.devices('Bagno Lampada').switchOn().forMin(2)
		        end
            end
	end
}

Re: if device = on and between specified time interval

Posted: Saturday 05 August 2017 0:00
by markjgabb
Think you need to use or. As the time can't be both after 11 and before 7 at the same time

Re: if device = on and between specified time interval

Posted: Saturday 05 August 2017 9:57
by bimse
[Try this

Code: Select all

return {
	active = true,
	
	on = {
		devices = {
            			['Sensore Movimento'] = {'at 23:00-07:00'}

        }
},
	execute = function(domoticz, Bagno)
			if domoticz.devices('Sensore Movimento').state == 'On' then
			         domoticz.devices('Bagno Lampada').switchOn().forMin(2)
		        end
            end
}
[/quote]

Re: if device = on and between specified time interval

Posted: Sunday 06 August 2017 17:10
by TheCondor
Awesome, both works fine, thanks and sorry for the dummy question!!!