Hi there,
I'd like to have my watering started every second day and was wandering is there a trigger similar to 'every odd day' or 'every other day'?
Thanks for help and cheers,
Zavjah
Timer trigger for every second day [Solved]
Moderator: leecollings
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Timer trigger for every second day
zavjah wrote: Thursday 09 July 2020 18:15 I'd like to have my watering started every second day and was wandering is there a trigger similar to 'every odd day' or 'every other day'?
Code: Select all
-- This one executes on odd days (jan 1 = 1 and feb 1 = 32, etc ) at 19:38
return
{
on =
{
timer = { function(domoticz) return os.date('*t').yday % 2 == 1 and domoticz.time.matchesRule('at 19:38') end },
},
execute = function(dz)
dz.log('Do stuff on odd days',dz.LOG_FORCE)
end
}Code: Select all
-- This one executes every other day at 19:38 (Thx to @jvdz )
return
{
on =
{
timer = { function(domoticz) return math.floor(os.time()/86400) % 2 == 1 and domoticz.time.matchesRule('at 19:38') end },
},
execute = function(dz)
dz.log('Do stuff every other day',dz.LOG_FORCE)
end
}Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
zavjah
- Posts: 36
- Joined: Tuesday 13 August 2019 10:20
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
Re: Timer trigger for every second day
Awesome, thank you 
- jvdz
- Posts: 2446
- Joined: Tuesday 30 December 2014 19:25
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.107
- Location: Netherlands
- Contact:
Re: Timer trigger for every second day
Don't think this test is "full-proof":
The last day of this year and first day of next year will both be oneven:
31-12-2020 = 365
1-1-2021 = 1
.. so on 1 - jan - 2021 the script will run without the one day gap.
You probably need to work with the juliandate days since Epoch.
maybe:
Jos
Code: Select all
os.date('*t').yday % 2 == 131-12-2020 = 365
1-1-2021 = 1
.. so on 1 - jan - 2021 the script will run without the one day gap.
You probably need to work with the juliandate days since Epoch.
maybe:
Code: Select all
math.floor(os.time()/60/60/24) % 2 == 1
Last edited by jvdz on Saturday 11 July 2020 12:13, edited 1 time in total.
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Timer trigger for every second day
Thx. Nice catch. I add this to my post so OP can choosejvdz wrote: Friday 10 July 2020 15:05 The last day of this year and first day of next year will both be oneven:
maybe:Code: Select all
math.floor(os.time()/60/60/24) % 2 == 1
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Who is online
Users browsing this forum: No registered users and 1 guest