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