Cycle hue bridge scenes with a remote

I am trying to cycle between hue bridge defined scenes using a remote.

Scene names are defined as an ‘input select’ list and the remote buttons call ‘input_select.select_next’ and ‘hue.hue_activate_scene’ service (passing the selected ‘scene_name’). This is working great but…

Is there a way to populate the ‘input select’ option list with all the scenes on the hue bridge instead of defining them manually?

Example input select list options defined manually thats working now:

  name: Hue scenes
    - Scene1
    - Scene2
    - Scene3

Yes, but not with a script; you would need something else, like a python_script.

If using a script, the limitation you will encounter is that a Jinja2 template always produces a string. So even if it generates something that looks like a list:

["scene1", "scene2", "scene3"]

it’s actually a string.

If you use the input_select.set_options service call, it expects a list for the options parameter and a template can’t dynamically produce one containing a variable number of items (i.e. there’s a way to use a template to create a list with a fixed number of items).

For example, the following script appears to do everything correctly, but ultimately the template produces a string (that only looks like a list, but isn’t). The result is that input_select.items is assigned a single option containing the names of all the selected scenes.

Example (this will NOT work as desired):

    alias: 'Set input_select options'
      - service: input_select.set_options
          entity_id: input_select.items
          options: "{{ states.scene | selectattr('attributes.something', 'eq', 'whatever') | map(attribute='name') | list ) }}"

In contrast, a python_script uses python code to generate a real list (even containing a variable number of items). It could then call input_select.set_options and assign the list to the options parameter.

Thanks for your reply.
I am looking at python scripts right now since there is no way to produce lists with Jinja2 templates.
Calling input_select.set_options seems to be a great way to populate the option list.

How can I get hue scene list from hue bridge? Did it on a standalone python script using phue library hardcoding bridge IP and token but would like to use home assistant’s own hue bridge connection instead.

That’s the first challenge because the Philips Hue integration does not reveal Hue scenes as Home Assistant scenes. From here:

To avoid user interface overload, we don’t expose scenes directly. Instead there is a hue.hue_activate_scene service which can be used in an automation or script

Therefore, the external Python script you have created to query the bridge, for a list of its scenes, may need to be enhanced to also set the input_select’s options. Perhaps it can use Home Assistant’s REST API to call the input_select.set_options service.

API Service call

curl -X POST -H "Authorization: Bearer ABCDEFGH" \
       -H "Content-Type: application/json" \
       -d '{"entity_id": "input_select.whatever", "options": ["scene1", "scene2"]}' \

Thank you so much, Taras.

Was able to do a simple post request using http.client on the external Python script and send the fetched Hue scenes.
Then assigning it to a shell_command and launching it at HA startup automation.

Would really like something better HA integrated but at least is working great now :slight_smile:

1 Like

You’re welcome! Glad to hear the API call helped to resolve it.

I would appreciate it if you could do two things:

  1. Mark my previous post with the Solution tag so that others know this issue has been resolved. A check-mark will be automatically placed next to the topic’s title. Anyone else who has a similar problem will now know they need to use an external Python script to resolve it.
  2. Only if you are willing to share, please post the script you created so that others know how to implement the solution. Redact any personal information in the code.

No problem with sharing the script, but the code is so messy (list is iterated 3 times!). If I get it refactored I will post it here (or if some user requests it) :slight_smile: