Advanced Circadian Lighting

I found why it does not work, it have issues with Toggle Light. To bad for me.

Hi @dimkaram!

I really like this blueprint! Very impressive work!
Although it is a little bit hard to debug when things doesn’t work as expected :slight_smile:

It would be really nice with a supplied graph showing the differences of the different functions!

Anyway, I think I found a bug, and potentially a solution.
In the event of elevation_sun{rise,set}_{start,end} end up exactly matching the value from the triggered sun.sun elevation event, the variable elevation_turn_on ends up with false, and thus makes the automation failing in turning the lights on.

Bellow follows a trace from one of my failed runs.
In the bellow case the trigger.from_state.attributes.elevation has the value of 6 which isn’t less than elevation_sunset_start (6), causing elevation_turn_on: false, and the lights won’t turn on.
See the relevant row in the blueprint.

Trace
this:
  entity_id: automation.mood_lighting_circadian_lighting
  state: 'on'
  attributes:
    last_triggered: '2023-04-08T17:12:00.417396+00:00'
    mode: queued
    current: 0
    max: 10
    id: 6E1D3D85-C166-40B6-8280-4489AF465DAA
    friendly_name: Mood lighting Circadian Lighting
  last_changed: '2023-04-08T10:01:03.019960+00:00'
  last_updated: '2023-04-08T17:12:00.485448+00:00'
  context:
    id: 01GXGXMY4R7H8B4VY1H7S2ZT8Y
    parent_id: 01GXGXMY44D56RFSBZWRR6Z2NE
    user_id: null
trigger:
  id: '3'
  idx: '3'
  alias: null
  platform: numeric_state
  entity_id: sun.sun
  below: 6
  above: null
  from_state:
    entity_id: sun.sun
    state: above_horizon
    attributes:
      next_dawn: '2023-04-09T03:38:20.316746+00:00'
      next_dusk: '2023-04-08T18:38:26.137907+00:00'
      next_midnight: '2023-04-08T23:08:43+00:00'
      next_noon: '2023-04-09T11:08:50+00:00'
      next_rising: '2023-04-09T04:17:38.682793+00:00'
      next_setting: '2023-04-08T17:59:02.614619+00:00'
      elevation: 6
      azimuth: 274.36
      rising: false
      friendly_name: Sun
    last_changed: '2023-04-08T10:00:51.449404+00:00'
    last_updated: '2023-04-08T17:10:05.031184+00:00'
    context:
      id: 01GXGXHDF7YTD8RASYEBM9N975
      parent_id: null
      user_id: null
  to_state:
    entity_id: sun.sun
    state: above_horizon
    attributes:
      next_dawn: '2023-04-09T03:38:20.316746+00:00'
      next_dusk: '2023-04-08T18:38:26.137907+00:00'
      next_midnight: '2023-04-08T23:08:43+00:00'
      next_noon: '2023-04-09T11:08:50+00:00'
      next_rising: '2023-04-09T04:17:38.682793+00:00'
      next_setting: '2023-04-08T17:59:02.614619+00:00'
      elevation: 5.72
      azimuth: 274.77
      rising: false
      friendly_name: Sun
    last_changed: '2023-04-08T10:00:51.449404+00:00'
    last_updated: '2023-04-08T17:12:05.031589+00:00'
    context:
      id: 01GXGXN2N7MVFBYY286GBNYJN3
      parent_id: null
      user_id: null
  for: null
  description: numeric state of sun.sun
sleep_mode: Turn off
sleep_entity: input_boolean.sleep
sleep_on: false
sleep_off: false
sleep_trigger: false
sleep_condition: true
circadian_type: Time
circadian_sunrise: '07:30:00'
circadian_sunset: '21:30:00'
circadian_function: Day & night (cosine)
circadian_position: 0.8358142798807886
circadian_coefficient: 0.7466174862109347
circadian_angle: 0.6679071399403943
circadian_brightness_midday: 100
circadian_brightness_midnight: 90
circadian_brightness_value: 248
circadian_temperature_midday: 4000
circadian_temperature_midnight: 2202
circadian_temperature_value: 302
circadian_hue_default_input: 180
circadian_hue_default: 180
circadian_hue_value: 240
circadian_saturation_default_input: 100
circadian_saturation_default: 100
elevation_switch_on_input: true
elevation_switch_on: true
elevation_switch_off_input: true
elevation_switch_off: true
elevation_inverse: false
elevation_sunrise_start_input: -8
elevation_sunrise_start: -8
elevation_sunrise_end_input: 6
elevation_sunrise_end: 6
elevation_sunset_start_input: 6
elevation_sunset_start: 6
elevation_sunset_end_input: -8
elevation_sunset_end: -8
elevation_condition: true
elevation_dim_on: true
elevation_dim_off: false
elevation_turn_on: false
elevation_turn_off: false
elevation_brightness: 5
presence_entity: binary_sensor.home
presence_switch_on_input: true
presence_switch_on: true
presence_switch_off_input: true
presence_switch_off: true
presence_inverse: false
presence_on: false
presence_off: false
presence_condition: true
turnon_trigger: false
lights_target_input:
  entity_id:
    - light.koksfonster_light
    - light.skank_lampa_light
    - light.vardagsrums_fonster_light
lights_target:
  - light.koksfonster_light
  - light.skank_lampa_light
  - light.vardagsrums_fonster_light
lights_dim_all: []
lights_on_all: []
lights_off_all:
  - light.koksfonster_light
  - light.skank_lampa_light
  - light.vardagsrums_fonster_light
lights_trigger_all: []
lights_dim_brightness: []
lights_dim_color: []
lights_dim_temperature: []
lights_on_brightness: []
lights_on_color: []
lights_on_temperature: []
lights_off_onoff: []
lights_off_brightness: []
lights_off_color: []
lights_off_temperature:
  - light.koksfonster_light
  - light.skank_lampa_light
  - light.vardagsrums_fonster_light
lights_trigger_brightness: []
lights_trigger_color: []
lights_trigger_temperature: []

The fix for this is quite simple, which allows these comparisons to include greater/less than or equal to. I also included this in a couple of more places. I’m not sure these are correct, however.
The changes can be seen in my fork of the blueprint. Please consider including these in the original gist.

Thank you for a great Blueprint! :star_struck:

Hi Thomas,

Thank you very much for your comments and work on this!

I knew something was going on, as I also found that my lights would sometimes (?) not turn off in the morning! Your suggestion seems reasonable, and I added it to my gist too. I will be trying it out in the next few days and monitoring the results. Many thanks for taking the time to debug what is indeed a rather complicated code.

Everyone else, please accept my apologies for not being able to provide support with this, I am afraid I just don’t have the time to help. Besides, as you might have noticed in the above, there was a bug with the code, which I could not identify. Hopefully, with Thomas’ suggestion, things might work better.

The same applies to providing graphs for the expected behaviour. If I get some time, I will prepare something, but I am afraid that I have too many other commitments at the moment. Sorry!

Best,

Dimitris