Adaptive Lightning Settings

I’ve thought of some better optimizations I’m going to add but I’ll update the same link so check back whenever as I’ll try and keep it in sync for anyone in this same boat.

1 Like

I updated my automation to make it easier to use. Basically, one only has to update the switches triger_variable such that each key is the switch and the value is the light group it targets.

Initially I wrote this with only smart bulbs in mind but I added another Blue 2-1 switch which targets dumb LED lights which I may change at another time so I wanted to make sure I don’t have to update this much later.

Anyways, hope this helps. I tried writing a blueprint but the need for a dictionary would have required a template input or creating some helper mapping and neither are as easy as updating the few lines in the automation YAML.

1 Like

I’ve been a little busy but took some time this evening to reimplement using Pyscript. With that, you can simply add a ZHA group light entity in which an Inovelli switch is a member and it’ll handle the same use case. Here is the example config:

pyscript:
  apps:
    inovelli_al_fixer:
      - al_sleep_switch: switch.adaptive_lighting_sleep_mode_default
        al_switch: switch.adaptive_lighting_default
        lights:
          - light.hallway
          - light.kitchen
          - light.kitchen_dining
          - light.living_room
          - light.stairway

In my case, this is handling 7 different Inovelli switches (I’ve been lazy and haven’t installed my new ones yet…).

My code is here. I did create a blueprint but it’s much more work to maintain, harder to document, and one must manually ensure Inovelli devices and the ZHA group entity are kept up to date. This new setup inspects the entity_registry entry and ensures that translation_key == 'light_groups' and then determines ZHA group, gets group members, filters for Inovelli switches, and then sets up triggers based on them.

Anyways, hope this helps.

1 Like

I have been using Node-Red to get around this. I want my lights to be bound to the switches and I want the switches to display current brightness levels and on/off while sending the color_temp, xy, hs, rgb commands etc… to the bound light group. Finally got away from Node-Red and got it all in Home Assistant by creating a custom MQTT Light object in the HA configuration.yaml and now have all that I wanted for these.

See image below for how I accomplished this:

I also use the Homekit capability of Home Assistant to publish this back to Homekit for Siri voice commands and mobile usage. For Adaptive, using the Adaptive Lighting from HACS and just making sure to send On/Off, Brightness, Color_temp etc… as separate commands on first turn on.

All seems fabulous so far.

1 Like

Nice but I’m using standard ZHA though seriously contemplating switching but I have 61 devices and would be a headache.

Having said that, I’m thinking of dumping Adaptive Lighting for the 💡 Sensor Light - Motion Sensor - Door Sensor - Sun Elevation - LUX Value - Scenes - Time - Light Control - Device Tracker - Night Lights - Blueprints Exchange - Home Assistant Community Blueprint. I’ve done a little testing and it accomplishes much of the same objective without the headaches. Plus it has a night light feature which is kinda nifty.

I considered both when first installing my Blue 2-1s. The Internet seems filled with reasons to use z2m, but I didn’t see all of the advantages that were talked about being worth the slightly more complex setup. I’d used ZHA a bit before and enjoyed some of the easier (or more familiar) setup interfaces, for instance scenes. I’m not saying one’s better than another, but some of the advantages that people suggest for z2m like custom quirks are now in ZHA as well.

Anyway, I stayed with ZHA for the time being.

z2m is far easier to configure and a little easier to visually inspect bindings which I do like. It also has the ability to create entities for device triggers which is nice at times.

If you’re talking about Zigbee scenes, there is support for that. If it’s HA scenes, then an entity is an entity. I have mostly stopped using HA scenes and just operate on labels since I’ve found some device weirdness with HA scenes.

If you’ve not used z2m, I’d buy a second controller and try it out. There are some nice features there. In fact, I have an extra controller so maybe I’ll do that with one of my switch/light groups.

It also decouples you nicely from Home Assistant. It’s really annoying with a large Zigbee network that it shuts down and restarts whenever Home Assistant does.

That’s a great point that I didn’t think about. I guess even more reason to setup my second controller this week!

I’ll update with my results once I get a change to move a Zigbee group container a blue switch and bulbs to z2m.

Has anyone been able to get the ‘auto reset’ timer working?

What is the use case? I often find times where I want to temporarily turn off the adaptive lighting service. Then after a specified period of time, they automatically resume adaptive lighting. Until now, I have tried various combinations of the adaptive lighting settings ranging from “take over control,” “detect non ha changes,” skip redundant commands,” etc. None of which seem to be triggering the manual trigger (found in AL’s main switch attributes). It is my understanding that ‘manual control’ will be set to yes when I double click up, down, hold down or up on the zigbee 2-1 switch.

I am only using the 2-1 switch. No smart bulbs.

Has anyone had any success with the manual control?

I would love to get some help. I have blue dimmers with Hue bulbs as well. I do not use AL to adjust brightness, nor do I want to. I only want to control the color_temp. All of my bulbs are ambiance bulbs and I have execute_if_off set to true. I just can’t get rid of the initial transition. It always turns on at the previous color and then transitions. It can be jarring at times.

You state that this mqtt entry is in your configuration yaml. Do I need to create one of these for each light group? For each light? Can I just remove the brightness topics if all I want is the color_temp?

I would appreciate any help anyone can provide to me on this. Thanks in advance.

I’m guessing that you local control enabled (which is enabled by default). This means that the switch will turn on the load as well as send a message to Home Assistant that the light has been turned on. One of those two things will clearly happen much faster than the other. (Electricity through a wire will always beat a message sent wirelessly.) Home Assistant (and Adaptive Lighting) won’t be able to do anything about the fact that the load was turned on before it received a notification of that occurring. If you want there to be no transition, disable local control on your switch and write an automation to turn the light on when the paddle up is pressed. I’m guessing this will remove any transition time as Adaptive Lighting should be able to intercept that turn_on call and get the right color. (You may still need to play with some Adaptive Lighting settings depending on how you currently have things configured.)

I assume you mean Local Protection. I don’t see a Local Control. It appears that I have it Disabled, but through some GoogleFu it seems that I may actually want to Enable that. I will try and report back.

Ah, yes. Sorry, I was going from memory. Your corrections are in line with my intended suggestion.

Thanks. I tried to flip that and it made no difference. I fear I am going to have to make some sort of workaround automation.

I’ve been frustrated by the same issue, and seeing your post here yesterday reminded me to look into fixing it again. I came across this automation and it’s pretty much solved the problem!

I had to make one modification, because I have some adaptive lighting instances that adapt only brightness, so I added a check to make sure adapt_color was on before publishing the color updates. Here’s my version of the script in full:

alias: Maintain Adaptive Lighting Color Temperature
description: >-
  Primes the color temperature of lights that are controlled by adaptive
  lighting

  and are currently off
triggers:
  - trigger: time_pattern
    minutes: /5
conditions: []
actions:
  - repeat:
      for_each: |-
        {{integration_entities("adaptive_lighting")|
          select("match","^switch\.adaptive_lighting_.*")|
          reject("match","^switch\.adaptive_lighting_adapt_.*")|
          reject("match","^switch\.adaptive_lighting_sleep_mode_.*")|
          list}}
      sequence:
        - variables:
            adaptive_lighting: "{{repeat.item}}"
            adaptive_lighting_lights: |-
              {{expand(state_attr(repeat.item,"configuration").lights)|
                selectattr("state", "==", "off")| map(attribute="entity_id")|
                list}}
        - if:
            - condition: template
              value_template: >-
                {{
                states(adaptive_lighting|replace('adaptive_lighting','adaptive_lighting_adapt_color'))
                == 'on' }}
          then:
            - repeat:
                for_each: "{{adaptive_lighting_lights}}"
                sequence:
                  - if:
                      - condition: template
                        value_template: "{{repeat.item in mqtt_entities}}"
                    then:
                      - action: mqtt.publish
                        data_template:
                          topic: >-
                            zigbee2mqtt/{{state_attr(repeat.item,
                            "friendly_name")}}/set
                          payload: |-
                            {
                              "color_options": {
                                "execute_if_off": "true"
                              }
                            }
                      - delay:
                          hours: 0
                          minutes: 0
                          seconds: 0
                          milliseconds: 100
                      - action: mqtt.publish
                        data_template:
                          topic: >-
                            zigbee2mqtt/{{state_attr(repeat.item,
                            "friendly_name")}}/set
                          payload: |-
                            {
                              "color_temp": {{state_attr(adaptive_lighting, "color_temp_mired")}},
                              "transition": 0
                            }
mode: single
variables:
  mqtt_entities: "{{integration_entities(\"mqtt\")}}"

Note: my AL is pointed at some zigbee groups in addiditon to individual lights. I don’t believe this automation will set execute_if_off for the members of the group, and I don’t know if that matters – I had already set it for each individual light in each group. If you have zigbee groups adapted by AL and this automation doesn’t work, I’d try setting execute_if_off to true for each individual light and see if that fixes the problem.

The original author seems to be updating/cleaning up the automation further here

Ok. This is great. I do have execute_if_off already turned on for all individual bulbs. I don’t know how to set that for groups, but I do have it for each bulb. I did verify that execute_is_off is set to true by looking at the state in all lights. I don’t mind adding this automation if it works. I am just not sure exactly what I need to do. Do I just copy and past that into a new automation.

I am not scared of yaml. My entire dashboard is yaml, but all of my automations have been built through the GUI.

Yes, just create a new automation, switch to “Edit in YAML” mode in the 3-dot menu in the top right, paste in the code and save. It’ll run every 5 minutes while it’s enabled.

I updated my own script to match the original author’s clean version, reintroduced my check for if adapt_color was on, and also added another filter to only select lights that accept color_temp commands (in addition to being off and controlled by AL). That updated code is here:

alias: Maintain Adaptive Lighting Color Temperature
description: >-
  Primes the color temperature of lights that are controlled by adaptive
  lighting and are currently off
triggers:
  - trigger: time_pattern
    minutes: /5
conditions: []
actions:
  - repeat:
      for_each: "{{enabled_adaptive_lighting_entities}}"
      sequence:
        - variables:
            adaptive_lighting_entity: "{{repeat.item}}"
            lights_currently_off_and_controlled_by_adaptive_lighting_entity: |-
              {{state_attr(adaptive_lighting_entity, "configuration").lights |
                expand |
                selectattr("state", "==", "off") |
                selectattr("attributes.supported_color_modes", "defined") |
                selectattr("attributes.supported_color_modes", "contains", "color_temp") |
                map(attribute="entity_id") |
                list}}
            color_temp_according_to_adaptive_lighting_entity: "{{state_attr(adaptive_lighting_entity, \"color_temp_mired\")}}"
        - if:
            - condition: template
              value_template: >-
                {{ 
                states(adaptive_lighting_entity|replace("adaptive_lighting","adaptive_lighting_adapt_color")) 
                == "on" }}
          then:
            - repeat:
                for_each: >-
                  {{lights_currently_off_and_controlled_by_adaptive_lighting_entity}}
                sequence:
                  - variables:
                      light_currently_off: "{{repeat.item}}"
                      mqtt_topic: >-
                        zigbee2mqtt/{{state_attr(light_currently_off,
                        "friendly_name")}}/set
                  - if:
                      - condition: template
                        value_template: >-
                          {{light_currently_off in
                          configured_light_entities_provided_by_mqtt}}
                    then:
                      - action: mqtt.publish
                        data_template:
                          topic: "{{mqtt_topic}}"
                          payload: |-
                            {
                              "color_options": {
                                "execute_if_off": "true"
                              }
                            }
                      - delay:
                          hours: 0
                          minutes: 0
                          seconds: 0
                          milliseconds: 100
                      - action: mqtt.publish
                        data_template:
                          topic: "{{mqtt_topic}}"
                          payload: |-
                            {
                              "color_temp": {{color_temp_according_to_adaptive_lighting_entity}},
                              "transition": 0
                            }
mode: single
variables:
  configured_light_entities_provided_by_mqtt: |-
    {{integration_entities("mqtt") |
      select("match", "^light\.") |
      expand |
      map(attribute='entity_id') |
      list}}
  enabled_adaptive_lighting_entities: |-
    {{integration_entities("adaptive_lighting") |
      select("match", "^switch\.adaptive_lighting_.*") |
      reject("match", "^switch\.adaptive_lighting_adapt_.*") |
      reject("match", "^switch\.adaptive_lighting_sleep_mode_.*") |
      expand |
      selectattr("state", "==", "on") |
      map(attribute="entity_id") |
      list}}

Awesome. Thanks man. I created the automation, but wil have to do some fine-tuning when I get home. I am getting this error. Out of curiosity, do you have your AL instances pointed at bulbs directly or the Z2M groups. I currently have it pointed to my groups that all have the dimmer switch as part of the group.