Read sunset in scripts

Dan 4 years ago updated by Vladimir Ovchinnikov (expert) 4 years ago 3


I'm adding timed events based on the local daylight times to a project, with the ability to use an offset for these events.

Reading through some similar topics, I have found that you do not natively support this, so I have added this functionality through scripts in the following way:

To get the sunset time in the scripts:

  • Created a schedule, 'Sunset' that begins at sunset and ends at sunrise, repeating every day.
  • Created a routine, 'Sunset'... WHEN 'Sunset' starts, THEN send_tag (System.Date.Day -> Sunset_Alert)
  • This channel has a script modifier that sets a tag with the current time when called

The same was done to get sunrise time.

I have left this running over the weekend to populate the server tags with the current sunset and sunrise times before I implement the timed events functionality.

The sunrise tag has correct values, while the sunset tag is still blank.

Looking at the server logs, I've noticed the following

  • I see the following each time it is sunrise, which correctly sets the sunrise time
    • [08-03-2020 06:07:00.002] INFO State of event 'Sunrise' has been changed to start
      [08-03-2020 06:07:00.002] INFO SCRIPT Sunrise set to 6:07
      [08-03-2020 06:07:00.002] INFO Routine 'Sunrise' has been activated
      [08-03-2020 06:07:00.002] INFO State of event 'Sunset' has been changed to finish
  • I do not see any other mention of 'Sunset' in the logs.

I have tested changing the channel 'Sunset_Alert' from the web interface - the script modifier is correctly called.

Below is the schedule and event for Sunset that I have, can you see any reason why this may not be working?

Image 38723

Image 38725

Kind Regards,



If you specify the beginning of sunset and the end of sunrise, then you need to specify the day for both. If you specified a day only for sunset, the server considers that both sunset and sunrise are in the same day. However, in one day, the sunset can not be before sunrise. Specify a day for each of them.

That makes sense - Thank you