I have a folder sensor which is populated with folder names.
In a Lovelace card I want to select one of these folder names from a pull-down - I use an input_text to make this selection.
I have an automation which I think is almost there but I cannot get it working.
alias: Play Pop Modern
description: ''
trigger:
- platform: state
entity_id: input_text.folderlist2
domain: ''
entity_id: ''
condition: []
action:
- service: input_select.set_value
data_template:
entity_id: input_select.folderlist2
value:
- Select
- '{{ states("input_text.folderlist2") | replace(states.sensor.pop_modern.attributes.file_list) | replace(states.sensor.pop_modern.attributes.path, '/') }}'
mode: single
I have followed structures shown in other posts but always get an error whether I use an input_text and value or an input_select and option Message malformed: extra keys not allowed @ data['action'][0]['target']['options']
The automation aims to populate the input_select (or input_text) with the selected item from the pull-down.
value is not the correct option name for an input_select.set_options service call. If you refer to the documentation, youâll see itâs options.
FWIW, the documentation doesnât include any examples where one of the options is templated. That might just be an omission or an indication itâs not supported. Letâs hope itâs the former.
You should also be aware that whatever options you set will only last until a restart and then they revert to the default values.
Yeah, thatâs why I need to see the result of the first template to understand whatâs contained in the attribute. Itâs a list, but Iâd like to see an example of its contents. I think in order to strip out the path, it will need to iterate through the listâs items.
For the input_select.set_options service call, the value assigned to options must be a list. I donât believe the combination of YAML and template you have there is understood to be a list. The line continuation character (>-) immediately tells the YAML processor that the rest is a Jinja2 template. That means the hyphen becomes part of the templateâs result as opposed to being handled by the YAML processor as a list item.
The template in your second example is missing outer quotes.
but it is not updating the input_select state and so the input_text state does not get a value set.
Should I be using a template for the trigger instead of a change of state? Please excuse these noob stumbles.
EDIT: Just found this: Invalid state encountered for entity ID: input_select.folderlist2. State max length is 255 characters.
I have heaps more than 255 chars. Looks like I need to find a work-around.
Same mistake as described in my previous post (itâs not supplying the input_selectâs options with a valid list).
The state value of all entities is restricted to a maximum length of 255 characters (and its type is always string). This constraint doesnât exist for an entityâs attributes. However, assigning data to an entityâs attributes is more challenging because thereâs no service call to do that. Itâs typically done via the entityâs configuration. For example, in the case of a Template Sensor via its attributes option and via json_attributes_template for an MQTT Sensor.
I believe you will need to step back and rethink how you want to achieve your goal.
I donât think itâs entirely hopeless. I performed a simple experiment to set an input_selectâs options and was successful. The key is how you present the data to options (as mentioned previously, your example doesnât present it as a valid list).
I was struggling with this for quite some time and now, based of @Taras post I revisited this and can confirm that it works! Here is my automation code:
So basically it looks at media_player.volumio available playlists, that are stored as source_list attribute, convert this to jinja list and loads into input_select.playlists.
Definitely something changed, as in the past HA versions it was not possible to create jinja list from template.
Thatâs true; in the past the output of a template was always handled as a string. When support for ânative typesâ was introduced (last November in version 0.118), the type of the templateâs output is inferred from its appearance (i.e. is if looks like a list, its type becomes list).
BTW, you automation uses a time_pattern trigger to set the input_selectâs options every minute. Wouldnât it be more efficient to use a State Trigger that monitorâs the media_playerâs source_list attribute? In other words, it would trigger only if the source_listâs contents change.
Perhaps yes! That was very quickly created automation, just to check how it works. Even updating it every minute does not make sense, since based on experience I create maybe 1 playlist per month
In reality Iâll now need to move this concept from Volumio (that Iâm phasing out) to new HEOS integration for my new, just installed marantz. So Iâll need to dig more into this. To be honest at this stage Iâm not even sure how to make it working with HEAS, as at the moment it does not provide proper source_list - only physical inputs (that anyhow Iâd filter out for this purpose) and is not showing favorites not play lists⌠But this is clealry HEOS issue.
Anyhow it is excellent idea let changes of attribute trigger updates rather than force updates by timer!