Update/refresh sunrise and sunset variables


#1

1) Give a description of the problem
It seems the sunrise and sunset from the previous day are used to schedule the piston, even after I have added a trigger for it to run daily just after midnight.
Am I running it too soon after midnight, or is there something else at play here that I do not understand?
In any case, do I need to move the timer to after 3AM in order to correctly capture changes due to daylight savings time? We moved the clock forward on 28 March as can be seen in the logs.

2) What is the expected behaviour?
I would expect the timer to turn the switch on or off should run at the current sunrise and sunset (eg. the same times as specified in the log statement run just after midnight)

3) What is happening/not happening?
The piston appears to trigger based on the sunrise and sunset from the previous day.

**4) Post a Green Snapshot of the piston

5) Attach logs after turning logging level to Full
3/29/2021, 7:16:59 AM +62ms
+0ms ╔Received event [My home].time = 1616995020000 with a delay of -939ms
+45ms ║RunTime Analysis CS > 21ms > PS > 6ms > PE > 18ms > CE
+47ms ║Runtime (39520 bytes) successfully initialized in 6ms (v0.3.113.20210203) (46ms)
+48ms ║╔Execution stage started
+82ms ║║Cancelling statement #7’s schedules…
+286ms ║║Executed physical command [Outdoor lights simulated switch].off() (199ms)
+287ms ║║Executed [Outdoor lights simulated switch].off (202ms)
+293ms ║║Calculating (string) Switch turned off at: + (string) Mon, Mar 29 2021 @ 7:16:59 AM CEST >> (string) Switch turned off at: Mon, Mar 29 2021 @ 7:16:59 AM CEST
+296ms ║║Switch turned off at: Mon, Mar 29 2021 @ 7:16:59 AM CEST
+297ms ║║Executed virtual command [Outdoor lights simulated switch].log (1ms)
+301ms ║╚Execution stage complete. (252ms)
+303ms ║Setting up scheduled job for Mon, Mar 29 2021 @ 7:54:00 PM CEST (in 45420s), with 2 more jobs pending
+310ms ╚Event processed successfully (311ms)
3/29/2021, 12:00:59 AM +47ms
+1ms ╔Received event [My home].time = 1616968860000 with a delay of -953ms
+65ms ║RunTime Analysis CS > 46ms > PS > 4ms > PE > 14ms > CE
+67ms ║Runtime (39520 bytes) successfully initialized in 4ms (v0.3.113.20210203) (66ms)
+68ms ║╔Execution stage started
+78ms ║║Cancelling statement #9’s schedules…
+83ms ║║Updating sunrise and sunset variables
+84ms ║║Executed virtual command log (2ms)
+136ms ║║Calculating (string) sunrise: + (string) Mon, Mar 29 2021 @ 7:14:00 AM CEST >> (string) sunrise: Mon, Mar 29 2021 @ 7:14:00 AM CEST
+139ms ║║sunrise: Mon, Mar 29 2021 @ 7:14:00 AM CEST
+140ms ║║Executed virtual command log (1ms)
+146ms ║║Calculating (string) sunset: + (string) Mon, Mar 29 2021 @ 8:12:00 PM CEST >> (string) sunset: Mon, Mar 29 2021 @ 8:12:00 PM CEST
+149ms ║║sunset: Mon, Mar 29 2021 @ 8:12:00 PM CEST
+150ms ║║Executed virtual command log (1ms)
+153ms ║╚Execution stage complete. (85ms)
+155ms ║Setting up scheduled job for Mon, Mar 29 2021 @ 7:17:00 AM CEST (in 26160s), with 2 more jobs pending
+162ms ╚Event processed successfully (162ms)
3/28/2021, 6:51:59 PM +60ms
+0ms ╔Received event [My home].time = 1616950320000 with a delay of -940ms
+40ms ║RunTime Analysis CS > 19ms > PS > 5ms > PE > 16ms > CE
+42ms ║Runtime (39520 bytes) successfully initialized in 5ms (v0.3.113.20210203) (41ms)
+43ms ║╔Execution stage started
+70ms ║║Cancelling statement #2’s schedules…
+108ms ║║Executed physical command [Outdoor lights simulated switch].on() (35ms)
+109ms ║║Executed [Outdoor lights simulated switch].on (37ms)
+115ms ║║Calculating (string) Switch turned on at: + (string) Sun, Mar 28 2021 @ 6:51:59 PM CEST >> (string) Switch turned on at: Sun, Mar 28 2021 @ 6:51:59 PM CEST
+118ms ║║Switch turned on at: Sun, Mar 28 2021 @ 6:51:59 PM CEST
+119ms ║║Executed virtual command [Outdoor lights simulated switch].log (1ms)
+122ms ║╚Execution stage complete. (79ms)
+123ms ║Setting up scheduled job for Mon, Mar 29 2021 @ 12:01:00 AM CEST (in 18540s), with 2 more jobs pending
+129ms ╚Event processed successfully (129ms)
3/28/2021, 6:19:59 AM +66ms
+0ms ╔Received event [My home].time = 1616905200000 with a delay of -934ms
+37ms ║RunTime Analysis CS > 19ms > PS > 5ms > PE > 13ms > CE
+40ms ║Runtime (39520 bytes) successfully initialized in 5ms (v0.3.113.20210203) (38ms)
+40ms ║╔Execution stage started
+71ms ║║Cancelling statement #7’s schedules…
+108ms ║║Executed physical command [Outdoor lights simulated switch].off() (33ms)
+109ms ║║Executed [Outdoor lights simulated switch].off (34ms)
+114ms ║║Calculating (string) Switch turned off at: + (string) Sun, Mar 28 2021 @ 6:19:59 AM CEST >> (string) Switch turned off at: Sun, Mar 28 2021 @ 6:19:59 AM CEST
+118ms ║║Switch turned off at: Sun, Mar 28 2021 @ 6:19:59 AM CEST
+118ms ║║Executed virtual command [Outdoor lights simulated switch].log (1ms)
+121ms ║╚Execution stage complete. (81ms)
+123ms ║Setting up scheduled job for Sun, Mar 28 2021 @ 6:52:00 PM CEST (in 45120s), with 2 more jobs pending
+129ms ╚Event processed successfully (129ms)
3/28/2021, 12:01:08 AM +847ms
+1ms ╔Received event [My home].time = 1616886060000 with a delay of 8847ms
+245ms ║RunTime Analysis CS > 225ms > PS > 6ms > PE > 14ms > CE
+248ms ║Runtime (39522 bytes) successfully initialized in 6ms (v0.3.113.20210203) (247ms)
+249ms ║╔Execution stage started
+262ms ║║Cancelling statement #9’s schedules…
+267ms ║║Updating sunrise and sunset variables
+269ms ║║Executed virtual command log (1ms)
+706ms ║║Calculating (string) sunrise: + (string) Sun, Mar 28 2021 @ 6:17:00 AM CEST >> (string) sunrise: Sun, Mar 28 2021 @ 6:17:00 AM CEST
+710ms ║║sunrise: Sun, Mar 28 2021 @ 6:17:00 AM CEST
+711ms ║║Executed virtual command log (1ms)
+719ms ║║Calculating (string) sunset: + (string) Sun, Mar 28 2021 @ 7:09:00 PM CEST >> (string) sunset: Sun, Mar 28 2021 @ 7:09:00 PM CEST
+724ms ║║sunset: Sun, Mar 28 2021 @ 7:09:00 PM CEST
+725ms ║║Executed virtual command log (2ms)
+729ms ║╚Execution stage complete. (479ms)
+731ms ║Setting up scheduled job for Sun, Mar 28 2021 @ 6:20:00 AM CEST (in 19130s), with 2 more jobs pending
+738ms ╚Event processed successfully (737ms)
3/27/2021, 6:49:59 PM +59ms
+0ms ╔Received event [My home].time = 1616867400000 with a delay of -941ms
+43ms ║RunTime Analysis CS > 21ms > PS > 5ms > PE > 16ms > CE
+45ms ║Runtime (39520 bytes) successfully initialized in 5ms (v0.3.113.20210203) (44ms)
+46ms ║╔Execution stage started
+79ms ║║Cancelling statement #2’s schedules…
+416ms ║║Executed physical command [Outdoor lights simulated switch].on() (334ms)
+417ms ║║Executed [Outdoor lights simulated switch].on (336ms)
+424ms ║║Calculating (string) Switch turned on at: + (string) Sat, Mar 27 2021 @ 6:49:59 PM CET >> (string) Switch turned on at: Sat, Mar 27 2021 @ 6:49:59 PM CET
+428ms ║║Switch turned on at: Sat, Mar 27 2021 @ 6:49:59 PM CET
+429ms ║║Executed virtual command [Outdoor lights simulated switch].log (1ms)
+433ms ║╚Execution stage complete. (387ms)
+435ms ║Setting up scheduled job for Sun, Mar 28 2021 @ 12:01:00 AM CET (in 18660s), with 2 more jobs pending
+443ms ╚Event processed successfully (443ms)
3/27/2021, 6:22:59 AM +60ms
+126ms ║Switch turned off at: Sat, Mar 27 2021 @ 6:22:59 AM CET
3/27/2021, 12:01:01 AM +672ms
+281ms ║Updating sunrise and sunset variables
+476ms ║sunrise: Sat, Mar 27 2021 @ 6:20:00 AM CET
+487ms ║sunset: Sat, Mar 27 2021 @ 7:07:00 PM CET
3/26/2021, 6:46:59 PM +59ms
+359ms ║Switch turned on at: Fri, Mar 26 2021 @ 6:46:59 PM CET
3/26/2021, 6:25:59 AM +66ms
+114ms ║Switch turned off at: Fri, Mar 26 2021 @ 6:25:59 AM CET
3/26/2021, 12:01:03 AM +3ms
+250ms ║Updating sunrise and sunset variables
+504ms ║sunrise: Fri, Mar 26 2021 @ 6:23:00 AM CET
+512ms ║sunset: Fri, Mar 26 2021 @ 7:05:00 PM CET


#2

See

and


#3

Assuming $sunrise/$sunset are tied to $twcweather, realize they do not update until around 3 am. Best to update closer to 4 am to ensure you have the latest data.

https://wiki.webcore.co/TWC_Weather


#4

Seems like a good idea to me.

SmartThings updates sunrise and sunset times a little after the current day’s events and pistons will update their own copies of the values from SmartThings when they execute if it has been eight hours or more since they were last updated.

There is probably an argument for having your dummy piston execution use a sunrise offset itself to allow it to run as near to your first real execution of the day as you feel comfortable with.


#5

Thanks for all the responses, though I am still confused.

I modified the piston to run at -90min from sunrise (instead of 1 min after midnight) in order to get the variables updated for the current day. It is still scheduling 3 minutes late…

Looking back at the previous logs (as posted here) I see that the sunrise variable and the setting up of the scheduled job do not match - is that not expected?
I thought maybe the presets of sunrise and sunset did not match the $sunrise and $sunset variables, but testing with another piston I have never seen them differ…


Here we see that sunrise is 6:17 AM, but the scheduled job is set up for 6:20 AM - why?


#6

Every blocks only run the block when they fire

This can be confusing when there are multiple in a single piston…ie what triggered. A test (entire piston) or an every block ( only the block)

I suggest change all the every to if statements

See my above post and links


#7

Thanks again! I did read the links but didn’t understand how relevant they were to my problem until the 2nd time around.

Basically, an Every block will never update the schedule of another Every block. The logging had me confused since it looks like the scheduled jobs are set up with each execution - but I guess they are not (or if they are, the schedule is exactly what it was previously)

I have set up a new piston for testing purposes, still keeping 2 Every blocks, but adding an If to force the “rescheduling” of those.


#8

Changing only 1 of the Every blocks to an If statement did not work; now testing with all If statements.


#9

This is what I ended up with after converting to use only If statements.