• 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
#1
I have one sunrise and one sunset rule.
I used labels to test for the exact times when these rules are being triggered.
The rules are using DATE_ADD() to shift the switching times 10 minutes before sunrise and 30 minutes after sunset.

Code:
"sunrise-decolight": {
"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",
"active": 1
},
"sunset-decolight": {
"rule": "IF (sunrisesetdev.sunset == DATE_FORMAT(DATE_ADD(datetimedev, +30 MINUTE), \"%Y-%m-%d %H:%M:%S\", %H.%M)) AND datetimedev.second == 0 THEN switch DEVICE light_deco_mirror_livingroom TO on AND label DEVICE labelsunset TO \"Sun set 30 minutes ago; Light on\" DATE_FORMAT(datetimedev, \"%d.%m.%Y %H:%M\") COLOR green",
"active": 1
}

My log shows correct timezone Europe/Berlin based on my latitude and longitude settings in config.json.
Code:
pilight-daemon: INFO: datetime datetimedev 13.404954:52.520007 seems to be in timezone: Europe/Berlin
pilight-daemon: INFO: sunriseset sunrisesetdev 13.404954:52.520007 seems to be in timezone: Europe/Berlin

The sunset rule is working as defined in config but the sunrise rule gets parsed one hour later.

Could there be an issue with DST and/or the timezone recognition in the latest version 8 or do I miss something else?
Code:
pilight-daemon version v8.0.4

In addition:
Placing the rule condition AND datetimedev.second == 0 inside the IF parenthesis is breaking the rule from getting parsed correctly at all.
Any ideas on this?
 
Reply
#2
Can you check this unittest to see if you can get it to fail with your findings?
https://github.com/pilight/pilight/blob/...ime.c#L122

Also, do the labels show the expected times?
 
Reply
#3
The labels do show the real time when the rules are actually trigger the switch. So they seems to be correct about the actual real switching time but not about the calculated time based on the rule.
Unfortunately I’m not very deep into C programming. So can you may be provide me a link or something for a little guide about getting into this pilight unit testing?
Is there something inside the manual what I might have missed?
 
Reply
#4
The calculated time used in the rules is the same time calculated time as shown in the labels right?
 
Reply
#5
The time calculation in the rule itself using DATE_ADD() is correct. And yes, the calculated time used in the rule is shown correctly in the labels.
The only mistake seems to be the given sunrise time from from zhe sunriseset device the rule trigger is based on.
As an example:
For today pilight shows sunrise at 8:15am.
So my sunrise rule should trigger at 8:05am but it actually switched off the lamp at 9:25 which seems to involve 2 mistakes:
1st: sunrise is 1 hour later
2nd: DATE_ADD() with negative value should subtract 10 minutes but it adds 10 minutes.
 
Reply
#6
Can you check the pilight log to see what the timestamps were for the execution of the actions? For example:
Code:
[Jan 08 17:44:47:568819] pilight-daemon: INFO: executed rule: sunrise-decolight
[Jan 08 17:44:47:568962] pilight-daemon: INFO: started "label" action for device "labelsunrise"
[Jan 08 17:44:47:568979] pilight-daemon: INFO: stopped "label" action for device "labelsunrise"
[Jan 08 17:44:47:569056] pilight-daemon: INFO: started "switch" action for device "light_deco_mirror_livingroom"
[Jan 08 17:44:47:569094] pilight-daemon: INFO: executed rule: sunset-decolight
[Jan 08 17:44:47:569124] pilight-daemon: INFO: stopped "switch" action for device "light_deco_mirror_livingroom"
[Jan 08 17:44:47:569222] pilight-daemon: INFO: started "label" action for device "labelsunset"
[Jan 08 17:44:47:569231] pilight-daemon: INFO: stopped "label" action for device "labelsunset"

Beware that the time you see is in UTC.

Secondly, check with pilight running with additional parsing information:
Code:
pilight-daemon --debuglevel=1
It will tell you how the rules are parsed.
Code:
[Jan 08 17:48:00:434640]pilight-daemon: DEBUG: broadcasted:
replace DATE_ADD(datetimedev, -10 MINUTE) with "2018-01-08 18:38:00" in DATE_ADD(datetimedev, -10 MINUTE)
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)
replace DATE_FORMAT("2018-01-08 18:38:00", "%Y-%m-%d %H:%M:%S", %H.%M) with 18.38 in sunrisesetdev.sunrise == DATE_FORMAT("2018-01-08 18:38:00", "%Y-%m-%d %H:%M:%S", %H.%M)
evaluate (OR) sunrisesetdev.sunrise == 18.38
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
[Jan 08 17:48:00:434879] pilight-daemon: DEBUG: rule #1 sunrise-decolight was parsed in 0.000076 seconds
replace DATE_ADD(datetimedev, +30 MINUTE) with "2018-01-08 19:18:00" in DATE_ADD(datetimedev, +30 MINUTE)
replace DATE_ADD(datetimedev, +30 MINUTE) with "2018-01-08 19:18:00" in sunrisesetdev.sunset == DATE_FORMAT(DATE_ADD(datetimedev, +30 MINUTE), "%Y-%m-%d %H:%M:%S", %H.%M)
replace DATE_FORMAT("2018-01-08 19:18:00", "%Y-%m-%d %H:%M:%S", %H.%M) with 19.18 in sunrisesetdev.sunset == DATE_FORMAT("2018-01-08 19:18:00", "%Y-%m-%d %H:%M:%S", %H.%M)
evaluate (OR) sunrisesetdev.sunset == 19.18
replace (sunrisesetdev.sunset == DATE_FORMAT(DATE_ADD(datetimedev, +30 MINUTE), "%Y-%m-%d %H:%M:%S", %H.%M)) with 0 in (sunrisesetdev.sunset == DATE_FORMAT(DATE_ADD(datetimedev, +30 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
[Jan 08 17:48:00:434933] pilight-daemon: DEBUG: rule #2 sunset-decolight was parsed in 0.000038 seconds
So if we analyze this:
1. It's 17:48:00 UTC time which means 18:48:00 in Berlin.

The first rule:
1. DATE_ADD(datetimedev, -10 MINUTE) is being parsed as "2018-01-08 18:38:00" which is correct.
2. DATE_FORMAT("2018-01-08 18:38:00", "%Y-%m-%d %H:%M:%S", %H.%M) is being parsed as 18.38 which is also correct.

The second rule:
1. DATE_ADD(datetimedev, +30 MINUTE) is being parsed as "2018-01-08 19:18:00" which is correct.
2. DATE_FORMAT("2018-01-08 19:18:00", "%Y-%m-%d %H:%M:%S", %H.%M) is being parsed as 19.18 which is also correct.

In both cases the actual datetime doesn't match the sunrise/sunset.

If we force the match:
Code:
IF sunrisesetdev.sunrise == 8.15 AND datetimedev.second > 0 THEN ...

Code:
[Jan 08 17:56:39:730219] pilight-daemon: DEBUG: broadcasted: {"origin":"receiver","protocol":"datetime","message":{"longitude":13.404954,"latitude":52.520007,"year":2018,"month":1,"day":8,"weekday":2,"hour":18,"minute":56,"second":39,"dst":0},"uuid":"0000-00-0c-29-3714d8"}
evaluate (AND) sunrisesetdev.sunrise == 8.15 AND datetimedev.second > 0
evaluate (AND) datetimedev.second > 0
replace DATE_FORMAT(datetimedev, "%d.%m.%Y %H:%M") with "08.01.2018 18:56" in "Sun rises in 10 minutes; Light off" DATE_FORMAT(datetimedev, "%d.%m.%Y %H:%M")
[Jan 08 17:56:39:730451] pilight-daemon: INFO: started "switch" action for device "light_deco_mirror_livingroom"
[Jan 08 17:56:39:730469] pilight-daemon: INFO: started "label" action for device "labelsunrise"
[Jan 08 17:56:39:730477] pilight-daemon: INFO: stopped "switch" action for device "light_deco_mirror_livingroom"
[Jan 08 17:56:39:730457] pilight-daemon: INFO: executed rule: sunrise-decolight

1. sunrisesetdev.sunrise == 8.15 applies because it continues to the next AND
2. datetimedev.second > 0 also applies so it triggers the action.

To see what happens when a condition doesn't apply:
Code:
[ Jan 08 17:59:30:99294] pilight-daemon: DEBUG: broadcasted: {"origin":"receiver","protocol":"datetime","message":{"longitude":13.404954,"latitude":52.520007,"year":2018,"month":1,"day":8,"weekday":2,"hour":18,"minute":59,"second":30,"dst":0},"uuid":"0000-00-0c-29-3714d8"}
evaluate (AND) sunrisesetdev.sunrise == 8.16 AND datetimedev.second > 0
skip (AND) datetimedev.second > 0
[ Jan 08 17:59:30:99437] pilight-daemon: DEBUG: rule #1 sunrise-decolight was parsed in 0.000097 seconds
You see that it skips the datetimedev.second evaluations because the left side of the condition already didn't apply.

I very curious if you can confirm that the rules are actually parsed correctly or not.


Then you've got a mistake in your logic as well.

1. The sunrise time is 8.15.
2. DATE_ADD(datetimedev, -10 MINUTE) means that 8.15 only applies at 8.25 in this case (8.25 - 0.10 = 8.15).

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
 
Reply
#7
I think I have the same problem. My rules are getting delayed one hour. That is also the difference between UTC and my timezone. pilight correctly detects my timezone from the coordinates. While trying to run pilight with debuglevel=1 to get the event code to print the details it doesn't even start for me. debuglevel=2 gets it to start but doesn't affect event.c. I'm running fully updated raspbian jessie and pilight 8.0.7. On a side note I wonder why isn't the internal time (i.e. the timestamps in the log file) of pilight the same as the timezone?
 
Reply
#8
What does it say with debuglevel = 1?
 
Reply
#9
Thanks for your reply. I run this command and it just prints the Usage screen. If i replace 1 with 2 it starts.
Code:
$ sudo pilight-daemon --debuglevel=1 --config=/etc/pilight/config.json
Usage: pilight-daemon [options]
    -H --help            display usage summary
    -V --version            display version
    -C --config            config file
    -S --server=x.x.x.x        connect to server address
    -P --port=xxxx            connect to server port
    -F --foreground        do not daemonize
    -D --debug            do not daemonize and
                    show debug information
        --stacktracer        show internal function calls
        --threadprofiler        show per thread cpu usage
        --debuglevel        show additional development info

    The following GPIO platforms are supported:
    - none
    - odroidxu4
    - odroidc2
    - odroidc1
    - raspberrypi3
    - raspberrypi2
    - raspberrypizero
    - raspberrypi1b+
    - raspberrypi1b2
    - raspberrypi1b1
    - hummingboard_edge_dq
    - hummingboard_gate_dq
    - hummingboard_edge_sdl
    - hummingboard_gate_sdl
    - hummingboard_base_dq
    - hummingboard_pro_dq
    - hummingboard_base_sdl
    - hummingboard_pro_sdl
    - orangepipc+
    - bananapim2
    - bananapi1
    - pcduino1

$ pilight-daemon -V
pilight-daemon version v8.0.7
 
Reply
#10
You will need the -D flag too

Code:
sudo pilight-daemon -D --debuglevel=1 --config=/etc/pilight/config.json
 
Reply
  


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

Forum Jump:


Browsing: 1 Guest(s)