I’m attempting to set the topic to publish to, based on an input_select and an array (see code below)
The script however does not work, complaining about the topic not being in the dictionary.
service: mqtt.publish
data_template:
topic: >
{% set mqttTopicsMap = { 'Humidifier' : 'home/Bedroom/Humidifier/cmnd/teleperiod',
'Bathroom' : 'home/Bathroom/Bathroom/cmnd/teleperiod',
'ChrismasTree' : 'home/Livingroom/ChristmasTree/cmnd/teleperiod',
'Spare-Plug' : 'home/unassigned/Spare-Plug/cmnd/teleperiod'} %}
{% set targetSwitch = states('input_select.tasmota_switch') | lower %}
{{ mqttTopicsMap[targetSwitch] }}
payload: >
{{ states('input_number.mqtt_tasmota_update_interval') | int }}