Toggle Button to switch between 2 mqtt payloads

Hi Folks,

I am trying to set up a toggle switch that will publish a 1 to a MQTT topic when turned on or a 0 when turned off.
Currently I have 2 seperate buttons on my dashboard. These are the standard button cards with this code -

show_name: true
show_icon: true
type: button
tap_action:
  action: call-service
  service: mqtt.publish
  data:
    topic: homeassistant/arduino17/switch
    payload: '1'
  target: {}
name: 'On'

This works as it should. The builtin LED on my ESP board turns off or on when I hit the off or on button but I am now trying to add a toggle button that shows which state it is in with the off / on functionality in one place. I am not using ESPEasy or anything similar, just plain C++ coded ESP modules.

I have had a good browse through the forums as I feel this is a pretty basic function but I couldn’t find how to amend the above code to change it to a toggle button along with doing the corresponding mqtt.publish

I have tried installing the Lovelace custom button cards but this seemed like a complex way of changing 2 push buttons into 1 toggle button.

MQTT Switch - Home Assistant looks like what I am after. I modified their example to the below and stuck in my configuration.yaml

mqtt:
  switch:
    - unique_id: arduino17switch
      name: "Arduino Switch"
      state_topic: "homeassistant/arduino17/switch"
      command_topic: "homeassistant/arduino17/switch/set"
      availability:
        - topic: "homeassistant/arduino17/switch/available"
      payload_on: "1"
      payload_off: "0"
      state_on: "1"
      state_off: "0"
      optimistic: false
      qos: 0
      retain: true

Back to dashboard and added a card, filtered by entity and added the ‘Arduino Switch’ with the provided suggestion of the toggle button. This is added but is greyed out and inoperable.

Any help on what I’m missing or a link to something I should be reading would be appreciated!

Got this cracked. Think the availability part was greying out the switch. Removed it and removed the /set from the end of the command topic