Question about timer condition

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

Moderator: leecollings

Post Reply
general07
Posts: 2
Joined: Saturday 27 September 2025 20:36
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Question about timer condition

Post by general07 »

Hello,

I'm trying to execute a scene, only once a day, if sunrise -10 minutes < 7:10 at 7:10, else at sunrise -10 minutes.

I tried with this code, but the scene is executed at the 2 timers :

Code: Select all

return {
	on = {
		timer = {
			'10 minutes before sunrise or at 7:10',
		},
	},
    execute = function(dz, device, info)
    dz.scenes("test").switchOn()
end
}
Is there a way to do this?
Thank you very much.
User avatar
habahabahaba
Posts: 266
Joined: Saturday 18 March 2023 14:44
Target OS: Windows
Domoticz version: 2024.4
Contact:

Re: Question about timer condition

Post by habahabahaba »

Something like this

Code: Select all


return {
	on = {
		timer = {

			function(domoticz)


                local setTime = '07:10'
                local minBeforSunrise = 10
                
				local currentDate = os.time()
				local minutesToSunrise = domoticz.time.sunriseInMinutes
				

				local setTimetoStamp = domoticz.time.dateToTimestamp(os.date("%Y-%m-%d "..setTime, currentDate))
 
				local CurrentSunriseTimeStamp = domoticz.time.dateToTimestamp(os.date("%Y-%m-%d 00:00", currentDate)) + minutesToSunrise * 60
				
				        if setTimetoStamp > (CurrentSunriseTimeStamp - minBeforSunrise*60) then
				            
                            --setTime = '08:00' for any case
                        else
                            setTime = '07:00'                            
                        end
                
                local setHour, setMin = setTime:match('(%d+):(%d+)')

                setHour = tonumber(setHour)
                setMin = tonumber(setMin)	
                
                local nowHour = domoticz.time.hour
                local nowMin = domoticz.time.min

                return (nowHour == setHour) and (nowMin == setMin)
				
			end,
		}
	},
	logging = {
		level = domoticz.LOG_INFO,
		marker = 'template',
	},
	execute = function(domoticz, timer)
		domoticz.log('Timer event was triggered by ' .. timer.trigger, domoticz.LOG_ERROR)
	end
}

general07
Posts: 2
Joined: Saturday 27 September 2025 20:36
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Question about timer condition

Post by general07 »

Thank you for your reply.
If I understand, there is no “easy way” to do this.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest