• 10 dec 2017: forum version update. In case of issues use this topic.
  • 30 nov 2017: pilight moved servers. In case of issues use this topic.
Hello There, Guest! Login Register


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
DATE_FORMAT & DATE_ADD
#1
This rule will not work, but will be parsed without failure.
What its wrong here:

Code:
"sunset": {
                        "rule": "IF sun.sunset == DATE_FORMAT(DATE_ADD(date_time, -10 MINUTE), \"%Y-%m-%d %H:%M:%S\", %H.%M) AND elro.state IS off AND date_time.second == 0 THEN switch DEVICE elro TO on",
                        "active": 1
                },

The sunset was today 16:07 and the device "elro" should become a on-signal 16:17.
The device will work manually correct. (Turn off and on in web-gui)

Thx.
Ralf[/align]
 
Reply
#2
Omit: AND date_time.second == 0
 
Reply
#3
Ok i´ve testet.

Code:
"rule": "IF (19.41 == DATE_FORMAT(DATE_ADD(date_time, -2 MINUTE), \"%Y-%m-%d %H:%M:%S\", %H.%M)) AND elro.state IS on THEN switch DEVICE elro TO off",

The elro is actually "on", 19.41 is the "sunset-dummy", because its only once per day ;-)
So the elro should going off at 19:43, but it does´t work either.

Here are the devices:

Code:
"elro": {
                        "protocol": [ "elro_800_switch" ],
                        "id": [{
                                "systemcode": 5,
                                "unitcode": 8
                        }],
                        "state": "on"
                },
                "sun": {
                        "protocol": [ "sunriseset" ],
                        "id": [{
                                "longitude": 12.8682,
                                "latitude": 50.5771312
                        }],
                        "sunrise": 8.07,
                        "sunset": 16.07,
                        "sun": "set"
                },
                "date_time": {
                        "protocol": [ "datetime" ],
                        "id": [{
                                "longitude": 12.8682,
                                "latitude": 50.5771312
                        }],
                        "year": 2016,
                        "month": 12,
                        "day": 20,
                        "hour": 19,
                        "minute": 41,
                        "second": 44,
                        "weekday": 3,
                        "dst": 0
                },
 
Reply
#4
Ok my last test was at 20:03,
an now - 1 hour later - the elro going off ;-)

But what causing the one hour shift (internal/system dst or timezone)?
Datetime in the GUI shows the correct time.
 
Reply
#5
@curlymo
I can confirm that the behaviour is incorrect, to me it seems that the function DATE_FORMAT is comparing time against UTC time, no matter whether time is provided as a numeric value or via the sunriseset protocol.
Code:
root@pi_65:/home/pi/pilight/libs/pilight/core# date
Di 20. Dez 22:05:29 CET 2016
root@pi_65:/home/pi/pilight/libs/pilight/core# raspi-config
Current default time zone: 'Europe/Berlin'
Local time is now:      Tue Dec 20 22:05:40 CET 2016.
Universal Time is now:  Tue Dec 20 21:05:40 UTC 2016.
@heural
Until further notice, i propose that you manually offset the comparison by 60 minutes if you are using the DATE_FUNCTION.

For the objects of the datetime protocol everything is okay.
For example, the following rule will trigger the associated action at 21:30 local time.
Code:
"RuleShutter_down_at_21:30": {
"rule": "IF Automaticmode.state IS on AND Shutter.state ISNOT down AND (date_time.second == 0 AND date_time.minute == 30 AND date_time.hour == 21) THEN switch DEVICE Shutter TO down",
"active": 1
},
 
Reply
#6
Datetime functions are thouroughly revisited in the rewrite code. It is now based on the Olsen TZ database. That should fix the UTC / Timezone issues.
 
Reply
#7
Ok thx at all!
I add the hour to the date_add function and this works.
(10 min after sunset: date_add +50 MINUTE)
I´ve noticed that the Datetime-Stamp in Logfile also gets the UTC.
 
Reply
#8
Logfile UTC is intentional.
 
Reply
  


Possibly Related Threads...
Thread Author Replies Views Last Post
  DATE_FORMAT → invalid: trying to compare string variable "21:30:00" to an integer PekkaLahtela 6 3,963 12-22-2016, 09:49 AM
Last Post: wo_rasp
  function: DATE_ADD Niek 8 4,487 12-18-2015, 01:15 PM
Last Post: mfhotdog

Forum Jump:


Browsing: 1 Guest(s)