Creating an input_select control using data from light

Hi guys,

First time posting as I thought I might be able to figure this on my own, but failed miserably :slight_smile:

I have Gove RGBICWW lights that have effects; I want to be able to change the “effect” using a dropdown input select box that has it’s values dynamically generated from the “effect_list”

I can use the following to get the list of effects in Template:
{{state_attr("light.lounge_lighting", "effect_list") | list }}

which outputs the following list:
['', 'Action', 'Action-A', 'Action-B', 'Action-C', 'Action-D', 'Adventure Game', 'Adventure Game-A', 'Adventure Game-B', 'Afternoon', 'Atlantis', 'Aurora', 'Aurora-A', 'Aurora-B', 'Awaken', 'Ballet', 'Ballet-A', 'Ballet-B', 'Birthday', 'Breaking', 'Breaking-A', 'Breaking-B', 'Breathe', 'Business', 'Candlelight',...]

The bit where it falls down is where I attempt to generate the input_select control in config.yaml:

input_select:
lounge_scene:
name: Current Lounge Ambience
data:
- {{state_attr(“light.lounge_lighting”, “effect_list”) | list }}

…its a bust.

…but I’m also thinking it can’t be hard to populate a list with dynamic data, right…

Hope I’ve explained myself right… any help would be MUCH appreciated (doing my head in!)

HA Docs - Template Integration - Select

1 Like

Erm… I get it, but I don’t get which example works in my instance (sorry I’m very new at this)

Your case is probably like Example 2, but with templated options. But it really depends on the desired behavior. Do you just want a select with dynamic options that you plan on referencing in a script or automation? Or do you want something to happen automatically when you make a selection?

template:
  - trigger:
      - platform: event
        event_type: custom_set_selected_lounge_ambience
    sensor:
      - name: Selected Lounge Ambience
        unique_id: selected_ambience_0001 
        state: "{{ trigger.event.data.ambience }}"
        attributes:
          description: "Required helper entity for select.current_lounge_ambience"

  - select:
      - name: Current Lounge Ambience
        unique_id: current_lounge_ambience_0001
        state: "{{ states('sensor.selected_lounge_ambience')}}"
        options: "{{ state_attr('light.lounge_lighting', 'effect_list') }}"
        select_option:
          - event: custom_set_selected_lounge_ambience
            event_data:
              ambience: "{{ option }}"
          - service: light.turn_on
            entity_id: light.lounge_lighting
            data:
              effect: "{{ option }}"
1 Like

This clarifies things a bit thanks!

So what I want to do is to be able to select one of the options from “effect_list” and that effect then be applied to "light.lounge_lighting; in essence it’s exposing the Effect button in More Info:

For that you would just add the light service call to the actions in the select_option section, I’ve updated the post above.

You, sir, are a muthafreakin’ legend!
Gracias!
That works and makes sense, plus the principle can also be applied to other non-exposed lists :slight_smile:

@Didgeridrew, I’ve added the YAML above to config.yaml, but the sensor and the select haven’t built after a full reload… anything I am being dumb about?:

Did you do a reload or restart? You need a restart when adding the first instance of an integration.

Did both… now just rebooting the actual VM it’s in :slight_smile:

Just having a look at my paste, is the sensor declaration missing a hyphen?

No, the sensor should not have a hyphen… the list item it is part of starts with trigger so that’s where the hyphen is.

Are you sure that file is actually being merged into your configuration properly?

Don’t think so

It looks like the Filebrowser addon has tricked you…

Go to homeassistant>configuration.yaml, paste it there, save it, then restart HA.

1 Like

…like a boss, sir… it worked!

image

Made a tweak in the YAML as well, so the current effect is shown as the state:
image

I used the example from dnwlmz to create a template and partially works. Disadvantage: the history of the state/effect is not working properly, usually showing Unknown status. For better functionality overall, use a custom template in configuration.yaml, as mentioned before. Maybe someone can experiment a bit more on this to work or it could be fixed in a future update.

Using Home Assistant Core 2024.8.2 (on VM) with HA OS 13.1, in case it matters. I tried adding the same template through the interface in Settings/Devices & services/Helpers (tab) → Create Helper-> Template → Template a select.

I will use the same settings/names added by dnwlmz in his example. You should be able to just copy paste the values and replace the entity (for state and options).
Name:
Selected Lounge Ambience
State template
{{ states(‘light.lounge_lighting’)}}
Available options
{{ state_attr(‘light.lounge_lighting’, ‘effect_list’) }}

Actions on select: choose Light: Turn on, select the light entity, make sure you check Effect and add as value {{option}}. Click Save/Submit.

I just tried to thinker a bit with the GUI to see if you can reach a similar functionality.

You could add a bit more functionality by using the following:

Name:

Selected Lounge Ambience

State template

{% if state_attr('light.lounge_lighting', 'effect') is defined and 
state_attr('light.lounge_lighting', 'effect') is not none %}
  {{ state_attr('light.lounge_lighting', 'effect')}}
{% else %}
  {{ states('light.lounge_lighting') }}
{% endif %}

Available options

{{ state_attr(‘light.lounge_lighting’, ‘effect_list’) + ['on', 'off'] }}

Actions on Select

choose:
  - conditions:
      - condition: template
        value_template: "{{ option == 'off'}}"
    sequence:
      - action: light.turn_off
        metadata: {}
        data: {}
        target:
          entity_id: light.lounge_lighting
  - conditions:
      - condition: template
        value_template: "{{ option == 'on'}}"
    sequence:
      - action: light.turn_on
        metadata: {}
        data: {}
        target:
          entity_id: light.lounge_lighting
default:
  - action: light.turn_on
    metadata: {}
    data:
      effect: "{{option}}"
    target:
      entity_id: light.lounge_lighting