[closed] problem using two different time triggers

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

Moderator: leecollings

Post Reply
BartSr
Posts: 491
Joined: Sunday 03 July 2016 16:16
Target OS: Raspberry Pi / ODroid
Domoticz version: V2024.7
Location: Netherlands
Contact:

[closed] problem using two different time triggers

Post by BartSr »

Hi,
Below my code.

Code: Select all

return {
	on = {
		timer = {
			'10 minutes after sunrise',
			'30 minutes after sunset',
				}
	},
	logging = {
		level = domoticz.LOG_INFO,
		marker = 'template',
	},
	execute = function(dz, timer)
	    if (timer == "10 minutes after sunrise") then
	    
	        dz.openURL({
	        url = "http://192.168.2.18/control?cmd=pulse,14,1,500" --luik omhoog
            })
    
        end
	    
	    if (timer == "30 minutes after sunset") then
	        	        
	        dz.openURL({
	        url = "http://192.168.2.18/control?cmd=pulse,13,1,500" --luik omlaag
	        })
	    
	    end
		dz.log('Timer event was triggered by ' .. timer.trigger, dz.LOG_INFO)
	end
}
This code is intended to open/close window-shutter.
The (somfy) shutter can be controlled using pushbuttons from domoticz.
The pushbuttons do avtivate the shutter using code:
http://192.168.2.18/control?cmd=pulse,14,1,500 for shutter up
and
http://192.168.2.18/control?cmd=pulse,13,1,500 for shutter down

That worked as expected. But as dzVents has better time possibilities for trigger I want to use dzVents.
As seen in the code shutter has to go up 10 min after sunrise and close 30 min after sunset.
But as a matter of facts nothing happens.

What is wrong in my code? Or are my expectations wrong ?

TIA
-Bart
Last edited by BartSr on Saturday 04 March 2023 18:08, edited 1 time in total.
Raspberry pi 3b
Arduino
KAKU
RfxCom
Zwave2MQTT
OTGW
Chinese sensors temp (Dallas),movement
Tasmota
Esp8266 / 32 espeasy
Zigbee2MQTT
willemd
Posts: 741
Joined: Saturday 21 September 2019 17:55
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.1
Location: The Netherlands
Contact:

Re: problem using two different time triggers

Post by willemd »

If you put in several dz.log() statements in your code, you should be able to find out what exactly happens and where the program does not function as expected.

Of course, to avoid waiting a full day for this debugging, you better change the timers while doing this ....
User avatar
jvdz
Posts: 2446
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: problem using two different time triggers

Post by jvdz »

Shouldn't the if's be change to timer.trigger?
eg: if (timer.trigger== "10 minutes after sunrise") then
BartSr
Posts: 491
Joined: Sunday 03 July 2016 16:16
Target OS: Raspberry Pi / ODroid
Domoticz version: V2024.7
Location: Netherlands
Contact:

Re: problem using two different time triggers

Post by BartSr »

Thanks guys, I changed the code with you help into:

Code: Select all

return {
	on = {
		timer = {
			'10 minutes after sunrise',
			'15 minutes after sunset',
		}
	},
	logging = {
		level = domoticz.LOG_INFO,
		marker = 'template',
	},
	execute = function(dz, timer)


	    if (timer.trigger == "10 minutes after sunrise") then

	        dz.openURL({
	        url = "http://192.168.2.18/control?cmd=pulse,14,1,500" --luik omhoog
            })
    
        end
	    
	    if (timer.trigger == "15 minutes after sunset") then

	        dz.openURL({
	        url = "http://192.168.2.18/control?cmd=pulse,13,1,500" --luik omlaag
	        })
	    
	    end
		dz.log('Timer event was triggered by ' .. timer.trigger, dz.LOG_INFO)
	end
}
And the changed "timer.trigger" did the job.
I checked by setting the trigger to xx minutes before sunset which made the trigger fire within just a minute.
Problem solved!

Thanks
Bart
Raspberry pi 3b
Arduino
KAKU
RfxCom
Zwave2MQTT
OTGW
Chinese sensors temp (Dallas),movement
Tasmota
Esp8266 / 32 espeasy
Zigbee2MQTT
Post Reply

Who is online

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