I have a system to control some outside lights that use a MQTT topic to turn on the lights and another, different, topic to turn them off. There is a binary sensor that indicates whether the light group is on or off.
I want to create a switch that sends one or the other of these MQTT messages and uses the binary sensor to feed back the state.
A “standard” MQTT switch doesn’t work since I need to send different topics for on and off, not just different payloads. (At least I don’t know how it could be done if it is possible!)
I tried a template switch like this:
switch:
- platform: template
switches:
eveninglights:
value_template: "{{ is_state('binary_sensor.evening_lights_on', 'on') }}"
turn_on:
service: mqtt.publish
service_data:
topic: cmnd/OusideLightsOn/POWER
payload: Run
target: {}
turn_off:
service: mqtt.publish
service_data:
topic: cmnd/OusideLightsOff/POWER
payload: Run
target: {}
But this gives me:
Invalid config for [switch.template]: [service_data] is an invalid option for [switch.template].
Check: switch.template->switches->eveninglights->turn_on->0->service_data. (See ?, line ?).
Any suggestions on how to solve my issue (using a template switch, or any other ways.)
I’m somewhat new to HA, and haven’t found anything by searching here and in general on the web.
Thanks!