Page 1 of 1

2 timers how to determine which trigged the script

Posted: Monday 15 November 2021 18:42
by Ragdag
In a dzVents script I have the following Timer block

Code: Select all

		timer = {
			'at 7:00 on mon,tue,wed,thu,fri',
			'at 20:00 on mon,tue,wed,thu,fri,sat,sun',
		}
		
Is there any way in the script to figure out which timer initiated the script?
A workaround could be that I create 2 different scripts but would like to not do that.

Re: 2 timers how to determine which trigged the script

Posted: Monday 15 November 2021 21:03
by waltervl
I think the time it was executed will tell you :)
So it the scripts run at 7.00 hours it will be the first trigger line. If run on 20.00 hrs it will be the second line.

But perhaps you mean something else....

Re: 2 timers how to determine which trigged the script

Posted: Tuesday 16 November 2021 7:49
by Ragdag
🤣
Basically it comes down to I want to do X at 7:00 and want do do Y at 20:00.
So is there a way I can use it in an if statement

Re: 2 timers how to determine which trigged the script

Posted: Tuesday 16 November 2021 9:02
by waltervl
Ragdag wrote: Tuesday 16 November 2021 7:49 🤣
Basically it comes down to I want to do X at 7:00 and want do do Y at 20:00.
So is there a way I can use it in an if statement
Aha ;-)
According the docs it should be possible with triggerInfo.trigger but I cannot find a working example......
.trigger: the timer rule that triggered the script if the script was called due to a timer event, or the security state that triggered the security trigger rule. See below for the possible timer trigger rules.
Perhaps you can do a search on the forum...

Re: 2 timers how to determine which trigged the script  [Solved]

Posted: Tuesday 16 November 2021 9:22
by waltervl
ow wait, timer rule should be on item.trigger from execute = function(domoticz, item, triggerInfo). TriggerInfo is declared obsolete
.trigger: . string. the timer rule, the security state, the customEvent or the http response callback string that actually triggered your script. E.g. if you have multiple timer rules can inspect trigger which exact timer rule was fired.

Re: 2 timers how to determine which trigged the script

Posted: Tuesday 16 November 2021 9:31
by Ragdag
Yes that works :D

Code: Select all

return {
	on = {
		timer = {
			'at 09:30',					-- specific time
            'at 09:31',					-- specific time
		}
	},
	logging = {
		level = domoticz.LOG_DEBUG,
		marker = 'template',
	},
	execute = function(domoticz, timer)
		domoticz.log('Timer event was triggered by ' .. timer.trigger, domoticz.LOG_DEBUG)
	end
}

Code: Select all

2021-11-16 09:30:03.722 Status: dzVents: Info: template: ------ Start internal script: Script #1:, trigger: "at 09:30"
2021-11-16 09:30:03.724 Status: dzVents: Info: template: Timer event was triggered by at 09:30
2021-11-16 09:30:03.729 Status: dzVents: Info: template: ------ Finished Script #1
2021-11-16 09:30:03.731 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua 
Pretty dumb from me as the default timer dzVents actually has that as example :oops: