MQTT Switch Discovery - Config Payload Help

Hello,

I’m writing something in Python to run on my FreePBX server to allow me, initially, to switch DND state from Home Assistant.

I’ve got everything working up to the MQTT Discovery payload for the switch. I’ve had a search of the forums, reddit and google but haven’t found anything that helps - there are lots of topics about sensors but not so many about switches, and those that are about switches seem to be for optimistic mode but I’m after something more reliable by using availability reports and a separate state topic.

Here is the latest attempt at a discovery payload that doesn’t work. I have also tried the availability as a list containing the dictionary. Can anyone help fix it, or at lease provide a blank payload that I can work with - the MQTT Discovery integration page lists all the required keys but doesn’t show the format.

{
    "name": "Fred Mobile Phone DND",
    "state_topic": "pbx2mqtt/041802/dnd/stat",
    "device": {
        "mf": "pbx2mqtt",
        "ids": [
            "137506819392943"
        ],
        "name": "PBX",
        "version": "v0.0.1"
    },
    "command_topic": "pbx2mqtt/041802/dnd/cmd",
    "availability": {
        "topic": "pbx2mqtt/avty",
        "payload_available": "online",
        "payload_not_available": "offline"
    },
    "unique_id": "041802dnd",
    "icon": "mdi:phone",
    "state_on": "on",
    "state_off": "off",
    "payload_on": "on",
    "payload_off": "off"
}

Thanks for your time
Fred