Timer 5 minute past the hour every 4 hours

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

Moderator: leecollings

Post Reply
FredZ
Posts: 30
Joined: Monday 08 June 2020 6:41
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Timer 5 minute past the hour every 4 hours

Post 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
User avatar
gizmocuz
Posts: 2536
Joined: Thursday 11 July 2013 18:59
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Top of the world
Contact:

Re: Timer 5 minute past the hour every 4 hours

Post 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
}
Quality outlives Quantity!
HvdW
Posts: 612
Joined: Sunday 01 November 2015 22:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Twente
Contact:

Re: Timer 5 minute past the hour every 4 hours

Post 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'
        }
Bugs bug me.
User avatar
gizmocuz
Posts: 2536
Joined: Thursday 11 July 2013 18:59
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Top of the world
Contact:

Re: Timer 5 minute past the hour every 4 hours

Post by gizmocuz »

Your AI solution won't work as it is only triggered every hour, not 5 minutes past.
Your second solution works perfect...
Quality outlives Quantity!
HvdW
Posts: 612
Joined: Sunday 01 November 2015 22:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Twente
Contact:

Re: Timer 5 minute past the hour every 4 hours

Post 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. 🥳
Bugs bug me.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest