• 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
Sunrise and daylight saving time issue
#11
Confirmed. My fix replaced debuglevel=1 with 2 instead of allowing both. Pushed a new version with the fix.
 
Reply
#12
Thank you. debuglevel=1 works in 8.0.8. It seems my problem is in the DATE_FORMAT. Please have a look in the log below:

Code:
[Jan 21 11:17:14:290424] pilight-daemon: DEBUG: socket write succeeded: {"origin":"update","type":8,"uuid":"0000-b8-27-eb-3dd28f","devices":["date"],"values":{"timestamp":1516533434,"year":2018,"month":1,"day":21,"hour":12,"minute":17,"second":14,"dst":0,"weekday":1}}

[Jan 21 11:17:14:290519] pilight-daemon: DEBUG: broadcasted: {"origin":"update","type":8,"uuid":"0000-b8-27-eb-3dd28f","devices":["date"],"values":{"timestamp":1516533434,"year":2018,"month":1,"day":21,"hour":12,"minute":17,"second":14,"dst":0,"weekday":1}}
[Jan 21 11:17:14:290938] pilight-daemon: DEBUG: socket write succeeded: {"origin":"receiver","protocol":"datetime","message":{"longitude":x,"latitude":y,"year":2018,"month":1,"day":21,"weekday":1,"hour":12,"minute":17,"second":14,"dst":0},"uuid":"0000-b8-27-eb-3dd28f"}

[Jan 21 11:17:14:291002] pilight-daemon: DEBUG: broadcasted: {"origin":"receiver","protocol":"datetime","message":{"longitude":x,"latitude":y,"year":2018,"month":1,"day":21,"weekday":1,"hour":12,"minute":17,"second":14,"dst":0},"uuid":"0000-b8-27-eb-3dd28f"}
replace DATE_ADD(date, +2 MINUTE) with "2018-01-21 12:19:14" in DATE_ADD(date, +2 MINUTE)
replace DATE_ADD(date, +2 MINUTE) with "2018-01-21 12:19:14" in 12.20 == DATE_FORMAT(DATE_ADD(date, +2 MINUTE), "%Y-%m-%d %H:%M:%S", %H.%M)
replace DATE_FORMAT("2018-01-21 12:19:14", "%Y-%m-%d %H:%M:%S", %H.%M) with 11.19 in 12.20 == DATE_FORMAT("2018-01-21 12:19:14", "%Y-%m-%d %H:%M:%S", %H.%M)
evaluate (OR) 12.20 == 11.19
replace (12.20 == DATE_FORMAT(DATE_ADD(date, +2 MINUTE), "%Y-%m-%d %H:%M:%S", %H.%M)) with 0 in (12.20 == DATE_FORMAT(DATE_ADD(date, +2 MINUTE), "%Y-%m-%d %H:%M:%S", %H.%M)) AND date.second == 0
evaluate (AND) 0 AND date.second == 0
skip (AND) date.second == 0
[Jan 21 11:17:14:292461] pilight-daemon: DEBUG: rule #3 test-rule was parsed in 0.000894 seconds

The rule looks like this:
Code:
"test-rule": {
            "rule": "IF (12.20 == DATE_FORMAT(DATE_ADD(date, +2 MINUTE), \"%Y-%m-%d %H:%M:%S\", %H.%M)) AND date.second == 0 THEN switch DEVICE Sanglampa TO on",
            "active": 1
        }
Thanks
 
Reply
#13
Good catch! Can you check the latest staging code on github?
 
Reply
#14
Big Grin 
Just tested it. Checked out tag v8.0.8 and applied the fix. Seems to work fine. New log below. Thanks for the quick fix. Smile

Code:
[Jan 21 18:41:26:423887] pilight-daemon: DEBUG: cpu: 0.431694%
[Jan 21 18:41:26:435847] pilight-daemon: DEBUG: socket write succeeded: {"origin":"update","type":8,"uuid":"0000-b8-27-eb-3dd28f","devices":["date"],"values":{"timestamp":1516560086,"year":2018,"month":1,"day":21,"hour":19,"minute":41,"second":26,"dst":0,"weekday":1}}

[Jan 21 18:41:26:435947] pilight-daemon: DEBUG: broadcasted: {"origin":"update","type":8,"uuid":"0000-b8-27-eb-3dd28f","devices":["date"],"values":{"timestamp":1516560086,"year":2018,"month":1,"day":21,"hour":19,"minute":41,"second":26,"dst":0,"weekday":1}}
[Jan 21 18:41:26:436321] pilight-daemon: DEBUG: socket write succeeded: {"origin":"receiver","protocol":"datetime","message":{"longitude":x,"latitude":y,"year":2018,"month":1,"day":21,"weekday":1,"hour":19,"minute":41,"second":26,"dst":0},"uuid":"0000-b8-27-eb-3dd28f"}

[Jan 21 18:41:26:436379] pilight-daemon: DEBUG: broadcasted: {"origin":"receiver","protocol":"datetime","message":{"longitude":x,"latitude":y,"year":2018,"month":1,"day":21,"weekday":1,"hour":19,"minute":41,"second":26,"dst":0},"uuid":"0000-b8-27-eb-3dd28f"}
replace DATE_ADD(date, +2 MINUTE) with "2018-01-21 19:43:26" in DATE_ADD(date, +2 MINUTE)
replace DATE_ADD(date, +2 MINUTE) with "2018-01-21 19:43:26" in 12.20 == DATE_FORMAT(DATE_ADD(date, +2 MINUTE), "%Y-%m-%d %H:%M:%S", %H.%M)
replace DATE_FORMAT("2018-01-21 19:43:26", "%Y-%m-%d %H:%M:%S", %H.%M) with 19.43 in 12.20 == DATE_FORMAT("2018-01-21 19:43:26", "%Y-%m-%d %H:%M:%S", %H.%M)
evaluate (OR) 12.20 == 19.43
replace (12.20 == DATE_FORMAT(DATE_ADD(date, +2 MINUTE), "%Y-%m-%d %H:%M:%S", %H.%M)) with 0 in (12.20 == DATE_FORMAT(DATE_ADD(date, +2 MINUTE), "%Y-%m-%d %H:%M:%S", %H.%M)) AND date.second == 0
evaluate (AND) 0 AND date.second == 0
skip (AND) date.second == 0
[Jan 21 18:41:26:437827] pilight-daemon: DEBUG: rule #3 test-rule was parsed in 0.000874 seconds
 
Reply
#15
(01-08-2018, 07:06 PM)curlymo Wrote: I can't confirm the enclosing of the datetimedev.seconds either. This runs fine:
Code:
IF (sunriseset.sunrise == DATE_FORMAT(DATE_ADD(datetimedev, -10 MINUTE), \"%Y-%m-%d %H:%M:%S\", %H.%M) AND datetimedev.second == 0) THEN switch DEVICE light_deco_mirror_livingroom TO off AND label DEVICE labelsunrise TO \"Sun rises in 10 minutes; Light off\" DATE_FORMAT(datetimedev, \"%d.%m.%Y %H:%M\") COLOR green

Code:
[Jan 08 18:05:03:990257] pilight-daemon: DEBUG: broadcasted: {"origin":"receiver","protocol":"datetime","message":{"longitude":13.404954,"latitude":52.520007,"year":2018,"month":1,"day":8,"weekday":2,"hour":19,"minute":5,"second":3,"dst":0},"uuid":"0000-00-0c-29-3714d8"}
replace DATE_ADD(datetimedev, -10 MINUTE) with "2018-01-08 18:55:03" in DATE_ADD(datetimedev, -10 MINUTE)
replace DATE_ADD(datetimedev, -10 MINUTE) with "2018-01-08 18:55:03" in sunriseset.sunrise == DATE_FORMAT(DATE_ADD(datetimedev, -10 MINUTE), "%Y-%m-%d %H:%M:%S", %H.%M) AND datetimedev.second == 0
replace DATE_FORMAT("2018-01-08 18:55:03", "%Y-%m-%d %H:%M:%S", %H.%M) with 18.55 in sunriseset.sunrise == DATE_FORMAT("2018-01-08 18:55:03", "%Y-%m-%d %H:%M:%S", %H.%M) AND datetimedev.second == 0
evaluate (OR) sunriseset.sunrise == 18.55 AND datetimedev.second == 0
replace (sunriseset.sunrise == DATE_FORMAT(DATE_ADD(datetimedev, -10 MINUTE), "%Y-%m-%d %H:%M:%S", %H.%M) AND datetimedev.second == 0) with sunriseset.sunrise == 18.55 AND datetimedev.second == 0 in (sunriseset.sunrise == DATE_FORMAT(DATE_ADD(datetimedev, -10 MINUTE), "%Y-%m-%d %H:%M:%S", %H.%M) AND datetimedev.second == 0)
evaluate (AND) sunriseset.sunrise == 18.55 AND datetimedev.second == 0
skip (AND) datetimedev.second == 0
Code:
replace DATE_ADD(datetimedev, -10 MINUTE) with "2018-01-08 18:38:00" in sunrisesetdev.sunrise == DATE_FORMAT(DATE_ADD(datetimedev, -10 MINUTE), "%Y-%m-%d %H:%M:%S", %H.%M)
vs
Code:
replace DATE_ADD(datetimedev, -10 MINUTE) with "2018-01-08 18:55:03" in sunriseset.sunrise == DATE_FORMAT(DATE_ADD(datetimedev, -10 MINUTE), "%Y-%m-%d %H:%M:%S", %H.%M) AND datetimedev.second == 0

I can't get it to work if I enclose the datetimedev.seconds. I also get other replacing values than you.

The following rule syntax seems to behave differently than the second one (notice the different (and wrong?) replacing than in your example and also the differences in setting the parenthesis for AND datetimedev.second == 0):
Code:
"rule": "IF (sunrisesetdev.sunrise == DATE_FORMAT(DATE_ADD(datetimedev, +10 MINUTE), \"%Y-%m-%d %H:%M:%S\", %H.%M)) AND datetimedev.second == 0 THEN switch DEVICE light_deco_mirror_livingroom TO off AND label DEVICE labelsunrise TO \"sun rises in 10 minutes; light off\" DATE_FORMAT(datetimedev, \"%d.%m.%Y %H:%M\") COLOR green"
vs
Code:
"rule": "IF (sunrisesetdev.sunrise == DATE_FORMAT(DATE_ADD(datetimedev, +10 MINUTE), \"%Y-%m-%d %H:%M:%S\", %H.%M) AND datetimedev.second == 0) THEN switch DEVICE light_deco_mirror_livingroom TO off AND label DEVICE labelsunrise TO \"sun rises in 10 minutes; light off\" DATE_FORMAT(datetimedev, \"%d.%m.%Y %H:%M\") COLOR green"


pilight debug for the first rule syntax gives me:
Code:
[Jan 24 17:54:08:823575] pilight-daemon: DEBUG: broadcasted: {"origin":"receiver","protocol":"datetime","message":{"longitude":13.404954,"latitude":52.520007,"year":2018,"month":1,"day":24,"weekday":4,"hour":18,"minute":54,"second":8,"dst":0},"uuid":"0000-b8-27-eb-0f8ee3"}
replace DATE_ADD(datetimedev, +10 MINUTE) with "2018-01-24 19:04:08" in DATE_ADD(datetimedev, +10 MINUTE)
replace DATE_ADD(datetimedev, +10 MINUTE) with "2018-01-24 19:04:08" in sunrisesetdev.sunrise == DATE_FORMAT(DATE_ADD(datetimedev, +10 MINUTE), "%Y-%m-%d %H:%M:%S", %H.%M)
replace DATE_FORMAT("2018-01-24 19:04:08", "%Y-%m-%d %H:%M:%S", %H.%M) with 19.04 in sunrisesetdev.sunrise == DATE_FORMAT("2018-01-24 19:04:08", "%Y-%m-%d %H:%M:%S", %H.%M)
evaluate (OR) sunrisesetdev.sunrise == 19.04
replace (sunrisesetdev.sunrise == DATE_FORMAT(DATE_ADD(datetimedev, +10 MINUTE), "%Y-%m-%d %H:%M:%S", %H.%M)) with 0 in (sunrisesetdev.sunrise == DATE_FORMAT(DATE_ADD(datetimedev, +10 MINUTE), "%Y-%m-%d %H:%M:%S", %H.%M)) AND datetimedev.second == 0
evaluate (AND) 0 AND datetimedev.second == 0
skip (AND) datetimedev.second == 0

while pilight debug for the second rule syntax shows:
Code:
[Jan 24 17:22:43:720194] pilight-daemon: DEBUG: broadcasted: {"origin":"receiver","protocol":"datetime","message":{"longitude":13.404954,"latitude":52.520007,"year":2018,"month":1,"day":24,"weekday":4,"hour":18,"minute":22,"second":43,"dst":0},"uuid":"0000-b8-27-eb-0f8ee3"}
replace DATE_ADD(datetimedev, +10 MINUTE) with "2018-01-24 18:32:43" in DATE_ADD(datetimedev, +10 MINUTE)
replace DATE_ADD(datetimedev, +10 MINUTE) with "2018-01-24 18:32:43" in sunrisesetdev.sunrise == DATE_FORMAT(DATE_ADD(datetimedev, +10 MINUTE), "%Y-%m-%d %H:%M:%S", %H.%M) AND datetimedev.second == 0
replace DATE_FORMAT("2018-01-24 18:32:43", "%Y-%m-%d %H:%M:%S", %H.%M) with 18.32 in sunrisesetdev.sunrise == DATE_FORMAT("2018-01-24 18:32:43", "%Y-%m-%d %H:%M:%S", %H.%M) AND datetimedev.second == 0
evaluate (OR) sunrisesetdev.sunrise == 18.32 AND datetimedev.second == 0
replace (sunrisesetdev.sunrise == DATE_FORMAT(DATE_ADD(datetimedev, +10 MINUTE), "%Y-%m-%d %H:%M:%S", %H.%M) AND datetimedev.second == 0) with 1 in (sunrisesetdev.sunrise == DATE_FORMAT(DATE_ADD(datetimedev, +10 MINUTE), "%Y-%m-%d %H:%M:%S", %H.%M) AND datetimedev.second == 0)
skip (OR) 1

If I understand you correctly this shouldn't be the case right? Also the replacements of "0" and "1" are not right. There should be the current parsed time. Am I correct in reading this?
 
Reply
#16
You indeed found a bug with the event parser (that i'm not able to fix to my own liking). But, can you try this intermediate try:
Code:
diff --git a/libs/pilight/events/events.c b/libs/pilight/events/events.c
index 0d89f6bd..14c43b19 100644
--- a/libs/pilight/events/events.c
+++ b/libs/pilight/events/events.c
@@ -982,6 +999,9 @@ static int event_parse_formula(char **rule, struct rules_t *obj, int depth, unsi
                        } if(search != NULL ) {
                                memset(search, '\0', strlen(search));
                        }
+                       if(strcmp(tmp, "AND") == 0 || strcmp(tmp, "OR") == 0) {
+                               break;
+                       }
 
Reply
#17
Hello all,

Looks like there is still an issue with DST calculation. This is a log captured at 8:38 CEST

Code:
replace DATE_ADD(CurrentDateTime, -1 HOUR) with "2018-03-26 07:36:25" in DATE_ADD(CurrentDateTime, -1 HOUR)
replace DATE_ADD(CurrentDateTime, -1 HOUR) with "2018-03-26 07:36:25" in wetterWangen.sunset == DATE_FORMAT(DATE_ADD(CurrentDateTime, -1 HOUR), "%Y-%m-%d %H:%M:%S", %H.%M)
replace DATE_FORMAT("2018-03-26 07:36:25", "%Y-%m-%d %H:%M:%S", %H.%M) with 08.36 in wetterWangen.sunset == DATE_FORMAT("2018-03-26 07:36:25", "%Y-%m-%d %H:%M:%S", %H.%M)
evaluate (OR) wetterWangen.sunset == 08.36
replace (wetterWangen.sunset == DATE_FORMAT(DATE_ADD(CurrentDateTime, -1 HOUR), "%Y-%m-%d %H:%M:%S", %H.%M)) with 0 in (wetterWangen.sunset == DATE_FORMAT(DATE_ADD(CurrentDateTime, -1 HOUR), "%Y-%m-%d %H:$
evaluate (AND) 0 AND LichtTerrasseAuto.state IS on AND CurrentDateTime.second == 0
evaluate (AND) LichtTerrasseAuto.state IS on AND CurrentDateTime.second == 0
evaluate (AND) CurrentDateTime.second == 0
[Mar 26 06:38:06:268330] pilight-daemon: INFO: rule #10 LichtTerrasseSunset was parsed in 0.005234 seconds
For some reason one hour is added in the comparation.
This is version 8.0.9. Can anyone confirm this issue?
 
Reply
#18
Can you provide me with a minimal test so i can confirm myself?
 
Reply
#19
This is my rule:

Code:
"LichtTerrasseSunset": {
   "rule": "IF (7.08 == DATE_FORMAT(DATE_ADD(CurrentDateTime, -1 HOUR), \"%Y-%m-%d %H:%M:%S\", %H.%M)) AND LichtTerrasseAuto.state IS on AND CurrentDateTime.second == 0 THEN switch DEVICE LichtTerrasse TO on",
   "active": 1
},

I replaced the variable providing the sunset time with a constant, that makes no difference.
 
Reply
#20
Can you check version 8.0.10?
 
Reply
  


Possibly Related Threads...
Thread Author Replies Views Last Post
Bug Full cpu usage after random time andiwand 4 1,830 05-01-2016, 09:05 PM
Last Post: andiwand
  Time based calculations wo_rasp 7 2,342 03-19-2016, 01:28 AM
Last Post: wo_rasp
  [Solved] Time Stamp Information wo_rasp 5 1,938 03-05-2016, 11:29 PM
Last Post: curlymo

Forum Jump:


Browsing: 1 Guest(s)