adaptive-lighting icon indicating copy to clipboard operation
adaptive-lighting copied to clipboard

Initial Adjustment Delay after light comes online (from `unavailable`)

Open sphbecker opened this issue 1 year ago • 20 comments

I assume HA raises an event when a device goes from offline to online, could Adaptive Lighting listen for that event and trigger an initial transition?

Back story: I switched to Adaptive Lighting from Circadian Lighting. Overall, I think Adaptive Lighting is a more mature project, but one thing lacking is that Adaptive Lighting is MUCH slower on the initial transition when smart bulbs are turned on with a dumb switch. I use primarily Wiz bulbs. Circadian was able to set the correct color as soon as the bulb registered with HA, typically within 1-2 seconds. Adaptive Lighting seems to miss this type of event and the bulb remains at its power-on default until the next interval.

sphbecker avatar Jul 31 '22 14:07 sphbecker

Made the exact same switch here. Wiz lights to HA based circadian rhythm.

It is very possible to do this, even with a blueprint or automation. The device returns a state_changed event from unavailable to on when this happens.

It really should be added into this integration as a feature, it's not as simple to implement for the average user if you have lots of lights affected.

abigdeel avatar Oct 21 '22 19:10 abigdeel

For the time being, I'm using this terribly inefficient automation to do the trick:

alias: Adaptive Lighting - Unavailable to ON Apply
description: ""
trigger:
  - platform: state
    entity_id:
      - light.cree_bulb_lr_1
      - light.cree_bulb_lr_2
    from: unavailable
    to: "on"
    id: lr
  - platform: state
    entity_id:
      - light.bulbrite_kc_1
............
    id: kitchen
condition: []

action:
  - choose:
      - conditions:
          - condition: trigger
            id: lr
        sequence:
          - service: adaptive_lighting.apply
            data:
              entity_id: switch.adaptive_lighting_living_room
  - choose:
.........

Could spend more time cleaning it up, but it does the trick. I'll just add more lights/rooms into this one automation. Now my lights update ~3-5 seconds after powering on, about the time they would take to connect and update state. Not the 90 seconds or whatever you set the interval to in Configure.

Also, I don't think Initial Adjustment Delay refers to what we're asking for. That setting is for OFF to ON, not Unavailable to ON like we're interested in.

Maybe this should be updated to a feature request?

abigdeel avatar Oct 21 '22 23:10 abigdeel

For automations what I did was add a sensor which checks the adaptive lighting brightness level attribute, so auto-on automations can set to the correct level. This doesn't particularly help with other methods of turning the lights on though.

cameronurnes avatar Nov 08 '22 06:11 cameronurnes

@cameronurnes Can you share the yaml for that?

robcresswell avatar Nov 14 '22 11:11 robcresswell

Don't most light bulbs come with power_on_state: on | off | last_known that you can configure?

If your lights are becoming unavailable due to a connection issue in your home, I don't see how programming adaptive-lighting to work around those pre-existing connection issues would help, if anything it'd make the problem more complex and harder to diagnose later on.

Other helpful relevant config options you might have missed:

interval: "interval: Time between switch updates. (seconds)", initial_transition: "initial_transition: When lights turn 'off' to 'on'. (seconds)", sleep_transition: "sleep_transition: When 'sleep_state' changes. (seconds)", transition: "Transition time when applying a change to the lights (seconds)", adapt_delay: "Wait time in seconds between light turn on, and Adaptive Lights applying changes to the light state. May avoid flickering."

th3w1zard1 avatar Mar 22 '23 05:03 th3w1zard1

Don't most light bulbs come with power_on_state: on | off | last_known that you can configure?

If your lights are becoming unavailable due to a connection issue in your home, I don't see how programming adaptive-lighting to work around those pre-existing connection issues would help, if anything it'd make the problem more complex and harder to diagnose later on.

Other helpful relevant config options you might have missed:

interval: "interval: Time between switch updates. (seconds)", initial_transition: "initial_transition: When lights turn 'off' to 'on'. (seconds)", sleep_transition: "sleep_transition: When 'sleep_state' changes. (seconds)", transition: "Transition time when applying a change to the lights (seconds)", adapt_delay: "Wait time in seconds between light turn on, and Adaptive Lights applying changes to the light state. May avoid flickering."

Thank you for the reply. I realize did a poor job explaining the use case. When I referred to the "device going offline" I meant a smart bulb being powered off by a physical switch, not a connection issue. The basic issue is that when power is restored to the bulb, it is interpreted by adaptive-lighting as a manual change (at least for my WiZ bulbs), which I argue is not the desired effect.

I have a perfectly fine work-around, created an automation that listens for the bulb to leave the unavailable state, pause about 300ms and then tell adaptive-listing to turn off manual control for that bulb. I can understand if there are no plans to address this, but I wanted to make sure I correctly explained my usage.

PS: yes, I am one of those old school people who prefers having physical switches in some settings. I have started installing Shelly's behind many of my switches so that I can use them for control without cutting power to the bulb, but I don't yet have a Shelly behind every switch.

sphbecker avatar Mar 22 '23 21:03 sphbecker

This is very odd as when my devices become unavailable they fire OFF state changes to hass. Is there no way you can simply do that?

Adaptive lighting will adapt any off->on state changes, and will set manually controlled when it finds on->on state changes (e.g brightness diff) not caused by the integration.

th3w1zard1 avatar Mar 22 '23 22:03 th3w1zard1

@th3w1zard1 How could a device fire an "off" state change if its had its power cut?

robcresswell avatar Mar 27 '23 13:03 robcresswell

Well that's what home assistant is for, you'd need to fire a state change event, I'm not exactly sure how you could do this.

th3w1zard1 avatar Mar 28 '23 05:03 th3w1zard1

@th3w1zard1 It'd be fairly trivial I think, but mapping your unavailable devices to off would probably break other behaviours

robcresswell avatar Mar 28 '23 11:03 robcresswell

Could anyone share debugging logs? Then I can understand what's going on.

basnijholt avatar Aug 06 '23 03:08 basnijholt

I believe this is the same as https://github.com/basnijholt/adaptive-lighting/issues/96

basnijholt avatar Aug 15 '23 22:08 basnijholt

I have the same issue:

Some Ikea Tradfri Lights that are controlled by physical switches. I use zigbee2mqtt. I currently have manual control turned off completely.

When I turn on the lights, they almost immediately switch from unavailable to on in HA. But AL will apply it's settings only after the next interval, which in my case can be up to 5 minutes.

Is this by design? I guess I could work around it if i make an automation for every light to apply AL settings when state changes from unavailable to on. But that seems like a hassle to me.

marvinpowell avatar Oct 02 '23 05:10 marvinpowell

For everyone using physical switches and using zigbee2mqtt, this is my current workaround:

I did not use the state change from Unavailable to On as Trigger, because that didn't work when the lights were only off for a couple of seconds or minutes - zigbee2mqtt only puts the devices in the unavailable state after 10 minutes.

Instead I created an automation that uses the MQTT Trigger and tries to apply the AL settings on every "DEVICE ANNOUNCE", so every time the light powers up.

With this solutio I don't need a separate automation for every light. This automation works for all lights. There is potential to improve it, for example one could add a condition to check if the entity exists and if adaptive lighting is enabled before running the action, but it works for me.

alias: Adaptive Lighting - Apply on Device Announce
description: ""
trigger:
  - platform: mqtt
    topic: zigbee2mqtt/bridge/event
condition:
  - condition: template
    value_template: "{{ trigger.payload_json.type == \"device_announce\" }}"
action:
  - service: adaptive_lighting.apply
    data:
      lights:
        - light.{{ trigger.payload_json.data.ieee_address }}
      transition: "1"
mode: single

marvinpowell avatar Oct 02 '23 13:10 marvinpowell

Hi @marvinpowell is the topic always the same, it should I change it to homeassistant/bridge/event if my publish topic within Z2M is homeassistant?

It does not trigger any way.

bjornsivertsen avatar Oct 02 '23 19:10 bjornsivertsen

Hi @marvinpowell did you see this?

bjornsivertsen avatar Nov 06 '23 10:11 bjornsivertsen

Hi @marvinpowell did you see this?

@bjornsivertsen it only works if you keep the ieee address as the entity id in HA.

marvinpowell avatar Nov 06 '23 19:11 marvinpowell

Hi @marvinpowell is the topic always the same, it should I change it to homeassistant/bridge/event if my publish topic within Z2M is homeassistant?

It does not trigger any way.

Not sure if the topic is the same for all installations. I looked it up in the logs tab in zigbee2mqtt. Then i turned on a light and looked for the event and topic.

marvinpowell avatar Nov 06 '23 19:11 marvinpowell

Currently running into the same issues described here and it just feels so clunky without a built-in solution. But I couldn't find a better solution other than the ones provided here unfortunately.

What I also noticed for my lights. My office has 1 bulb in the ceiling light and I'm using the automation with the unavailable state trigger from above to reapply the adaptive lighting settings. This one works fine and while it takes a bit, the light comes on already adjusted. For my bedroom though I have a Zigbee group with 4 bulbs for the ceiling light. Here the light comes on and only after a bit the settings are applied. Using the same automation here.

Any idea how I can fix that? I've currently settled to setting the transition to 1 to make it look more natural but it's still a bit ugly

andarotajo avatar Dec 28 '23 09:12 andarotajo

[Copy pasting this message in a few recent open issues]

I just wanted to take a moment to express my heartfelt thanks to everyone that is active in this repo. Your contributions, from answering questions to addressing issues, have been invaluable. It's amazing to see how supportive and helpful our community is!

Adaptive Lighting is all about enhancing your living spaces with smart, sunlight-responsive lighting. We've had quite a few discussions and open issues recently, and I see this as a positive sign of our community's engagement and growth. If you come across anything in the documentation that's unclear or if you have suggestions for improvement, please don't hesitate to share!. Your feedback is crucial for making Adaptive Lighting better for everyone.

On a personal note, I've recently welcomed twin boys into my family, which has been an incredible and life-changing experience. As you can imagine, my time is now more limited, and while I'm doing my best to keep up with the project, there may be delays in my responses. I appreciate your understanding and patience during this time.

Rest assured, I'm fully committed to addressing any bugs, especially those related to new Home Assistant updates, as swiftly as possible. I understand that many issues may stem from hardware limitations or misunderstandings about things like Zigbee groups. Your continued support and collaboration in helping each other out not only strengthen our community but also enhance the Adaptive Lighting experience for all.

Thank you once again for your understanding, patience, and support. Let's keep our houses well lit and adaptive for maximal enjoyment of life! 🌞🏠🌙

basnijholt avatar Mar 03 '24 19:03 basnijholt