Xiaomi aqara vibration sensor binary sensor versus last state attribute

I just started out with a few xiaomi sensors including one of their vibration sensors. It seems a little different from other sensors I have encountered. I was wondering if somebody who has used it can fill me in on the best way to use it in automatons. Ive done alot of googling and found some stuff on this forum and github. I guess my first question is the binary sensor that is automatically added to the front end supposed to work. When I look on the states page there is a last_action attribute which changes to tilt,vibrate,or free-fall depending on what I do with it. I think the state returns the angle of deflection but for example when vibrate is shown the state is set to off. From what I’m reading there is no attribute shown for not_vibrate so there is no way to tell if vibration has stopped. Is this correct or is my info dated? It seems that it is difficult to use these attributes to determine if vibration has stopped. I was hoping that the binary sensor might be on with vibration and then off when no vibration but this does not seem to be the case.

If this is true how are people working around this. I assume some kind of rechecking must occur. Has anybody been able to come up with a template that can show on and off vibration? I’m not sure how often the actual sensor returns a new value either sometimes it seems to quickly react? Dropping the sensor from one hand to the other always seems to change the last_action to free fall but then trying to get it to switch to vibration seems like it takes awhile.

Any helpful info would be nice. Thanks

Hi,

This sensor dont work like all the others so “state” is not that useful as it is more “event” oriented. In this thread there are a few sugestions on how to use it. I guess it’s possible to derive a vibration sensor from it using a template sensor and the same approach we do for those pir sensors that dont send a “no movement”. You turn the sensor “on” when you see the vibration event, and then use “delay_off” to turn it off. hm… I have to try, but shouldnt be too difficult.

Replying to myself… it seem that the component has changed since the last time I checked and now there’s a bed activity/tilt/orientation/vibration sensor.

Try this:

binary_sensor:
  - platform: mqtt
    name: vibracao
    state_topic: "home-assistant/test/vibration"
    payload_on: "ON"
    off_delay: 30


automation:
  - alias: Detect vibration
    trigger:
      platform: event
      event_type: xiaomi_aqara.movement
      event_data:
        entity_id: binary_sensor.vibration_xxxxxx
        movement_type: vibrate
    action:
     - service: mqtt.publish
       data:
         topic: "home-assistant/test/vibration"
         payload: "ON"

Not perfect, but it’s a start :slight_smile:

1 Like

Thanks very much for your reply. It looks like you are using zigbee2mqtt. I’ve looked at setting that up but for now I’m using the xiaomi gateway. Am I right to say from your example that if the sensors starts to vibrate then you will know but you will not know if the vibration stops? Is there a way to work around this? Do you think the binary sensor is supposed to show on at any time

I went back and re-read the documentation more carefully. The binary sensor will always remain off. It definitely makes it more of a challenge for me to use it in an automation where I would like to know the beginning and end of a vibration occurrence. Is there some way to keep checking if vibration is occurring without constantly checking and wasting resources.It looks like in the MI app that each vibration event is logged so is it possible somehow to determine that vibration has stopped using a timestamp in home assistant. Sort of “if another vibration update is not sent in X amount of time than vibration must have stopped” situation. Some other sensors are created with this hardware, like bed activity. I’m not sure if this can be utilized for this purpose using an above a certain number would represent vibration and below no vibration so ill give that a shot.
These things look still fairly new so I hope more experienced HASS’rs get there hands on them and will share their configs

Hi,

Well… first thing we have to do is to discover how long it take from one vibration event to another. Xiaomi movement sensor sleeps for 2 minutes after detecting movement. I think the off_delay should take care of the event updates (have to check…) as long we use a value larger than two event updates.

btw, I’m using the xiaomi gateway. The MQTT sensor was used to a create our virtual sensor.

I think I saw your name come up in another thread where you mentioned that you had sniffed some packets for this sensor so I’m thinking you know what your doing :wink: . 2 minutes seems long? I could have sworn I could tap around the sensor and get indications in the mi app quicker than 2 minutes? 2 minutes wouldn’t be too long a lag time I suppose though. I’ll go back through your post and see if I can figure out your sensor. I’m not that familiar with mqtt. I have two switches running with mqtt to start to understand it. I’ll have to look at this when I’m done working my nights

@clyra
I think I’ve learned a bit more about mqtt but I’m not sure how you would use that to get around the problem of the sensor not reporting when activity stops. I would have thought and have tried basing automation’s on the bed activity sensor but haven’t really had success.
Im trying to use it on a dryer but as you can see although it picks up motion initially it tends to show motion long after the motion has stopped.

As you can see last state sensor showing vibration is even less useful for this type of automation. I was not drying close for all those hours lol

the vibrate_sensor_action is the mqtt binary_sensor?

The vibrate sensor in the picture is available in my front end. I understand you can make a binary sensor out of just about anything but from what I can tell the sensors don’t seem to change state to off only a different movement state. The vibration sensor seems to just seem show changes of state but never to off so you will see vibration—>freefall(if you drop it)—> then vibration again(if you shake it) but not to off. So unless my dryer is going to fall over when its done I dont know how I can automate off this using a binary or not? Maybe I’m missing what your trying to tell me

Hi,

What I’m trying to tell you is that you cant rely on the vibrate sensor only, as it does not exactly report “state” but “events”. So the idea is to use a template/mqtt sensor that change its state on a “vibrate” event and after a while turn its off because it didnt saw another vibrate sensor. That is what my example try to do :-).

Gotcha. Ya I guess I could give it a try but what I’m seeing from the front end sensors doesn’t look encouraging

People seem to be using power consumption aware plugs to track the completion of the washing machine cycle.

Yes I’ve done that with the washer already. The dryer however though uses a higher amperage special services plugin. Alteratively I have contemplated using a temperature sensor on the exhaust hose and perhaps a trend up and down sensor but the vibration sensor seemed like it might work. I think it might using a diy zigbee2mqtt setup

Wow. Out of interest, why do you need to know that it has finished?

1 Like

Have you found a solution?

Sorry no. Not with the xiaomi motion sensor. It’s unfortunate bc when I installed the aquara app it would report repeat vibration occurrences so it seems like the sensor could be used in some way for home assistant so that after it reports vibration that it would check every so often and report when it stopped. I’m leaning more towards the temp sensor on the dryer exhaust hose

Ok thanks a lot for your reply!!! :smiley:

Hi all, I have one of those aqara vibration sensor, using it with zigbee2mqtt, I see for example these attributes:
angle x, angle y, angle z ,angle x absolute, angle y absolute, linkquality, unknown data, battery, voltage, angle
I was wondering in which way I can use it to determine if the garage door is open or not, using someone of the angle attributes; also a template for displaying a garage icon open or closed following the value, I read something but very few information for this sensor used in home assistant.
Thank you for the help.