Page 1 of 1

Trigger every 5 mintes after midnight if device is off

Posted: Thursday 03 August 2017 16:07
by DespyNL
Hi,

I am new to dzVents and it looks very promising. I've started migrating some lua script to dzVents, but I am experiencing some difficulties.

By default I would like to switch off the lights after midnight, but only when the TV is off. If the tv is on, the lights should stay on and the script has to check again in 5 minutes. I guess the script should be triggered at midnight, every 5 minutes and only when the lights are on. Is this possible with dzVents?

Its a waste of time to run the script if its past midnight and the lights are already out

Code: Select all

return {
	active = true,
	on = {
		timer = {
			'at 00:00 every 5 minutes'
		}
		-- + only if device light state is on
		-- is there any way?
	},
	execute = function(domoticz, device)

	end
}
Thanks

Re: Trigger every 5 mintes after midnight if device is off

Posted: Friday 04 August 2017 9:09
by Nautilus
Sorry for bit of an off-topic (as I don't use dZvents) but I cannot see why you don't put this to a device script that triggers when TV is turned off (with a second condition for a desired time frame)? You can of course add a delay too if you do not want the lights to turn off immediately...

Re: Trigger every 5 mintes after midnight if device is off

Posted: Friday 04 August 2017 22:56
by freakshock
I'm new to dzVents as well, but it should be something like this I think:

Code: Select all

return {
   active = true,
   on = {
      timer = {
         'at nighttime 00:00 every 5 minutes' --added at nighttime because else it would continue forever I think
      }
   
   },
   execute = function(domoticz)
   
   	if (domoticz.devices('TV').state == 'Off' then 
		    domoticz.devices('Light1').switchOff()
		    domoticz.devices('Light2').switchOff() --or insert a group with all lights here

   		end
   end
}

Re: Trigger every 5 mintes after midnight if device is off

Posted: Sunday 06 August 2017 9:43
by dannybloe
This will not work like this. 'at nighttime' is a period (from sunset-sunrise) but 00:00 is a moment. So that's a contradiction. So in your case I would do something like this:

Code: Select all

return {
   active = true,
   on = {
      timer = {
         'every 5 minutes at 00:00-06:00' 
      }
   
   },
   execute = function(domoticz)
   
      if (domoticz.devices('TV').state == 'Off' then 
      	-- do your thing
      end
   end
}
But, why don't you make a script that is triggered when the tv goes off?

Code: Select all

return {
   active = true,
   on = {
      devices = { 
      	'TV' = {'at 00:00-06:00'}
      }
   },
   execute = function(domoticz, tv)
   	if (tv.state == 'Off) then
   		domoticz.devices('Light1').switchOff()
          	domoticz.devices('Light2').switchOff()
        end  	
   end
}
Unless of course you don't get an event when the tv is turned off.