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

adaptive_lighting.manual_control throws "Unable to find referenced entities" for working lights

Open bverkron opened this issue 4 years ago • 1 comments

Location

adaptive_lighting.manual_control

Description

Not sure if this is a bug, documentation issue or configuration issue on my end.

Scenario: I have take_over_control enabled and a light has been turned a different colour (red) by an automation so adaptive lighting has been suspended for this light. I want to return control to adaptive lighting without having to toggle the light off / on again (which does work but is a clunky solution). My understanding is that I should still be able to return control to the adaptive lighting integration with adaptive_lighting.manual_control based on this line of the documentation:

... the Adaptive Lighting component will stop adapting that light until it turns off and on again (or if you use the service call adaptive_lighting.set_manual_control)

However, when I make the following service call from a script

sequence:
  - service: adaptive_lighting.set_manual_control
    data:
      entity_id: light.desk_bulb
      lights: light.desk_bulb
      manual_control: false
mode: single
alias: Reset Bedroom
icon: mdi:bed

... the log shows this warning and nothing happens with the light.

Unable to find referenced entities light.desk_bulb

This perplexes me because the entity by that name most definitely exists and I use that entity_id to control the light via automations, etc.

So, I'm wondering if I've misunderstood the doc and configured the service call wrong or if there's some other problem. If I remove the lights: light.desk_bulb I get the same error so it's definitely referring to the entity_id line

bverkron avatar Dec 16 '21 00:12 bverkron

I see the issue now. entity_id needs to be one of the switch entities that are created by the adaptive lighting component, in my case switch.adaptive_lighting_home.

The doc is confusing because it states at the beginning that, for example, switch.adaptive_lighting_living_room would be created but that example switch name doesn't show up anywhere else in the doc so you cannot search the page for examples of how it would be used. Further the doc for set_manual_control is heavily parameterized and doesn't actually give an example of what the value of entity_id should be, it just shows the parameter/variable name of {{ switch }}. Thus it's really hard to get a sense of how to actually use services like .apply (which doesn't have a working example at all) or .set_manual_control (which doesn't show you what should be passed to it in the data section). I had to dig through examples on the Home Assistant forum / reddit to understand how this is supposed to work.

Switching to this works for my use case. (I had tried .apply in the beginning but moved to .set_manual_control during troubleshooting)

Script to reset adaptive lighting (make it apply adaptive lighting to a manually controlled light)

alias: Reset Adaptive Light
sequence:
  - service: adaptive_lighting.apply
    data:
      entity_id: switch.adaptive_lighting_home
      lights: '{{ light }}'
      adapt_color: 'yes'
fields:
  light:
    name: Light
    description: Light entity that should have adaptive lighting reset
    required: true
    selector:
      entity:
        domain: light
mode: single
icon: mdi:lightbulb-on-outline

Calling script (could be done from an automation too)

sequence:
  - service: script.reset_adaptive_light
    data:
      light: light.desk_bulb
mode: single
alias: Reset Bedroom
icon: mdi:bed

Going to leave this issue open as I think the documentation on this could be much clearer, but I do not have time at the moment to make suggested changes and submit a PR.

bverkron avatar Dec 17 '21 21:12 bverkron

Yeah this definitely takes some getting used to. adaptive-lighting has no way (currently) to get a switch's entity id from a light, so you need to pass the switch's entity id as it's the entity containing all the adapt data for the light (it's where manual_mode gets set)

I'm going to rename your issue to make it easier for devs to reference when moving forward with the current code.

th3w1zard1 avatar Mar 23 '23 17:03 th3w1zard1

The linked PR is now merged. Can close this issue :)

basnijholt avatar Mar 26 '23 03:03 basnijholt