Trigger every 5 mintes after midnight if device is off

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

Moderator: leecollings

Post Reply
DespyNL
Posts: 11
Joined: Thursday 23 July 2015 11:42
Target OS: Linux
Domoticz version: v4.9701
Location: The Netherlands
Contact:

Trigger every 5 mintes after midnight if device is off

Post 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
Nautilus
Posts: 722
Joined: Friday 02 October 2015 12:12
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Finland
Contact:

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

Post 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...
freakshock
Posts: 64
Joined: Friday 14 April 2017 13:39
Target OS: NAS (Synology & others)
Domoticz version:
Location: The Netherlands
Contact:

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

Post 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
}
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

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

Post 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.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest