Zigbee2mqtt - Xiaomi Door Sensor

Has anyone automated a script when a xiaomi door sensor is open through Zigbee2mqtt

i’m trying to get an easy example to work at this stage - then I want to add conditions

  • alias: Living Switch Test
    trigger:

    • platform: mqtt
      topic: ‘zigbee2mqtt/living_room__door_sensor’

    action:

    • service_template: >
      {% if trigger.payload_json.contact == ‘false’ %}
      script.kettle_on

      {% endif %}

doesn’t seem to work - I’ve managed to get xiaomi wireless switch to work. Now for the door sensor.

Haven’t tested a door sensor, but the temp sensor from xiaomi and a switch and a lamp from IKEA when connected to zigbee2mqtt, they actually create a device in home assistant. So you can directly check the device instead of mqtt messages. For eg. the temp sensor in mine is sensor.0x00158d00036b744d_temperature.
In trigger i would put the sensor instead of the topic and check its’ state.

And here’s an automation eg. which I take data from a IKEA button and trigger a lamp. Both are zigbee2mqtt devices.

- id: ButtonLight
  alias: Turn on stairlight when button is pressed
  trigger:
  - platform: state
    entity_id: sensor.0x000d6ffffe1f896f_action
    to: toggle
  action:
  - service: light.toggle
    entity_id: light.0x000b57fffe9151b8_light

If you find out what your entities are named you just replace the entity_id and the to: to what the message is sent when the sensor triggers, On the action you just put service: script.turn_on and entity_id: script.kettle_on. This way it will only trigger when the sensor triggers open