Mode (Time of Day) - Configuration clarification


The Mode (Time of Day) code allows for 2 time periods to be defined in the

The docs says that “If both are used, the first one that occurs will trigger the Mode.”.

Does this mean that the second will end that Mode time - so a start and end time for each mode? If so, can you use Astro channels for both times?



The time and Channel used for the Night mode are not start and end times. If you were to use something like this…

mode_dict = OrderedDict([
    ("Morning", {"channel": "astro:sun:local:civilDawn#event", "event": "START"}),
    ("Night"  , {"hour": 21, "minute": 0,  "second": 0, "channel": "astro:sun:local:civilDusk#event", "event": "START"})

… the Night mode will start at 9pm or when CivilDusk starts, whichever comes first. Night Mode will end when the Morning Mode starts. The times and Channels only affect the start times of the Mode. Currently, you can only specify one time and/or one Channel per Mode.

Thanks Scott.

Update: Now I’ve re-read the documentation, it makes sense. :roll_eyes:

1 Like

A (much belated) follow up. The docs say that the “Modes must be ordered first to last, with no overlap in times.”

I’m assuming that none of the configured times can overlap, not just the earliest times and that if dynamic channel times overlap with set times flapping between modes will occur.

("Evening", {"hour": 20, "minute": 0, "second": 0, "channel": "astro:sun:local:daylight#event", "event": "END", }),
("Night_Evening", {"hour": 21, "minute": 0, "second": 0, "channel": "astro:sun:local:civilDusk#event", "event": "END"})

If you have Modes that overlap, things can be unpredictable. For example…

mode_dict = OrderedDict([
    ("Morning", {"channel": "astro:sun:local:civilDawn#event", "event": "START"}),
    ("Day"  , {"hour": 7, "minute": 0,  "second": 0})

In this example, there are times of the year when Day will occur before Morning. This could be avoided by using both a time and Channel, like in what you have setup, since the times prevent an overlap. Your Modes look fine to me.

Hi Scott,

Well I actually get both modes twice. My config:

("Evening", {"hour": 20, "minute": 0, "second": 0, "channel": "astro:sun:local:daylight#event", "event": "END", }), 
("Night_Evening", {"hour": 21, "minute": 0, "second": 0, "channel": "astro:sun:local:civilDusk#event", "event": "END"}) 

So for 29 June 2020:

  • Evening is 20:00:00 OR Daylight end (21:18 hrs)
  • Night_Evening is 21:00:00 OR Civil Dusk end (22:10 hrs)

Evening is triggered at 20:00 hrs (as expected)
Night_Evening is triggered at 21:00 hrs (as expected)
Evening is re-triggered at 21:18
Night_Evening is re-triggered at 22:10

I’m still migrating from a simple IsDay/IsNight setup, so I’ll probably tweak stuff.

Does it matter that not all my config items use both fixed time and dynamic channels? For example ‘Afternoon’ starts at 12:00:00, so I’ve not put in a channel equivalent.

mode_dict = OrderedDict([
    ("Night_Morning", {"hour": 0, "minute": 2, "second": 0}),
    ("Morning", {"hour": 6, "minute": 0, "second": 0, "channel": "astro:sun:local:daylight#event", "event": "START"}),
    ("Afternoon", {"hour": 12, "minute": 0, "second": 0}),
    ("Evening", {"hour": 20, "minute": 0, "second": 0, "channel": "astro:sun:local:daylight#event", "event": "END", }),
    ("Night_Evening", {"hour": 21, "minute": 0, "second": 0, "channel": "astro:sun:local:civilDusk#event", "event": "END"})

Hi there,

I’m comparing a couple of options for time of day at the moment - this and the Ephemeris ToD implementation.

A couple of questions/observations:

  1. Is there a way to specify a different time/event depending on the day - i.e. Friday & Saturday NIGHT to be a later time?
  2. I’ve noticed that the Event configuration doesn’t seem to recognise Earliest or Latest, I’ve got a trigger set to Sunrise END, with the Latest set to 08:00, but the transition still takes place at the end of the sunrise event:
mode_dict = OrderedDict([
    ("Dawn",    {"channel": "astro:sun:local:civilDawn#event", "event": "START"}),
    ("Morning", {"hour": 6,  "minute": 30,  "second": 0}),
    ("Day"    , {"channel": "astro:sun:local:rise#event", "event": "END"}),
    ("Dusk",    {"channel": "astro:sun:local:civilDusk#event", "event": "START"}),
    ("Evening", {"channel": "astro:sun:local:set#event", "event": "START"}),
    ("Night"  , {"hour": 22, "minute": 10,  "second": 0}),
    ("Late"   , {"hour": 23, "minute": 0,  "second": 0})
"uid": "astro:sun:local:rise#end",
      "id": "rise#end",
      "channelTypeUID": "astro:end",
      "itemType": "DateTime",
      "kind": "STATE",
      "label": "End Time",
      "description": "The end time of the event",
      "defaultTags": [],
      "properties": {},
      "configuration": {
        "offset": 0,
        "earliest": "08:00"

And the output I get is:

2020-09-04 06:17:00.055 [DEBUG] [jsr223.jython.Update Mode           ] - Mode changed from [Dawn] to [Day]

2020-09-04 06:17:00.115 [INFO ] [jsr223.jython.ToD Mode Change       ] - Mode Changed:[Day]

2020-09-04 06:30:00.312 [DEBUG] [jsr223.jython.Update Mode           ] - Mode changed from [Day] to [Morning]

2020-09-04 06:30:00.453 [INFO ] [jsr223.jython.ToD Mode Change       ] - Mode Changed:[Morning]

And the mode won’t change to Day at 08:00 as intended.


Not in the released version. I have a lot of cool updates to push.

That would be the Astro binding, not the ToD script. Take a look at the trigger Channels. I think you are looking for rise#event.