basnijholt / adaptive-lighting

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

Can't seem to get manual control working. #91

Closed chadbaum closed 1 year ago

chadbaum commented 3 years ago

Hi, I may totally be misunderstanding the functionality provided, but I have both "take_over_control" and "detect_non_HA_changes" flags enabled in the UI setup, but when someone changes the brightness on a physical switch that is on and already adapted, the brightness will still be adapted/reverted about 20 seconds later. The only way to stop adaptive lighting from overriding it is through HA alone, which has serious WAF issues.

Thanks for the help! Otherwise love the component.

Mrten commented 3 years ago

I have the same and I was suspecting that my tradfri hub is somehow having troubles. No logs yet.

Profil404 commented 3 years ago

Same problem here with Philips Hue + ConBee II + Deconz.

camStryk3r commented 3 years ago

Any updates on this? Having the same issue with the TP-Link HS220 switches. I may also be misunderstanding how to use take_over_control, but each time I set the brightness on the physical switch to a level that's different than the adapted brightness, it reverts back to the adapted brightness after 20-30 seconds.

LukaszP2 commented 3 years ago

Did you have resolution?

jezstinger commented 3 years ago

Same issue here. I'm using Shelly Dimmer 2's and it seems hit or miss if the light will stay dimmed when someone hits the switch.

Seems a few others are having this problem as well

https://community.home-assistant.io/t/new-adaptive-lighting-integration/243788/192?u=jiredell

mindtripper commented 3 years ago

I've worked around the issue that manual_control is sometimes not detected when I use my Ikea switches to control the brightness of my lights.

It is a work in progress, but it is working in my environment. So, I thought I'd share. When I control any light via device external to HA. then this is more or less instantly picked up and the lights involved are set to manual_control.

Using this technique I have no need for detect_non_ha_changes: true

Notes:

This is the "code":

light:
  - platform: group
    name: all_except_entrance
    entities:
      - light.kitchen_table
      - light.kitchen_window
      - light.kitchen_spot1
      - light.kitchen_spot2
      - light.kitchen_spot3
      - light.kitchen_spot4
      - light.kitchen_spot5
      - light.hall
      - light.living_room_picture_wall
      - light.living_room_glow
      - light.office_table
      - light.aaa
      - light.bbb
      - light.ccc
      - light.ddd
  - platform: group
    name: livingroom
    entities:
      - light.office_table
      - light.living_room_glow
      - light.living_room_picture_wall
  - platform: group
    name: bedrooms
    entities:
      - light.aaa
      - light.bbb
      - light.ccc
      - light.ddd

automation:
  - alias: "Turn on lights outside HA set to manual control TESTING"
    mode: parallel
    max: 100
    trigger:
      - platform: event #https://www.home-assistant.io/docs/automation/trigger/#event-trigger
        event_type: state_changed
    variables:
      light: "{{ trigger.event.data.entity_id | default }}"
      newlight: "{{ trigger.event.data.new_state.entity_id | default }}"
      oldlight: "{{ trigger.event.data.old_state.entity_id | default }}"
      domain: "{{ trigger.event.data.new_state.domain | default }}"
      newstate: "{{ trigger.event.data.new_state.state | default }}"
      oldstate: "{{ trigger.event.data.old_state.state | default }}"
      context_user_id: "{{ trigger.event.data.new_state.context.user_id | default }}"
      context_id: "{{ trigger.event.data.new_state.context.id | default }}"
      context_parent_id: "{{ trigger.event.data.new_state.context.parent_id | default }}"
      new_brightness: "{{ trigger.event.data.new_state.attributes.brightness | default }}"
      old_brightness: "{{ trigger.event.data.old_state.attributes.brightness | default }}"
      new_color_temp: "{{ trigger.event.data.new_state.attributes.color_temp | default }}"
      old_color_temp: "{{ trigger.event.data.old_state.attributes.color_temp | default }}"
    condition:
      - "{{ domain == 'light' }}"
      - "{{ newstate == 'on' }}"
      - "{{ oldstate == 'on' }}"
      - "{{ context_parent_id == none }}"
      - "{{ context_user_id == none }}"
      - "{{ 'adapt_lgt_' not in context_id }}"
      - "{{ new_brightness !=  old_brightness }}"
      - "{{ light in expand(state_attr('light.all_except_entrance', 'entity_id'))|map(attribute='entity_id')|list}}"
    action:
      - service: system_log.write
        data:
          message: "Monitor Adaptive Lighting ({{ light }}/{{ newlight }}/{{ oldlight }}) changed by {{ context_user_id }}/{{ context_id }}/{{ context_parent_id }}. Brigthness ({{ old_brightness }}-> {{ new_brightness }}). Color Temp ({{ old_color_temp }}-> {{ new_color_temp }})"
          level: warning
      - service: script.manual_control_of_light
        data:
          light: "{{ light }}"

script:
  manual_control_of_light:
    alias: 'Light changed outside HA. Set Adaptive Lighting Manual Control'
    mode: parallel
    sequence:
      - choose:
          - conditions:
              - condition: template
                value_template: "{{ light in expand(state_attr('light.bedrooms', 'entity_id'))|map(attribute='entity_id')|list}}"
            sequence:
              - service: adaptive_lighting.set_manual_control
                data:
                  entity_id: switch.adaptive_lighting_bedrooms
                  manual_control: true
                  lights: "{{ light }}"
          - conditions:
              - condition: template
                value_template: "{{ light in expand(state_attr('light.livingroom', 'entity_id'))|map(attribute='entity_id')|list}}"
            sequence:
              - service: adaptive_lighting.set_manual_control
                data:
                  entity_id: switch.adaptive_lighting_livingroom
                  manual_control: true
                  lights: "{{ light }}"
pfak commented 3 years ago

I think take_over_control doesn't work properly (at least with Hue Hub) because take_over_control is looking for light on/off service calls instead of state_changed.

If I turn on/off a light using Hue tap switch, it shows state_changed and not a service call. I wonder if this is due to the change in the way Hue integration tracks states?

broyuken commented 3 years ago

That automation/script seems fairly straightforward, this logic should be fairly easy to add into the component itself.

basnijholt commented 3 years ago

is looking for light on/off service calls instead of state_changed

Unfortunately, this needs to be the case because some lights just randomly update their status to some slightly different light setting all the time.

Only when using detect_non_HA_changes then it looks at state changes.

@mindtripper, I do not really understand why your automation would work. IIUC you switch to manual control on every state change, also the ones resulting from adaptive-lighting. Perhaps I am missing something?

mindtripper commented 3 years ago

@basnijholt I only trigger the automation if the change was not made by Adaptive Lighting and only if the brightness has changed. The key is in conditions. This is my use-case as Adaptive Lightning via "detect_non_ha_changes" does not reliably detect these changes using Ikea Trådfri light and controllers.

    condition:
      - "{{ 'adapt_lgt_' not in context_id }}" #ensures it is adaptive lighting making the change.
      - "{{ new_brightness !=  old_brightness }}" # ensures it only triggers if the brightness has changed.

This can of course be extended to any light attribute change. But for me brightness is key.

The script condition ensures that a lights in not set to manually_controlled if it's already manually_controlled.

              - condition: template
                value_template: "{{ light in expand(state_attr('light.bedrooms', 'entity_id'))|map(attribute='entity_id')|list}}"

Side-note: I even have an automation that triggers if any of my HA users turn on the light from off. The use-case being that;

    trigger:
      - platform: event
        event_type: state_changed
        context:
          user_id:
            - "zzzzzxxxyyyzxxxyzyzyxyxz" # Me
            - "zzzzzxxxyyyzxxxyzyzyxyxz" # Someoneelse

    condition:
      - "{{ domain == 'light' }}"
      - "{{ new_state == 'on' }}"
      - "{{ old_state == 'off' }}"

As an added bonus I do not need HA to call 'homeassistant.update_entity' every 'interval'.

Profil404 commented 2 years ago

Hi,

Any update about this issue ?

RubenKelevra commented 2 years ago

I'm currently in the process of doing version 2. This will be added/fixed.

Keep this ticket open until you can verify that it's properly working in the upcoming version 2.

bdunn44 commented 2 years ago

Is there an update on when version 2 is coming out? My wife can't control our dimmers manually. She's about to rage.

Assume I'll need to implement the workaround above, but this has been open for over a year... What gives?

broyuken commented 2 years ago

If your wife’s gonna rage maybe turn off AL

bdunn44 commented 2 years ago

You can turn this thing off!?!? What a revelation

michaelsleen commented 1 year ago

I have Philips Hue lights throughout my home connected to a Hue hub. Many of them are controlled by a Lutron Aurora Smart Bulb Dimmer Switch for adjusting the brightness, and turning on and off. I love AL, but take_over_control and detect_non_ha_changes do not work at all for me with these bulbs and switches. I'm desperate for a solution to restore peace in my home.

wgregorian commented 1 year ago

Like the other Hue consumers, AL is invasive even with the take_over_control and detect_non_ha_changes toggles enabled.

Would love it if this one was given a little more attention.

th3w1zard1 commented 1 year ago

Should be fixed in 1.10.0