basnijholt / adaptive-lighting

Adaptive Lighting custom component for Home Assistant
https://basnijholt.github.io/adaptive-lighting/
Apache License 2.0
1.71k stars 127 forks source link

Does not work with Light Template #847

Open lennon101 opened 7 months ago

lennon101 commented 7 months ago

TLDR:

Please confirm that you have completed the following steps:

Required information for bug reports:

  1. Debug logs captured while the issue occurred. See here for instructions on enabling debug logging:
2023-11-20 09:22:58.030 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Intercepted TURN_ON call with data {'params': {}, 'entity_id': ['light.kitchen_island_led_lights']} (01HFMY9X3DZQVF16NS2CMJJY3B)
2023-11-20 09:22:58.031 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] RGBW Lights: Setting color_temp of light light.kitchen_island_led_lights
2023-11-20 09:22:58.031 DEBUG (MainThread) [custom_components.adaptive_lighting.adaptation_utils] Preparing adaptation data for light.kitchen_island_led_lights with service data {'entity_id': 'light.kitchen_island_led_lights', 'brightness': 255, 'color_temp_kelvin': 4950}
2023-11-20 09:22:58.031 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Detected an 'light.turn_on('['light.kitchen_island_led_lights']')' event with context.id='01HFMY9X3DZQVF16NS2CMJJY3B'
2023-11-20 09:22:58.031 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] RGBW Lights: execute_cancellable_adaptation_calls with data: AdaptationData(entity_id=light.kitchen_island_led_lights, context_id=01HFMY9X3F:al:KJDU:dpt_:01, sleep_time=0.0, force=False, max_length=1, which=both, initial_sleep=True)
2023-11-20 09:22:58.040 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] (0) _service_interceptor_turn_on_handler: call.context.id='01HFMY9X3DZQVF16NS2CMJJY3B', is_skipped_hash='False'
2023-11-20 09:22:58.040 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] (1) _service_interceptor_turn_on_handler: call='<ServiceCall light.turn_on (c:01HFMY9X3DZQVF16NS2CMJJY3B): entity_id=['light.kitchen_island_led_lights'], params=>', service_data='{'entity_id': ['light.kitchen_island_led_lights'], 'params': {}}'
2023-11-20 09:22:58.041 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] (2) _service_interceptor_turn_on_handler: switch_to_eids='{'Adaptive Lighting: RGBW Lights': ['light.kitchen_island_led_lights']}', skipped='[]'
2023-11-20 09:22:58.041 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] (3) _service_interceptor_turn_on_handler: intercepting entity_ids='['light.kitchen_island_led_lights']'
2023-11-20 09:22:58.041 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Intercepted TURN_ON call with data {'params': {}, 'entity_id': ['light.kitchen_island_led_lights']} (01HFMY9X3DZQVF16NS2CMJJY3B)
2023-11-20 09:22:58.042 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] RGBW Lights: Setting color_temp of light light.kitchen_island_led_lights
2023-11-20 09:22:58.042 DEBUG (MainThread) [custom_components.adaptive_lighting.adaptation_utils] Preparing adaptation data for light.kitchen_island_led_lights with service data {'entity_id': 'light.kitchen_island_led_lights', 'brightness': 255, 'color_temp_kelvin': 4950}
2023-11-20 09:22:58.042 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Detected an 'light.turn_on('['light.kitchen_island_led_lights']')' event with context.id='01HFMY9X3DZQVF16NS2CMJJY3B'
2023-11-20 09:22:58.042 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] RGBW Lights: execute_cancellable_adaptation_calls with data: AdaptationData(entity_id=light.kitchen_island_led_lights, context_id=01HFMY9X3T:al:KJDU:dpt_:02, sleep_time=0.0, force=False, max_length=1, which=both, initial_sleep=True)
2023-11-20 09:22:58.042 WARNING (MainThread) [homeassistant.helpers.script.kitchen_island_led_lights] Kitchen Island LED Lights: Already running
  1. Your Adaptive Lighting configuration: I have set up the light using the UI, but a duplicate of the settings is below

    adaptive_lighting:
    lights:
    - light.living_room_lights
      transition: 45
      initial_transition: 5
      interval: 90
      min_brightness: 80
      max_brightness: 100
      min_color_temp: 2000
      max_color_temp: 5500
      sleep_brightness: 50
      sleep_color_temp: 2000
      take_over_control: true
      detect_non_ha_changes: false
      only_once: false
  2. My light template config is below

    - platform: template
    lights:
    kitchen_island_led_lights:
      unique_id: kitchen_island_led_lights
      friendly_name:        "Kitchen Island LED Lights"
      value_template:       >-
                            {{ ( state_attr('light.kitchen_island_led_lights_warm_white', 'brightness') | int(0) +
                                 state_attr('light.kitchen_island_led_lights_cool_white', 'brightness') | int(0) ) > 0 }}
      level_template:       "{{  states('input_number.kitchen_island_led_lights_brightness')  | int(0)   }}"
      temperature_template: "{{  states('input_number.kitchen_island_led_lights_temperature') | int(500) }}"
      set_level:
        - service:     input_number.set_value
          target:
            entity_id: input_number.kitchen_island_led_lights_brightness
          data:
            value:     "{{ brightness | int(0) }}"
        - if:
            - condition: numeric_state
              entity_id: input_number.kitchen_island_led_lights_brightness
              above:     128
          then:
            - variables:
                perc_above_mid: "{{ ((states('input_number.kitchen_island_led_lights_brightness') | int(0) - 128) / 127) | float(0) }}"
            - if:
                - condition:    numeric_state
                  entity_id:    input_number.kitchen_island_led_lights_temperature
                  above:        327
              then:
                - variables:
                    warmest:          "{{ (500 - (perc_above_mid * 173)) | int(500) }}"
                - if:
                    - condition:      numeric_state
                      entity_id:      input_number.kitchen_island_led_lights_temperature
                      above:          0
                      value_template: "{{ (float(state.state) - warmest) | int(0) }}"
                  then:
                    - service:        input_number.set_value
                      target:
                        entity_id:    input_number.kitchen_island_led_lights_temperature
                      data:
                        value:        "{{ warmest | int(500) }}"
            - if:
                - condition:    numeric_state
                  entity_id:    input_number.kitchen_island_led_lights_temperature
                  below:        327
              then:
                - variables:
                    coldest:          "{{ (153 + (perc_above_mid * 174)) | int(153) }}"
                - if:
                    - condition:      numeric_state
                      entity_id:      input_number.kitchen_island_led_lights_temperature
                      below:          0
                      value_template: "{{ (float(state.state) - coldest) | int(0) }}"
                  then:
                    - service:        input_number.set_value
                      target:
                        entity_id:    input_number.kitchen_island_led_lights_temperature
                      data:
                        value:        "{{ coldest | int(153) }}"
        - service:     light.turn_on
          target:
            entity_id: light.kitchen_island_led_lights
      set_temperature:
        - service:     input_number.set_value
          target:
            entity_id: input_number.kitchen_island_led_lights_temperature
          data:
            value:     "{{ color_temp | int(500) }}"
        - if:
            - condition: numeric_state
              entity_id: input_number.kitchen_island_led_lights_brightness
              above:     128
          then:
            - variables:
                delta_perc_mean_temp: "{{ (((( (states('input_number.kitchen_island_led_lights_temperature') | int(500) - 152) / 348) - 0.5) | abs ) * 2) | float(0) }}"
                max_brightness:       "{{ ( (1 - delta_perc_mean_temp) * 127 + 128 ) | int(0) }}"
            - if:
                - condition:          numeric_state
                  entity_id:          input_number.kitchen_island_led_lights_brightness
                  above:              0
                  value_template:     "{{ (float(state.state) - max_brightness) | int(0) }}"
              then:
                - service:            input_number.set_value
                  target:
                    entity_id:        input_number.kitchen_island_led_lights_brightness
                  data:
                    value:            "{{ max_brightness | int(0) }}"
        - service:     light.turn_on
          target:
            entity_id: light.kitchen_island_led_lights
      turn_on:
        - variables:
            ww_ratio:   "{{ ((   states('input_number.kitchen_island_led_lights_temperature') | int(500) - 152 ) / 348 ) | float(0) }}"
        - service:      light.turn_on
          target:
            entity_id:  light.kitchen_island_led_lights_warm_white
          data:
            brightness: "{{ (2 * states('input_number.kitchen_island_led_lights_brightness') | int(0) * ww_ratio)        | int(0) }}"
        - service:      light.turn_on
          target:
            entity_id:  light.kitchen_island_led_lights_cool_white
          data:
            brightness: "{{ (2 * states('input_number.kitchen_island_led_lights_brightness') | int(0) * (1 - ww_ratio) ) | int(0) }}"
      turn_off:
        - service:      light.turn_off
          target:
            entity_id:  light.kitchen_island_led_lights_warm_white
        - service:      light.turn_off
          target:
            entity_id:  light.kitchen_island_led_lights_cool_white
  3. Describe the bug and how to reproduce it: I have a Template Light that implements the service call light.Turn_On as well as several other necessary service calls in order to turn a warm-white LED strip and a cool-white LED strip into a single light entity with brightness and temperature control. However, when I try to use this light template in the Adapative Light settings, the service call light.turn_on doesn't seem to be getting interrupted in the right way. I've checked the home assistant logs and the only error I'm getting is:

WARNING (MainThread) [homeassistant.helpers.script.kitchen_island_led_lights] Kitchen Island LED Lights: Already running
  1. Steps to reproduce the behavior: call the service light.turn_on for the template light
lennon101 commented 7 months ago

I'd love some feedback or comments on this? Perhaps its how the template light is setup or something else on my end?

lennon101 commented 7 months ago

Here's a snippet from the HA log relating to this issue:

2023-11-30 16:35:56.629 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] (0) _service_interceptor_turn_on_handler: call.context.id='01HGFF1WTM6C50AJ8PTV9RSTYR', is_skipped_hash='False'
2023-11-30 16:35:56.629 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] (1) _service_interceptor_turn_on_handler: call='<ServiceCall light.turn_on (c:01HGFF1WTM6C50AJ8PTV9RSTYR): entity_id=['light.bathroom_vanity_led_lights'], params=>', service_data='{'entity_id': ['light.bathroom_vanity_led_lights'], 'params': {}}'
2023-11-30 16:35:56.629 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] (2) _service_interceptor_turn_on_handler: switch_to_eids='{'Adaptive Lighting: LED Lights ': ['light.bathroom_vanity_led_lights']}', skipped='[]'
2023-11-30 16:35:56.629 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] (3) _service_interceptor_turn_on_handler: intercepting entity_ids='['light.bathroom_vanity_led_lights']'
2023-11-30 16:35:56.629 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Intercepted TURN_ON call with data {'params': {}, 'entity_id': ['light.bathroom_vanity_led_lights']} (01HGFF1WTM6C50AJ8PTV9RSTYR)
2023-11-30 16:35:56.630 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] LED Lights : Setting color_temp of light light.bathroom_vanity_led_lights
2023-11-30 16:35:56.630 DEBUG (MainThread) [custom_components.adaptive_lighting.adaptation_utils] Preparing adaptation data for light.bathroom_vanity_led_lights with service data {'entity_id': 'light.bathroom_vanity_led_lights', 'brightness': 255, 'color_temp_kelvin': 3810}
2023-11-30 16:35:56.631 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Detected an 'light.turn_on('['light.bathroom_vanity_led_lights']')' event with context.id='01HGFF1WTM6C50AJ8PTV9RSTYR'
2023-11-30 16:35:56.631 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] LED Lights : execute_cancellable_adaptation_calls with data: AdaptationData(entity_id=light.bathroom_vanity_led_lights, context_id=01HGFF1WTP:al:JRCU:dpt_:03, sleep_time=0.0, force=False, max_length=1, which=both, initial_sleep=True)
2023-11-30 16:35:56.633 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] (0) _service_interceptor_turn_on_handler: call.context.id='01HGFF1WTM6C50AJ8PTV9RSTYR', is_skipped_hash='False'
2023-11-30 16:35:56.633 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] (1) _service_interceptor_turn_on_handler: call='<ServiceCall light.turn_on (c:01HGFF1WTM6C50AJ8PTV9RSTYR): entity_id=['light.bathroom_vanity_led_lights'], params=>', service_data='{'entity_id': ['light.bathroom_vanity_led_lights'], 'params': {}}'
2023-11-30 16:35:56.633 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] (2) _service_interceptor_turn_on_handler: switch_to_eids='{'Adaptive Lighting: LED Lights ': ['light.bathroom_vanity_led_lights']}', skipped='[]'
2023-11-30 16:35:56.633 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] (3) _service_interceptor_turn_on_handler: intercepting entity_ids='['light.bathroom_vanity_led_lights']'
2023-11-30 16:35:56.633 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Intercepted TURN_ON call with data {'params': {}, 'entity_id': ['light.bathroom_vanity_led_lights']} (01HGFF1WTM6C50AJ8PTV9RSTYR)
2023-11-30 16:35:56.634 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] LED Lights : Setting color_temp of light light.bathroom_vanity_led_lights
2023-11-30 16:35:56.634 DEBUG (MainThread) [custom_components.adaptive_lighting.adaptation_utils] Preparing adaptation data for light.bathroom_vanity_led_lights with service data {'entity_id': 'light.bathroom_vanity_led_lights', 'brightness': 255, 'color_temp_kelvin': 3810}
2023-11-30 16:35:56.635 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Detected an 'light.turn_on('['light.bathroom_vanity_led_lights']')' event with context.id='01HGFF1WTM6C50AJ8PTV9RSTYR'
2023-11-30 16:35:56.635 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] LED Lights : execute_cancellable_adaptation_calls with data: AdaptationData(entity_id=light.bathroom_vanity_led_lights, context_id=01HGFF1WTT:al:JRCU:dpt_:04, sleep_time=0.0, force=False, max_length=1, which=both, initial_sleep=True)
2023-11-30 16:35:56.635 WARNING (MainThread) [homeassistant.helpers.script.bathroom_vanity_led_lights] Bathroom Vanity LED Lights: Already running
lennon101 commented 7 months ago

Just an update on this. I've since discovered that if I un-tick the option intercept tick-box then AL is able to turn the template light and off and change its colour (but not to the correct colour) but that seems to be about it. Brightness control is still not working. Screenshot of current options ticked/unticked below:

Screenshot 2023-11-30 at 8 45 37 pm