Aqara tilt sensor tracking garage door zigbee2mqtt

Hey everyone,

I am attempting to use an Aqara Tilt Sensor to track when my garage door opens and closes. I would like to have a separate entity (aka binary_sensor) that has the current state of the Garage Door (Open, Closed).

How do I go about creating a trigger event (for zigbee2mqtt) so that when the Tilt sensor z state > X my binary_sensor sets itself to Open and when its <= X it set itself to closed?

I can find various posts on how to do this with ZHA, but not with zigbee2mqtt.

I know there is probably a couple different options here, I have tried a few , but haven’t been able to get it working yet.

When you say ‘tilt sensor’ are you referring to the Aqara Vibration Sensor (DJT11LM) which is only useful as a tilt sensor?

Did you see the example for the trigger in this thread?

I tried to use the tilt functionality to detect, if my garage door is open, opening, closing, or closed but did not react quickly enough for my use case.

Yes, the DJT11LM. That example looks just about what I want, but the “action” I want that numeric_state to do is set another entity to Open or Closed. So for example I can create a card on the homepage to view the garage status at all times.

Template binary_sensor triggered by the Z2M event?

So, you create the ‘other entity’ as a helper, e.g. a binary sensor/toggle, and use the trigger to switch it on and off. You can then display the binary_sensor e.g. in a glance card that can automatically color the icon according to the on/off/ status.

Or you can use a template to define a binary sensor to achieve the status change and then show the state in a card - this is how I show it in a custom button card:

type: custom:button-card
show_entity_picture: true
  - value: Open
    icon: mdi:garage-open
    color: red
  - value: Closed
    icon: mdi:garage-lock
    color: green
  - value: Opening
    icon: mdi:garage-alert
    color: orange
  - value: Closing
    icon: mdi:garage-alert
    color: orange
  action: call-service
  service: input_text.set_value
    value: Closed
    entity_id: input_text.garage_door_status
entity: input_text.garage_door_status
show_state: false
show_label: true
name: Garage is
size: 40%
label: |
    if (states['input_text.garage_door_status'].state === "Closed")
      return "closed";
    else if (states['input_text.garage_door_status'].state === "Opening")
      return "opening";
    else if (states['input_text.garage_door_status'].state === "Closing")
      return "closing";
    else if (states['input_text.garage_door_status'].state === "Open")
      return "open";

image image image image

Note that the last bit for the label is only to convert the upper case state info to the lower case in the button - mine is obviously NOT a real binary sensor because I want/need to show the opening and closing states as well.