MQTT Command as switch - Tasmota

Hello all

I’m trying to make a switch out of a MQTT command to enable/disable the use of a physical switch on a Shelly1.

My Example:
Doorbell is wired into shelly 1. I have tasmota on it. I want to be able to turn on/off the use of the doorbell.

SwitchMode does this (0 makes the doorbell usable, 15 makes it disabled but still sends a MQTT request)

I would like to make a switch in HA that shows when the doorbell is enabled or disabled.

I’ve tried to set it myself but I think I messed up somehow. Basically the switch needs to show as “ON” when SwitchMode is at 0, and “OFF” when it’s at 15. Is this possible? I posted what I’ve been trying below but it’s clearly not right.

Help?
Massive thanks in advance <3

  - platform: mqtt
    unique_id: doorbell_switch
    name: "Doorbell Switch"
    state_topic: "stat/tasmota_78273E/RESULT"
    command_topic: "stat/tasmota_78273E/RESULT"
    availability:
      - topic: "stat/tasmota_78273E/RESULT"
    payload_on: '{"SwitchMode":"0"}'
    payload_off: '{"SwitchMode":"15"}'
    state_on: "ON"
    state_off: "OFF"
    optimistic: false
    qos: 0
    retain: 

You probably need something like this:

  - platform: mqtt
    unique_id: doorbell_switch
    name: "Doorbell Switch"
    state_topic: "stat/tasmota_78273E/RESULT"
    command_topic: "cmnd/tasmota_78273E/SWITCHMODE"
    availability:
      - topic: "tele/tasmota_78273E/LWT"
    payload_on: 0
    payload_off: 15
    value_template: >-
      {% if value_json.SwitchMode1 is defined %}
        {{ 'on' if value_json.SwitchMode1 == 0 else 'off' }}
      {% else %}
        {{ states('switch.doorbell_switch') }}
      {% endif %}
    state_on: 'on'
    state_off: 'off'

The complex value_template is needed because the stat/tasmota_78273E/RESULT topic will contain other messages that do not have the SwitchMode1 key.
I haven’t tested any of this. You could try simplifying the value_template, but I think you’ll get error messages in your log.