Mqtt switch with state from sensor

i want to create an mqtt switch which would get the state from a contactsensor.

this is what i have, but i’m not sure what to set for the state topic.

which is provided by a sensor and has this payload
{"battery":86,"contact":true,"linkquality":47,"voltage":2975}
obviously if contact = true, the door is closed, so switch should be OFF

but this doesn’t work, otherwise i won’t be here… any suggestions?

switch:
  - platform: mqtt
    unique_id: garagedoor_switch
    name: "Garagedoor Switch"
    state_topic: "zigbee2mqtt/GarageDeur"
    command_topic: "home/garagedoor/switch/set"
    payload_on: "OPEN"
    payload_off: "CLOSE"
    state_off: "contact"
    optimistic: false
    qos: 0
    retain: true

First of all, you don’t want to set ‘retain: true’ in your HA definition, that retains the command, not the state !

try :

switch:
  - platform: mqtt
    unique_id: garagedoor_switch
    name: "Garagedoor Switch"
    state_topic: "zigbee2mqtt/GarageDeur"
    command_topic: "home/garagedoor/switch/set"
    payload_on: "OPEN"
    payload_off: "CLOSE"
    value_template: >- 
      {% if value_json.contact == 'true' %}
        {{'ON'}}
      {% else %}
        {{'OFF'}}
      {% endif %}
    optimistic: false
    qos: 0