Timer only when device is on

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

Moderator: leecollings

Post Reply
Cyroq
Posts: 30
Joined: Monday 10 December 2018 13:44
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Timer only when device is on

Post by Cyroq »

Hi, is it possible to only run a timer script when a specific device is on? Of course I could run a timer script and put everything in an if-statement like

Code: Select all

if (dz.devices('devicename') == 'On') then
...
end
but that floods my log file big time if the timer is run every minute 24/7. The script will in reality only be active 10 minutes a day, so it runs 10 times. It is triggered by a (dummy) device.
mgugu
Posts: 218
Joined: Friday 04 November 2016 12:33
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: France
Contact:

Re: Timer only when device is on

Post by mgugu »

User avatar
boum
Posts: 135
Joined: Friday 18 January 2019 11:31
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Location: France
Contact:

Re: Timer only when device is on

Post by boum »

You can also change your script to trigger only on your dummy device and when triggered to On, execute a buncho of dz.emitEvent('customname', {...}).afterMin(X).
You can have another script with customEvents trigger. Or do that in your device script too.

You can also execute a single custom event in the first script, and in the second one, trigger it again as long as some condition is met.
Neutrino
Posts: 21
Joined: Sunday 08 May 2016 19:00
Target OS: Raspberry Pi / ODroid
Domoticz version: 2021.1
Location: France
Contact:

Re: Timer only when device is on

Post by Neutrino »

I'm using this :

Code: Select all

return {
	active = function(domoticz)
		return (domoticz.devices('devicename').state == 'On')
	end,
	--active = true,
	on = {
		timer = {'every minute'},
	},
Cyroq
Posts: 30
Joined: Monday 10 December 2018 13:44
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Timer only when device is on

Post by Cyroq »

Thanks @Neutrino, that's a neat solution! Works perfectly.
@boum I'm hesitant using AfterMin() because it's complex to cancel the operation mid way, if I'd want that. But I didn't know about the customEvents trigger, might come in handy later 8-)
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest