Page 1 of 1
Timer 5 minute past the hour every 4 hours
Posted: Wednesday 26 March 2025 5:20
by FredZ
Hello all
I have a script that triggers (turns on a pump) every 4 hours. and it works fine. however, I would like it to trigger 5 minutes past the hour instead of on the hour. No real reason why except for ease of viewing/scanning log as I have several events running at the same time.
Code: Select all
},
timer = {
'every 4 hours', -- Adjust this if necessary
},
},
EG: 0005 0405 0805 1205 1605 2005
Can this be done simply?
FYI: Since I changed all my scripts to dzVents I haven't had any fail to run.
Regards
Fred
Re: Timer 5 minute past the hour every 4 hours
Posted: Wednesday 26 March 2025 8:19
by gizmocuz
You could do something like this:
Code: Select all
return {
on = {
timer = {
'at *:05', -- called every 5th minute in the hour
}
},
logging = {
level = domoticz.LOG_INFO,
marker = 'template',
},
execute = function(domoticz, timer)
local act_hour = tonumber(os.date('%H'))
if ((act_hour % 4) ~= 0) then
do return end -- we don't want to be calle yet
end
domoticz.log('This IS called every forth hour!', domoticz.LOG_INFO)
end
}
Re: Timer 5 minute past the hour every 4 hours
Posted: Wednesday 26 March 2025 9:42
by HvdW
What about this?
light.switchOn().checkFirst().afterMin(5)
From the wiki.
Your pump could maybe use this one as well:
light.switchOff().afterMin(15)
I asked AI as well
Code: Select all
return {
on = {
timer = {'every hour'} -- Checks every hour, but only triggers at 4-hour intervals
},
execute = function(domoticz)
local time = domoticz.time
local currentHour = time.hour
local currentMinute = time.min
-- Check if it's 5 minutes past the hour AND hour % 4 == 0 (every 4 hours)
if (currentMinute == 5) and (currentHour % 4 == 0) then
domoticz.log("Triggering pump at " .. time.rawTime, domoticz.LOG_INFO)
domoticz.devices("Your Pump Name").switchOn() -- Replace with your pump's name
end
end
}
It uses domoticz.time which is elegant.
Another solution
Code: Select all
on = {
timer = {
'at 00:05', 'at 04:05', 'at 08:05',
'at 12:05', 'at 16:05', 'at 20:05'
}
Re: Timer 5 minute past the hour every 4 hours
Posted: Wednesday 26 March 2025 15:23
by gizmocuz
Your AI solution won't work as it is only triggered every hour, not 5 minutes past.
Your second solution works perfect...
Re: Timer 5 minute past the hour every 4 hours
Posted: Wednesday 26 March 2025 16:00
by HvdW
gizmocuz wrote: ↑Wednesday 26 March 2025 15:23
Your AI solution won't work as it is only triggered every hour, not 5 minutes past.
Your second solution works perfect...
The second is human.
