I successfully use an input_select and an automation to pick a value of 0, 1 or 2 in the input_select in the GUI and send that value as the payload of an MQTT message. I have a 2nd automation updates the input_select when HA sees a new value appear inbound on that same MQTT topic. Thats all working fine.
What I’d like to do is put text in the input_select like “Red”, “Green” etc and when they are selected, convert them to an integer say 0 or 1 or 2 etc and send that out over the MQTT topic. And vice versa, if HA sees an integer update inbound on the MQTT topic it will update the input_select to the correct text.
I have been trying various templates, but I can’t get my head around what I need to do. Any ideas?
Here is the original input_select and the new one I’m working on.
pj_office_leds_dynamic_pattern_sub_mode:
name: PJ Office LEDs Dynamic Pattern Sub Mode (dev231)
options:
- "1"
- "2"
- "3"
- "4"
initial: "1"
icon: mdi:flashlight:
pj_office_leds_dynamic_pattern_sub_mode:
name: PJ Office LEDs Dynamic Pattern Sub Mode (dev231)
options:
- "Black"
- "Red"
- "Green"
- "Blue"
initial: "Black"
icon: mdi:flash
Here are my two automations that work with the integer based input_select but need to be modified to work with the text based input_select.
- alias: Sync PJ Office LEDs Dynamic Pattern Sub Mode Selector
trigger:
platform: mqtt
topic: "home/rfm_gw/nb/node03/dev231"
action:
service: input_select.select_option
data_template:
entity_id: input_select.pj_office_leds_dynamic_pattern_sub_mode
option: '{{ trigger.payload }}'
- alias: Set PJ Office LEDs Dynamic Pattern Sub Mode
trigger:
platform: state
entity_id: input_select.pj_office_leds_dynamic_pattern_sub_mode
action:
service: mqtt.publish
data_template:
topic: "home/rfm_gw/sb/node03/dev231"
retain: true
payload: '{{ states.input_select.pj_office_leds_dynamic_pattern_sub_mode.state }}'