Setting up Xiaomi Vibration Sensor using Zigbee2mqtt

Using the knowledge gained here by going through various topics on Zigbee2mqtt and Xiaomi Aqara devieces, I am able to configure a Xiaomi Aqara Vibration sensor, attached it to postbox for following purposes:

  • To know via notification when there is new post arrrived in postobox and also display the new post info on UI using sitemap
  • To know via notification when post is collected and also display this info on UI using sitemap.

I’m using Zigbee2MQTT (https://koenkk.github.io/zigbee2mqtt/ ) to bridge Aqara sensors to MQTT and bind them to things and items in OpenHAB 2.5.3-1.

Currently I’m using following Xiaomi Aqara devices

  • motion sensors
  • contact sensors
  • vibration sensors

xiaomivib.things

Thing topic postboxvib "Postbox" (mqtt:broker:mosquitto) @ "Xiaomi" {
      Channels:
          Type number : battery           [ stateTopic="zigbee2mqtt/postboxvib", transformationPattern="JSONPATH:$.battery" ]
          Type number : voltage           [ stateTopic="zigbee2mqtt/postboxvib", transformationPattern="JSONPATH:$.voltage" ]
          Type number : linkquality       [ stateTopic="zigbee2mqtt/postboxvib", transformationPattern="JSONPATH:$.linkquality" ]
          Type number : angle             [ stateTopic="zigbee2mqtt/postboxvib", transformationPattern="JSONPATH:$.angle" ]
          Type number : angle_x           [ stateTopic="zigbee2mqtt/postboxvib", transformationPattern="JSONPATH:$.angle_x" ]
          Type number : angle_y           [ stateTopic="zigbee2mqtt/postboxvib", transformationPattern="JSONPATH:$.angle_y" ]
          Type number : angle_z           [ stateTopic="zigbee2mqtt/postboxvib", transformationPattern="JSONPATH:$.angle_z" ]
          Type number : angle_x_absolute  [ stateTopic="zigbee2mqtt/postboxvib", transformationPattern="JSONPATH:$.angle_x_absolute" ]
          Type number : angle_y_absolute  [ stateTopic="zigbee2mqtt/postboxvib", transformationPattern="JSONPATH:$.angle_y_absolute" ]
          Type number : strength          [ stateTopic="zigbee2mqtt/postboxvib", transformationPattern="JSONPATH:$.strength" ]
          Type string : action            [ stateTopic="zigbee2mqtt/postboxvib", transformationPattern="JSONPATH:$.action" ]
    }

xiaomivib.items

    //Vibation sesnor Items
    Number  postboxvib_battery           "Battery Strength [%.1f %%]" <battery> {channel="mqtt:broker:mosquitto:postboxvib:battery"}
    Number  postboxvib_voltage           "Volt Signal [%d mV]" {channel="mqtt:broker:mosquitto:postboxvib:voltage"}
    Number  postboxvib_linkquality       "Link Quality [%d]"  {channel="mqtt:broker:mosquitto:postboxvib:linkquality"}
    Number  postboxvib_angle             "Angle [%d]"      {channel="mqtt:broker:mosquitto:postboxvib:angle"}
    Number  postboxvib_angle_x           "Angle X [%d]"    {channel="mqtt:broker:mosquitto:postboxvib:angle_x"}
    Number  postboxvib_angle_y           "Angle Y [%d]"    {channel="mqtt:broker:mosquitto:postboxvib:angle_y"}
    Number  postboxvib_angle_z           "Angle Z [%d]"    {channel="mqtt:broker:mosquitto:postboxvib:angle_z"}
    Number  postboxvib_angle_x_absolute  "Absolute X [%d]" {channel="mqtt:broker:mosquitto:postboxvib:angle_x_absolute"}
    Number  postboxvib_angle_y_absolute  "Absolute Y [%d]" {channel="mqtt:broker:mosquitto:postboxvib:angle_y_absolute"}
    Number  postboxvib_strength          "Strength [%d]"   {channel="mqtt:broker:mosquitto:postboxvib:strength"}
    String  postboxvib_action            "Action [%s]"     {channel="mqtt:broker:mosquitto:postboxvib:action"}

2 dummy items were created to control the display of messages on UI using sitemaps:

dummy.items

String postin  "[%s]" <returnpipe>
String postout "[%s]" <flowpipe>

Sitemap has following entries:
myhome.sitemaps

    Frame label="Postbox" {
        Default item=postin visibility=[postboxvib_action=="vibration", postboxvib_action=="drop"] icon="returnpipe"
        Default item=postout visibility=[postboxvib_action=="tilt"] icon="flowpipe"

To get the notification of post arrival and removal, following rules have been implemented:
postbox.rules

rule "PostboxAction"
when
    Item postboxvib_action changed
then
    if(postboxvib_action.state=="vibration") {
            sendNotification("xyz@web.de", "Post to Collect !!")
            postin.postUpdate("New Post arrived @ " + now.toString("dd-MM-yyyy HH:mm:ss") + " !!")
    }
    if(postboxvib_action.state=="drop") {
            sendNotification("xyz@web.de", "Post to Collect !!")
            postin.postUpdate("New Post arrived @ " + now.toString("dd-MM-yyyy HH:mm:ss") + " !!")
    }
    if(postboxvib_action.state=="tilt") {
            sendNotification("xyz@web.de", "Post Collected !!")
            postout.postUpdate("Post Collected @ " + now.toString("dd-MM-yyyy HH:mm:ss") + ".")
    }
end

Best regards, Sukkhi

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.