Syntax dates in scripts

Moderator: leecollings

Post Reply
HennyN
Posts: 16
Joined: Friday 21 May 2021 21:42
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.7
Location: Achterhoek
Contact:

Syntax dates in scripts

Post by HennyN »

Hello,

I hope someone can and will help me.

I have a script I use to calculate my energy costs. That works. But.....
Energy costs change annually, so to compare costs per year, I actually need to add a date line to that.

I see in that script: if (domoticz.time == ‘Between 23:00 and 07:00’), but does that work the same way with a date?
So something like: if (domoticz.date == ‘Between 01-01-2023 and 01-01-2024’) etc....

Is that the right syntax, or does that work differently. It is not yet clear to me from the wiki how to do that.
Ultimately, I want to adjust the rates annually so that I can do clean comparisons over years.

Thanks in advance for answers.
Regards, Henny
HvdW
Posts: 612
Joined: Sunday 01 November 2015 22:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Twente
Contact:

Re: Syntax dates in scripts

Post by HvdW »

Code: Select all

local startDate = '2023-01-01'
local endDate = '2024-01-01'
local currentDate = domoticz.time.rawDate

if currentDate >= startDate and currentDate < endDate then
    print("Date is between 01-01-2023 and 01-01-2024")
else
    print("Date is outside the range")
end
Bugs bug me.
HennyN
Posts: 16
Joined: Friday 21 May 2021 21:42
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.7
Location: Achterhoek
Contact:

Re: Syntax dates in scripts

Post by HennyN »

Oké, Thanks (Bedankt! HvdW)

I'll work on it and see if I can get it working.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest