Current date and Date user variables

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

Moderator: leecollings

Post Reply
galinette
Posts: 68
Joined: Monday 11 December 2017 22:57
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Current date and Date user variables

Post by galinette »

Hi,

I want to do a simple thing : test if the current date matches the value of a user variable of "Date" type.

Code: Select all

domoticz.variables("MyDate").value
returns a string that looks like : "25/12/2018"

but:

Code: Select all

domoticz.time.rawDate
returns a string that looks like : "2018-12-25"

So I cannot compare the two. Also:

Code: Select all

domoticz.time.matchesRule('on '.. domoticz.variables("MyDate").value)
Does not work since the trigger rules cannot have a dd/mm/yyyy format, only dd/mm

As a workaround I now rely on:

Code: Select all

local day = domoticz.time.day
local month = domoticz.time.month
local year = domoticz.time.year
local date = day .. '/' .. month .. '/' .. year
if date==domoticz.variables(MyDate').value then
That's quite cumbersome for a simple task, and this is awfully non robust as it will break if the date format changes.

Is there any good solution?

Thanks!
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Current date and Date user variables

Post by waaren »

galinette wrote: Monday 10 December 2018 22:41 I want to do a simple thing : test if the current date matches the value of a user variable of "Date" type.

Code: Select all

domoticz.variables("MyDate").value
returns a string that looks like : "25/12/2018"

Code: Select all

domoticz.time.rawDate
returns a string that looks like : "2018-12-25"
Is there any good solution?
yes !
use

Code: Select all

domoticz.time.matchesRule('on '.. domoticz.variables("MyDate").date.rawDate)
Other Variable attributes and methods can be found here
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: Current date and Date user variables

Post by dannybloe »

Or you use the date object’s compare function. See the docs.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests