How to set timer to last day of the month

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

Moderator: leecollings

Post Reply
Kranendijk
Posts: 60
Joined: Wednesday 29 May 2019 14:39
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Location: Zwolle
Contact:

How to set timer to last day of the month

Post by Kranendijk »

Hi all,

Thanks to the great help of this forum Inwas able to use dzvents for my energy meter. I have a script to copy the current week total to another device to store it as last week. A timer running each saturday at 23:55 does that job.
Now I want something similar for the month values. Like “rune every last day of the month at 23:55”. Should be possible but I am not able to figure that out.

Can’t be difficult, but I don’t see it...

Help appeciated. As always :D
HvdW
Posts: 505
Joined: Sunday 01 November 2015 22:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Twente
Contact:

Re: How to set timer to last day of the month

Post by HvdW »

Cron does the job.
Take a look over here.

I'm testing this one:
If you're lucky to be using one of those implementations, it's as simple as:
55 23 L * * ?
Bugs bug me.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: How to set timer to last day of the month

Post by waaren »

Kranendijk wrote: Thursday 28 January 2021 18:53 Now I want something similar for the month values. Like “rune every last day of the month at 23:55”. Should be possible but I am not able to figure that out.
This could do it

Code: Select all

return
{
    on =
    {
        timer =
        {
            'at 23:55 on 28/2,29/2,30/*,31/*',
        },
    },

    execute = function(dz, item)
        if os.date("%d", os.time() + 24 * 3600 )  ~= '01' then
            dz.log(item.trigger .. " ==>> today is not the last day of the month" , dz.LOG_FORCE)
            return
        else
            dz.log(item.trigger .. " ==>> today is the last day of the month" , dz.LOG_FORCE)
        end

        dz.log('rest of the script below this line', 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
Kranendijk
Posts: 60
Joined: Wednesday 29 May 2019 14:39
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Location: Zwolle
Contact:

Re: How to set timer to last day of the month

Post by Kranendijk »

Really. That simple??
I’ll give it a shot, big thanks!
HvdW
Posts: 505
Joined: Sunday 01 November 2015 22:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Twente
Contact:

Re: How to set timer to last day of the month

Post by HvdW »

That's 7 times twice on 30th and 31th
Bugs bug me.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: How to set timer to last day of the month

Post by waaren »

HvdW wrote: Thursday 28 January 2021 21:21 That's 7 times twice on 30th and 31th
True but in the execute part of the script there is an extra check that will stop the execution of the script if it is not the last day of the month, before the scripts real work starts.
Do you know a better way in pure dzVents ?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
HvdW
Posts: 505
Joined: Sunday 01 November 2015 22:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Twente
Contact:

Re: How to set timer to last day of the month

Post by HvdW »

Correct @waaren
For simplicity you could trigger it every day as well, like:

Code: Select all

return
{
    on =
    {
        timer =
        {
            'at 23:55',
        },
    },

    execute = function(dz, item)
        if os.date("%d", os.time() + 24 * 3600 )  ~= '01' then
            dz.log(item.trigger .. " ==>> today is not the last day of the month" , dz.LOG_FORCE)
            return
        else
            dz.log(item.trigger .. " ==>> today is the last day of the month" , dz.LOG_FORCE)
        end

        dz.log('rest of the script below this line', dz.LOG_FORCE )
    end
}
Bugs bug me.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: How to set timer to last day of the month

Post by waaren »

HvdW wrote: Thursday 28 January 2021 22:12 For simplicity you could trigger it every day as well, like:
The time rule looks indeed a bit intricate at first but that is only once and you save 365 - 19 = 346 unnecessary script triggers yearly by using it.
I can live with both approaches :D
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
HvdW
Posts: 505
Joined: Sunday 01 November 2015 22:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Twente
Contact:

Re: How to set timer to last day of the month

Post by HvdW »

Correct again @Waaren
I like script simplicity and computers don't care about repetition.
How many times a day is this script being run to check if it's 23:55?
Bugs bug me.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest