hello
i hope i posted this in the right section.
im trying to make the command template for a mqtt select option, but i need it to just return the index of the select option i choose instead of the “value”, is this possible?
thanks
hello
i hope i posted this in the right section.
im trying to make the command template for a mqtt select option, but i need it to just return the index of the select option i choose instead of the “value”, is this possible?
thanks
i think i figured it out, idk if there is a better/easier way, but if anyone else needs it:
(note that this is also packed as a bytes object)
"cmd_tpl": "{{ this.attributes.options.index(value) | pack('B') }}"
Hey, i have the same questions regarding a command template for a MQTT select entity .
HA should send only the number and not the option name for the command, so I probably need a command template. I saw this post, which is exactly what I need, but it does not work even not in the ha dev-tool:
{{state_attr(‘select.micron_mode_select_micron’, ‘options.index(value)’) }}
results in “None”
{{states(‘select.micron_mode_select_micron.attributes.options.index(value)’) }}
results in “unknown”
{{state_attr(‘select.micron_mode_select_micron’,‘options’) }}
works and prints me all options.
Hey, I found the problem. the value needs to be the state.
{{state_attr(‘select.micron_mode_select_micron’,‘options’).index(states(‘select.micron_mode_select_micron’)) }}
because I’m using mqtt discovery, it is of course easier to you use “this”:
{{state_attr(‘this’,‘options’).index(states(‘this’)) }}
@Halvhjearne
I think you could set this topic regarding “MQTT Select” to solved
Here is a similar topic regarding template for mqtt select options
These attr options are really nice and helped me a lot: