Page 1 of 1

[closed] problem using two different time triggers

Posted: Saturday 04 March 2023 12:23
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

Re: problem using two different time triggers

Posted: Saturday 04 March 2023 14:45
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 ....

Re: problem using two different time triggers

Posted: Saturday 04 March 2023 15:47
by jvdz
Shouldn't the if's be change to timer.trigger?
eg: if (timer.trigger== "10 minutes after sunrise") then

Re: problem using two different time triggers

Posted: Saturday 04 March 2023 18:08
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