How to do a Switch with different MQTT topics for on and off

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!

Try:

switch:
  - platform: template
    switches:
      eveninglights:
        value_template: "{{ is_state('binary_sensor.evening_lights_on', 'on') }}"
        turn_on:
          service: mqtt.publish
          data:
            topic: 'cmnd/OusideLightsOn/POWER'
            payload: 'Run'
        turn_off:
          service: mqtt.publish
          data:
            topic: 'cmnd/OusideLightsOff/POWER'
            payload: 'Run'

@francisp - That does it! Thanks!
Not sure why the qoutes are needed here - for a button, I used the GUI editor, but it showed as yaml code this:

type: button
tap_action:
  action: call-service
  service: mqtt.publish
  service_data:
    topic: cmnd/ToggleGarageDoor1/POWER
    payload: Run
  target: {}
entity: binary_sensor.ib_5_door1
icon_height: 50px
name: Ron's Garage Door
show_state: true

I just copied part of that over, which didn’t have the quotes. Gotta love this syntax.

I really don’t know if the quotes are needed. It is just I have always used them in mqtt template switches.

Maybe more likely just the service_data: vs data:. Seems inconsistant if so though. BUT it works, so I’m happy! Thanks again.