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

Manual Control Not Being Declared For Various 'light.turn_on' Calls from Google Assistant and for Scenes #82

Closed regoras closed 1 year ago

regoras commented 3 years ago

The detection of light.turn_on calls frequently doesn't seem to get detected as something where manual control would be desired. I didn't collect logs from the scenes example, but when calling a scene on lights that are under an adaptive lighting control, my automation has to include a call for manual_control before calling the scene, otherwise the lights will not get turned on to the correct color temperature and brightness. (This portion seems to be working for now.)

Similarly, while testing the Gentle Wake feature from Google, I'm finding that if adaptive lighting is enabled on the light, nothing is recognized about the the call to make it manually controlled. Logs below:

2021-02-02 18:43:15 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Detected an 'light.turn_on('['light.living_room_desk_light']')' event with context.id='e194f1bb3836ff2ebef91bf6d45549c1'
2021-02-02 18:43:15 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Detected an 'light.turn_on('['light.living_room_desk_light']')' event with context.id='1a9d75b8d32324b6fd6db0e55b1c39b3'
2021-02-02 18:43:15 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Detected a 'light.living_room_desk_light' 'state_changed' event: '{'min_mireds': 153.0, 'max_mireds': 370.0, 'effect_list': ['None', 'Random', 'Strobe', 'Throb', 'Color Cycle'], 'brightness': 3, 'color_temp': 370.0, 'hs_color': (0.0, 0.0), 'rgb_color': (255, 255, 255), 'xy_color': (0.323, 0.329), 'white_value': 255, 'effect': 'None', 'friendly_name': 'Desk Light', 'supported_features': 191, 'icon': 'mdi:desk-lamp'}' with context.id='1a9d75b8d32324b6fd6db0e55b1c39b3'
2021-02-02 18:43:15 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Office: Detected an 'off' → 'on' event for 'light.living_room_desk_light' with context.id='1a9d75b8d32324b6fd6db0e55b1c39b3'
2021-02-02 18:43:15 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Office: '_update_attrs_and_maybe_adapt_lights' called with context.id='adapt_lgt_6c3a_light_event_1'
2021-02-02 18:43:15 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Adaptive Lighting: Office: '_adapt_lights(['light.living_room_desk_light'], 0.25, force=True, context.id=adapt_lgt_6c3a_light_event_1)' called
2021-02-02 18:43:15 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Office: Scheduling 'light.turn_on' with the following 'service_data': {'entity_id': 'light.living_room_desk_light', 'transition': 0.25, 'brightness': 240, 'white_value': 240, 'color_temp': 370} with context.id='adapt_lgt_6c3a_light_event_1'
2021-02-02 18:43:15 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Detected an 'light.turn_on('['light.living_room_desk_light']')' event with context.id='adapt_lgt_6c3a_light_event_1'
2021-02-02 18:43:15 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Detected a 'light.living_room_desk_light' 'state_changed' event: '{'min_mireds': 153.0, 'max_mireds': 370.0, 'effect_list': ['None', 'Random', 'Strobe', 'Throb', 'Color Cycle'], 'brightness': 240, 'color_temp': 370.0, 'hs_color': (0.0, 0.0), 'rgb_color': (255, 255, 255), 'xy_color': (0.323, 0.329), 'white_value': 255, 'effect': 'None', 'friendly_name': 'Desk Light', 'supported_features': 191, 'icon': 'mdi:desk-lamp'}' with context.id='adapt_lgt_6c3a_light_event_1'
2021-02-02 18:43:54 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Office: '_update_attrs_and_maybe_adapt_lights' called with context.id='adapt_lgt_6c3a_interval_2'
2021-02-02 18:43:54 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Adaptive Lighting: Office: '_adapt_lights(['light.living_room_desk_light'], None, force=False, context.id=adapt_lgt_6c3a_interval_2)' called
2021-02-02 18:43:54 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] State of 'light.living_room_desk_light' didn't change wrt change event nr. 0 (context.id=adapt_lgt_6c3a_interval_2)
2021-02-02 18:43:54 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Office: Scheduling 'light.turn_on' with the following 'service_data': {'entity_id': 'light.living_room_desk_light', 'transition': 30.0, 'brightness': 240, 'white_value': 240, 'color_temp': 370} with context.id='adapt_lgt_6c3a_interval_2'
2021-02-02 18:43:54 DEBUG (MainThread) [custom_components.adaptive_lighting.switch] Detected an 'light.turn_on('['light.living_room_desk_light']')' event with context.id='adapt_lgt_6c3a_interval_2'

From the debug logs and looking at the logs from ESPHome for the bulb, I can see that it's getting turned on at 3% brightness, but then immediately getting controlled by adaptive_lighting.

I'm not sure what the correct solution here is, maybe some sort of state check to see if the new turn_on command is substantively different than the old turn_on command, but driving me a bit nuts over here. I know the Gentle Wake feature works by itself, so maybe the janky solution is just to turn off adaptive_lighting for the appropriate lights when I would want to call Gentle Wake, but that's a bit of a moving target and doesn't really solve that the same issue occurs for a range of other light.turn_on calls (such as calling the service from an automation or from a scene).

Edit: after a quick check, I'll amend that it's when a scene is called from an automation that there are issues with detecting manual_control.

2nd edit: and of course as soon as I go actually try to get logs for the scenes issue, it stops reproducing.

Notes: I do have take_over_control and detect_non_ha_changes enabled. Separate commands is disabled.

regoras commented 3 years ago

I should take notes for myself more often - I was able to reproduce the scenes issue and I suppose this is a bit of a case "read the fine print". The issue seems to be universally tied to (of course) when lights are going from an off state to an on state. Scenes won't stick unless manual_control is manually called before the scene makes the light.turn_on call, otherwise adaptive_lighting just sees it as a regular off to on.

sphanley commented 3 years ago

The Google Assistant piece of this is a big blocker for me in terms of being able to fully use this integration. My wife very frequently tells Google to turn a room's lights on to a specific brightness percentage, and it's a no-go if Adaptive Lighting immediately resets them to a different value. It would be huge if the integration could distinguish cases where the lights were turned on to an arbitrary value that's different from their default, and treat that as a manual_control situation.

regoras commented 3 years ago

Yeah, I'd certainly echo that. Right now, I'm starting to feel like I spend more time wrangling some of the complexities that adaptive_lighting (and all of it's predecessors) introduce in terms of automatic control, than the benefits they provide, but I know it's a bit of an impossible to solve perfectly kind of problem.

Maybe detecting if the call for turn_on is greater than 10% different on any given value (than what adaptive_lighting is calling for? or what the light's old values were?), apply manual_control, even if coming from off? Or at least adding that as an option (detect manual_control from off)? I think from a process/automation standpoint it's easier to have something make a manual_control: false service call when needed, to get adaptive values to apply, rather than the inverse of trying to catch every other case.

Spit-balling - maybe when adaptive_lighting detects a turn_off call, it saves the values for those bulbs in a sensor to compare against when the next turn_on call is applied?

sphanley commented 3 years ago

The thing that makes this so hard is that a manual turn-on can look like a lot of different things. For example, I'm using Philips Wiz bulbs, which have two different defaults you can set during bulb setup - one makes it so that when they're turned on, they go to a specific default brightness/color, and the other says to revert to the last setting from when they were turned off. I'm assuming there are plenty of other bulbs/switches out there that have similar variability in how they work.

Or for another example - for my Lutron Caseta switched lights, I can turn them on from the physical switch one of two ways - either hitting the top-most "on" button, which turns them to 100%, or by hitting the "dimmer up" button, which turns them on to a very low brightness. I'd like to use Adaptive Lighting to manage their brightness when I don't have a specific brightness intention, but which of those should be treated as a sign that I want to manually control it? Both? Neither?

I don't envy anyone trying to come up with good answers as to how to handle these cases. I suspect that in my case, given the variety of bulbs I'm using and the variety of ways they're going to be triggered, I'm just not a good fit for this integration.

regoras commented 3 years ago

Hmm, new change coming in 2021.2 for HA, I wonder if this will have any impact that may help this issue or if it's all local on HA.

“Significant Changes” for Google Home and Amazon Echo Home Assistant now has the concept of a significant change. Essentially Home Assistant will prevent reporting small changes to sensors in the recorder and voice assistants. So if a temperature sensor only changes by point 1 of a degree, then that change won’t be sent to Google Home or Amazon Echo.

This should reduce the amount of traffic flowing around these devices, making everything perform a bit better.

https://hasspodcast.io/ha080

RubenKelevra commented 3 years ago

Hey @regoras,

can you confirm this issue for a more recent HA version? :)

keshavdv commented 2 years ago

I've still run into this when using the gentle wake-up feature on Google Home. Depending on the time of day, adaptive lighting will kick in and override the brightness instead of following the expected, slow transitions.

jukkyrjo commented 1 year ago

I can also reproduce this: Activating a scene from off state with voice, physical button or app bypasses take over control and detect non ha changes, when the proper behavior would be to set their state to manual control

th3w1zard1 commented 1 year ago

Is anyone still having this issue with the latest adaptive lighting version 1.7.0?

jukkyrjo commented 1 year ago

Is anyone still having this issue with the latest adaptive lighting version 1.7.0?

Yes. To replicate:

  1. Lights setup with up-to-date Adaptive Lighting
  2. Have lights off
  3. Ask Google Assistant to set a certain scene OR tap a scene in Philips Hue app OR Google Home etc.
  4. Lights turn on with the correct scene BUT adaptive lighting takes over and changes them in 1-3 seconds
th3w1zard1 commented 1 year ago

@jukkyrjo Oh that's expected behavior as lights need to be on before you change their brightness/color. There's a vote going on right now on the V2 Roadmap to change this behavior, please check it out!

th3w1zard1 commented 1 year ago

@jukkyrjo specifically see https://github.com/basnijholt/adaptive-lighting/discussions/291#discussioncomment-2886261 for the discussion.