Periodic-lights icon indicating copy to clipboard operation
Periodic-lights copied to clipboard

I... I am too dumb.

Open christianreiss opened this issue 2 years ago • 5 comments

So I have been playing with this for two days now. It looks like it can do what I want, which basically is to have

  • Start increasing brightness and color in the morning from 1 hour (or so) before sunrise and be done 2 hours or so after sunrise.
  • Start decreasing brightness and color in the evening from 2 hours or so before sunrise an be in full effect 2 hours after (or so).

I have been reading the documentation but honestly, that is beyond me. And I am running a 400-or-so automations HA setup with 28 integrations. But this beats me.

I have been whacking at the settings in an orderly fashion at first, randomly bashing later.

main_periodic_lights:
  module: update_lights
  class: update_lights
  run_every: 180
  event_subscription: main_update_lights
  entities:
    - light.mi_esstischlampe
    - light.mi_licht_badezimmer
    - light.mi_licht_theodor
    - light.mi_licht_wohnzimmer_tv
    - light.licht_kuche
    - light.licht_johann
    - light.licht_schlafzimmer_4
    - light.licht_buro_3
  brightness_threshold: 25
  color_temp_max: 4100
  color_temp_min: 3000
# color_temp_unit: 'kelvin'
  max_brightness_level: 100
  min_brightness_level: 35
  brightness_unit: 'percent'
  sleep_entity:
    - input_boolean.just_woke_up,off
  disable_entity:
    - input_boolean.watching_tv,on
# red_hour: '21:00:00'
  start_time: sunset - 04:00:00
  end_time: sunrise + 01:00:00
  start_index: sunrise - 02:00:00
  end_index: sunset
  transition: 5
  keep_lights_on: False
  stop_lights_off: True
  watch_light_state: True
  sensor_log: sensor.main_lights

I have been playing with start_time, end_time, start_index etc. Even after reading the documentation 10 or so time I still don't know what they do. Sorry :)

Could someone pleas help me and roughly tell me what goes where? And a "lamens section" in the documentation would not go amiss.

Cheers! -Chris.

christianreiss avatar Nov 08 '22 16:11 christianreiss

Hi thanks for checking this out.

Nothing in your config looks wrong I don't think.

Basic explanation of the start and end time is this, you have to define a point in the day where the lights are the most dim in some way (aka minimum brightness). The approach here is to give two time parameters, the start and end times and just figure out what the middle of those times are. So if your start time is 6pm, and your end time is 6am, then midnight is the time when it will hit minimum brightness. Conversely noon will be the brightest time. That's all there is to it.

The index stuff is a little more complicated, but not much. If those are set you now have 2 middle points. One between the start_index and end_time, and another between start_time and end_index. The time between the 2 middle points is held to the minimum brightness the whole time.This lets you set a range during the night where the lights are always at the minimum.

One thing to note: this acts continuously over the whole day; it will not do what you suggest where it only acts 1 or two hours at a time. This fits the light brightness to a Sin function, so the slope, and hence the pace, that the lights change does vary over the course of the day; but you can't exactly say start at the minimum brightness at 5am and have it be max at 7am.

I also have a simplified blueprint. There are not nearly as many options, but it does the same basic job.

haberda avatar Nov 09 '22 22:11 haberda

Thank you for your reply.

In the meantime I think I got it the way I want it to work. I am aware that its a constant smooth transition, not some switchpoints. But I wanted it to start say 1 hour before sundown and on spot for sunrise. So the outside "ambient" color and brightness is matched by my internal lights.

So far it seems to do just that.

Can I have multiple main_periodic_lights: routines? Kids need other routines that the office etc. I copy-pasted the routine and moved the entities round. That should do the trick? Or So i need ti add a name variable or so to keep multiple instances?

AppDaemon is a mystery for me :)

christianreiss avatar Nov 13 '22 10:11 christianreiss

Yes, AppDaemon lets you have as many instances of the app as you want. You just have to give it a different name: for example main_periodic_lights: could be kids_periodic_lights: or whatever. Just don't have the same lights in different instances, unless you have booleans or whatever turning one off and another on. Otherwise they will fight each other.

haberda avatar Nov 15 '22 00:11 haberda

Thank you!

Everything seems to be working now. I noticed it wont touch a light if the brightness if off by 35% points (as seen in yaml). Does that aslo apply if the kelvin is too far off?

christianreiss avatar Nov 16 '22 11:11 christianreiss

No I never got around to doing color temperature thresholds. There are complications because it also supports RGB colors so it would require some reworking to get that right and I haven't had time. But if you change the brightness enough it ignores the light completely, so if you change the brightness enough it will just stay that color and brightness.

haberda avatar Nov 17 '22 17:11 haberda