Mapping JSON Output from True to Closed

Hi I have a door sensor that outputs as True or false. I am trying to remap the output so instead of true it outputs this as CLOSED and false as OPEN. This is aqara window/door sensor using the zigbee2mqtt gateway.

Sensor info in configuration.yaml

  • platform: “mqtt”
    state_topic: “zigbee2mqtt/0x00300d000104baba”
    name: ‘Front Door’
    availability_topic: “zigbee2mqtt/bridge/state”
    payload_on: false
    payload_off: true
    value_template: “{{ value_json.contact}}”
    json_attributes:
    • “battery”
- platform: template
  sensors:
    the_front_door:
      friendly_name: "Jamos' Front Door"
      entity_id:
        - sensor.front_door
      value_template: >- 
        {% if is_state('sensor.front_door', 'true') %}
          Closed
        {% else %}
          Open
        {% endif %}

Use sensor.the_front_door to display the mapped version.

Thanks Florian, That solved it. Much appreciated.

1 Like