stefanvictora / hue-scheduler

☀ Adjust your Philips Hue and Home Assistant lights to your natural rhythm. With advanced schedules and transitions based on solar times.
Apache License 2.0
16 stars 0 forks source link

Schedule configuration validation #9

Open cswrd opened 8 months ago

cswrd commented 8 months ago

Hi, I just realized some schedules I configured in the summer, don't make sense in the winter, anymore. Example:

...
noon+180
golden_hour-180
...

Mathematically, the 2nd line should be scheduled before the 1st line. Hue scheduler still "works". Maybe it does this, already. If you think about more complex schedules and situations (tr, tr-before, turning on the lights during overlapping phases or having them powerd on all the time) I don't even know what users are supposed to expect here. Is there is any good interpretation people would understand and intent to configure like that?

I can't think of any good interpretation here. That's why the idea of validating the schedule configuration came into my mind. I'd be happy if hue scheduler would refuse to execute such a "weird" configuration (already in the summer in my case). "Weird" might be defined as:

  1. The configured schedule order doesn't match the execution order.
  2. There're overlapping phases.
  3. ... both detected in advance for an entire year when hue scheduler is started for the given long, lat, elevation.
stefanvictora commented 1 month ago

Hi, thank you for opening the issue and sorry for not getting back to you sooner. Working with changing solar times between winter and summer is indeed a challenge and a source of frustration, even in my own setup.

You are right: Hue Scheduler will automatically switch the order of states depending on the time of year. It dynamically calculates the next start (and end) time of such expressions after each execution, continuously shifting the states as needed. However, I agree that this can cause quite a lot of confusion and unintended schedules throughout the year, especially if you manually adjust solar times or combine them with local times.

I do like the idea of performing such validation on startup. However, I'm a bit concerned that it might limit the flexibility of the configuration file. Currently, Hue Scheduler does not use the defined order for anything, as the states are dynamically sorted after each execution once they are read from the file. Nevertheless, I see how they could be useful for sanity checks to avoid potential misconfigurations.


Another idea I had for tackling the different seasons was to allow the definition of date ranges in which the defined states should be scheduled. Since a validation alone would not solve the issue of wanting different schedules in winter versus summer. It could look something like this, which is a more advanced version of restricting states to certain days of week:

# Common states:
Light  sunrise
Light  12:00

# Date range specific states:
date-range: 01.01.-01.04.
  Light    sunset
  Light    civil_dusk

...

date-range: 01.06.-31.10.
  Light    21:00
  Light    22:00

Another variant I had in mind involves time brackets, which define the minimum and/or maximum value for a dynamic solar time:

# Sunrise, but not earlier than 06:00
Light  [06:00,sunrise]

# Sunrise, but not earlier or later than 06:00 and 08:00
Light  [06:00,sunrise,08:00]

# Sunset, but not later as 21:00
Light  [sunset,21:00]

Such brackets could also be created implicitly, based on the defined order:

# Implicit
Light    06:00
Light    sunrise
Light    08:00

Even though this could mean that some states would be skipped, for example, if sunrise occurs before 06:00 or after 08:00.

I'm not sure yet, what the best approach would be or if any of the advanced configuration are usable 🤔 I appreciate any feedback and thoughts on this topic. The dynamic nature of solar times is also one of the primary reasons why I would like to create a GUI to easily adjust my schedules and see their current execution times.