if device = on and between specified time interval

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

Moderator: leecollings

Post Reply
TheCondor
Posts: 78
Joined: Thursday 18 June 2015 10:32
Target OS: Linux
Domoticz version:
Contact:

if device = on and between specified time interval

Post 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
}
markjgabb
Posts: 142
Joined: Tuesday 24 January 2017 23:00
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.8153
Location: Australia
Contact:

Re: if device = on and between specified time interval

Post by markjgabb »

Think you need to use or. As the time can't be both after 11 and before 7 at the same time
V 2020.2 RPI 3
RFlink 334 mhz
mysensors
broadlink
Mirabella Genio Globes
bimse
Posts: 21
Joined: Sunday 05 February 2017 12:09
Target OS: Raspberry Pi / ODroid
Domoticz version: Model 3
Contact:

Re: if device = on and between specified time interval

Post 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]
Translated with google
TheCondor
Posts: 78
Joined: Thursday 18 June 2015 10:32
Target OS: Linux
Domoticz version:
Contact:

Re: if device = on and between specified time interval

Post by TheCondor »

Awesome, both works fine, thanks and sorry for the dummy question!!!
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 1 guest