Mode (Time of Day) - Configuration clarification

Tags: #<Tag:0x00007f61800b60b0> #<Tag:0x00007f61800b5ef8>

@5iver

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

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?

TIA

Nick

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"})
])