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

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

Moderator: leecollings

Post Reply
User avatar
Ragdag
Posts: 169
Joined: Friday 30 March 2018 13:56
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Netherlands
Contact:

2 timers how to determine which trigged the script

Post 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.
User avatar
waltervl
Posts: 6691
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2025.1
Location: NL
Contact:

Re: 2 timers how to determine which trigged the script

Post 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....
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
User avatar
Ragdag
Posts: 169
Joined: Friday 30 March 2018 13:56
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Netherlands
Contact:

Re: 2 timers how to determine which trigged the script

Post 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
User avatar
waltervl
Posts: 6691
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2025.1
Location: NL
Contact:

Re: 2 timers how to determine which trigged the script

Post 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...
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
User avatar
waltervl
Posts: 6691
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2025.1
Location: NL
Contact:

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

Post 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.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
User avatar
Ragdag
Posts: 169
Joined: Friday 30 March 2018 13:56
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Netherlands
Contact:

Re: 2 timers how to determine which trigged the script

Post 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:
Post Reply

Who is online

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