Automation to list all scenes in area, and add these to an input select

Hi

I am trying to dynamically populate an input select with the names of all scenes in an area. This is to make it easy to show all in a dashboard, without having to edit it each time a scene is added.
Anyone have any idea how to accomplish such a goal. Have not found any examples, is it possible?. Not yet good enough to roll my own

Thanks

1 Like

Check Select/activate Hue scenes in new v2 Api setup - #27 by Mariusthvdb

It’s what I do to with hue scenes.

Thanks @Mariusthvdb

You can also use a Template Select… the following example uses an Input text helper to save the selected option. It also turns the selected scene on, but that is optional.

template:
  - select:
      - name: "Kitchen Scenes"
        state: "{{ states('input_text.selected_kitchen_scene') }}"
        options: >
          {{ expand(area_entities("Kitchen"))
          | selectattr('domain', 'eq', 'scene')
          | map(attribute='name')
          | list }}
        select_option:
          - variables:
              entity: >
                {{ states.scene | selectattr('name', 'eq', option) | map(attribute='entity_id') | join }}
          - service: input_text.set_value
            target:
              entity_id: input_text.selected_kitchen_scene
            data:
              value: "{{ option }}"
          - service: scene.turn_on
            target:
              entity_id: "{{ entity }}"

Update: It is possible to accomplish the goal without using an Input Text to hold the state

7 Likes

@Didgeridrew thanks, that looks like more what I was thinking of. Need to digest it fully

Cheers

@Didgeridrew this works perfectly! Thanks very much

1 Like

I am working on something very similar. I am setting up a blueprint and would like to provide a Select selector that lists all scenes in the home. Unfortunately, I can’t figure this one out based on the code above. @Didgeridrew Do you maybe have a suggestion?

Wait - nevermind! I just realized that the scene is an entity like any other and I can just use the entity selector for this with a domain of scene.

I’ve never touched templates before so this is my first attempt. But I’m interested in getting this to work and not having to manually input these for smart switches.

I wondered if you had an example of what you’ve configured to get this to work?

I’ve got this config so far:

configuration.yaml

template: !include templates.yaml

this is the templates.yaml file:


  - select:
      - name: "Kitchen_Scenes"
        state: "{{ states('input_text.selected_kitchen_scene') }}"
        options: >
          {{expand(area_entities("Kitchen"))
          | selectattr('domain', 'eq', 'scene')
          |map(attribute='name')
          | list }}
        select_option:
          - variables:
              entity: >
                {{ states.scene | selectattr('name', 'eq', option) | map(attribute='entity_id') | join }}
          - service: input_text.set_value
            target:
              entity_id: input_text.selected_kitchen_scene
            data:
              value: "{{ option }}"

A dropdown helper named “Kitchen Scenes”
A text helper named “selected_kitchen_scene”

Is this right?

Please format your code block properly so we can see if there are issues.

Thanks, edited above.

That looks fine except for two minor things…

This configuration creates it’s own entity (select.kitchen_scenes), you do not need the dropdown/Input select Helper.

You don’t need to define the entity variable if you aren’t using the scene.turn_on function included in the original example.