Hello good people,
I am new to HA and I want to have a select list that gets updated dynamically and it seems the only way to do that is with a template. However, I am struggling a bit with some of the jinja syntax and I am unsure where to find the documentation to help clear it up.
Essentially, I am trying to create a template that creates a select list of all the Phillips Hue scenes that get automatically created in a given room so that I can then use something like a bubble card select list to choose them.
As an example, one of the rooms is Sunroom and the Hue integration creates scenes like scene.sunroom_artic_aurora (name: Arctic aurora) or scene.sunroom_bright (name: Bright)
Because Hue uses the same name like âBrightâ for scenes in multiple rooms, I needed to be able to limit the list to a given room but not show the name of the room in the list as it is redundant. I came up with this for listing the options and it works how I want it but was put together from other examples people posted:
options: {{ states.scene | selectattr('entity_id','search','sunroom')| map(attribute='name') | list | replace("Sunroom ","") }}
Now, the trouble comes in when I am trying to set up the target entity ID. My main problem is that I donât understand what the different filters specifically do for selectattr.
Iâve seen examples that say:
selectattr('entity_id','search',option)
or others that say:
selectattr('name', 'eq' , option)
and others but where is the documentation that says what âsearchâ or âeqâ actually does? I looked on the jinja doc page and the templating page and saw some references to regex filtering but nothing that explicitly gave the list of those options, their syntax, and what exactly they do. Am I blind?
I thought maybe I had cracked it with the following:
entity_id: "{{ states.scene | selectattr('entity_id','search','sunroom') | selectattr('name', 'eq' , option) | map(attribute='entity_id') | list | first}}"
but it throws the following error
âFailed to perform the action select/select_option. not a valid value for dictionary value @ data[âentity_idâ]â
and I canât find any way in the template editor in dev tools to test me selecting something to see what the value of âoptionâ is or the then-resulting entity_id would be.
Beyond that, if I need to concatenate the name of the room with the name attribute to come up with an entity ID, can I even do that?
Any help anyone could provide would be most appreciated.