Issues with Xiaomi Vibration Sensor

Hi there :slight_smile:

I’m having some (i think) issues with the integration of the Xiaomi Vibration Sensor in my Hass.io install :-/

To be clear, the sensor in the mi-home app detect when it’s touched (great when glued to the washing machine) but doesn’t seem to trigger anything in hass…?

I’ve removed and re-added the sensor in the mi-home app, and it’s configured on “high” sensibility.


Not sure if that’s usefull but posting this also:



Am I doing something wrong or there is a problem with my sensor…?

Thanks by advance for the help provided!

1 Like

Hi, your doing nothing wrong. This is how these sensors work. You probably expect a state like viberate, tilt or free-fall, but the state will keep off. The good news is that this sensor has an attribute called last_action that return the state.

To follow the behavior of Xiaomi sensors, you can turn on logging by adding this to your configuration.yaml:

logger:
   default: info
   logs:
      xiaomi_gateway: debug
      homeassistant.components.xiaomi_aqara: debug
      homeassistant.components.switch.xiaomi_aqara: debug
      homeassistant.components.sensor.xiaomi_aqara: debug
      homeassistant.components.binary_sensor.xiaomi_aqara: debug

In that case you will see something like this in the logging:

DEBUG (Thread-4) [xiaomi_gateway] MCAST (report) << {'cmd': 'report', 'model': 'vibration', 'sid': '158d0002b83c5b', 'short_id': 50317, 'data': '{"status":"vibrate"}'}
DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Vibration_158d0002b83c5b: off>: {'status': 'vibrate'}
DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Bed Activity_158d0002b83c5b: None>: {'status': 'vibrate'}
DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Tilt Angle_158d0002b83c5b: None>: {'status': 'vibrate'}
DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Coordination_158d0002b83c5b: None>: {'status': 'vibrate'}
DEBUG (Thread-4) [xiaomi_gateway] MCAST (report) << {'cmd': 'report', 'model': 'vibration', 'sid': '158d0002b83c5b', 'short_id': 50317, 'data': '{"bed_activity":"202"}'}
DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Vibration_158d0002b83c5b: off>: {'bed_activity': '202'}
DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Bed Activity_158d0002b83c5b: None>: {'bed_activity': '202'}
DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Tilt Angle_158d0002b83c5b: None>: {'bed_activity': '202'}
DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Coordination_158d0002b83c5b: None>: {'bed_activity': '202'}
DEBUG (Thread-4) [xiaomi_gateway] MCAST (report) << {'cmd': 'report', 'model': 'vibration', 'sid': '158d0002b83c5b', 'short_id': 50317, 'data': '{"status":"tilt"}'}
DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Vibration_158d0002b83c5b: off>: {'status': 'tilt'}
DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Bed Activity_158d0002b83c5b: 202.0>: {'status': 'tilt'}
DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Tilt Angle_158d0002b83c5b: None>: {'status': 'tilt'}
DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Coordination_158d0002b83c5b: None>: {'status': 'tilt'}
DEBUG (Thread-4) [xiaomi_gateway] MCAST (report) << {'cmd': 'report', 'model': 'vibration', 'sid': '158d0002b83c5b', 'short_id': 50317, 'data': '{"final_tilt_angle":"16"}'}
DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Vibration_158d0002b83c5b: off>: {'final_tilt_angle': '16'}
DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Bed Activity_158d0002b83c5b: 202.0>: {'final_tilt_angle': '16'}
DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Tilt Angle_158d0002b83c5b: None>: {'final_tilt_angle': '16'}
DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Coordination_158d0002b83c5b: None>: {'final_tilt_angle': '16'}
DEBUG (Thread-4) [xiaomi_gateway] MCAST (report) << {'cmd': 'report', 'model': 'vibration', 'sid': '158d0002b83c5b', 'short_id': 50317, 'data': '{"status":"free_fall"}'}
DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Vibration_158d0002b83c5b: off>: {'status': 'free_fall'}
DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Bed Activity_158d0002b83c5b: 202.0>: {'status': 'free_fall'}
DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Tilt Angle_158d0002b83c5b: 16.0>: {'status': 'free_fall'}
DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Coordination_158d0002b83c5b: None>: {'status': 'free_fall'}
DEBUG (Thread-4) [xiaomi_gateway] MCAST (report) << {'cmd': 'report', 'model': 'vibration', 'sid': '158d0002b83c5b', 'short_id': 50317, 'data': '{"coordination":"-53,-207,1114"}'}
DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Vibration_158d0002b83c5b: off>: {'coordination': '-53,-207,1114'}
DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Bed Activity_158d0002b83c5b: 202.0>: {'coordination': '-53,-207,1114'}
DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Tilt Angle_158d0002b83c5b: 16.0>: {'coordination': '-53,-207,1114'}
DEBUG (MainThread) [homeassistant.components.xiaomi_aqara] PUSH >> <Entity Coordination_158d0002b83c5b: None>: {'coordination': '-53,-207,1114'}

If you want to make an automation you can trigger it on the following movement_types: tilt, free_fall or
vibrate. This one will trigger a notification:

automation:
   - alias: create notification upon vibrate sensor 
     trigger:
       platform: event
       event_type: xiaomi_aqara.movement
       event_data:
         entity_id: binary_sensor.vibration_158d0002b83c5b
         movement_type: vibrate 
     action:
       service: persistent_notification.create
       data_template:
               message: '{{now().strftime("%Y-%m-%d %H:%M:%S")}}: vibrate'

If you want a sensor that returns the last_action, you can try this:

sensor:
   platform: template
   sensors:
      viberate_158d0002b83c5b:
         friendly_name: vibrate_sensor_action
         value_template: '{{ states.binary_sensor.vibration_158d0002b83c5b.attributes["last_action"] }}'

I hope this makes it clear.

4 Likes

Thanks a lot for the help but I’m really struggeling trying to do what I want :frowning:

Why this sensors doesn’t work like motion sensor? That would be wwaayy easier :frowning:

The template isn’t working as I would like, for example if the sensor vibrate once, the template will stay in the “vibrate” mode until something else happen.

I’ve tried using virtual switches also but I think I’m not a good enough developper to achieve what I want.

What I want to do: the sensor vibrate once every minute when vibration is detected, I just want to receive a notification when it’s not vibrating anymore :-/

That seems so easy but really I can’t find anyway to do it easily…?

Is it possible to “listen” for all events in you first automation (notification? What if movement type is left blank?

I’m struggling with the same issue. None of the sensors will update unless i shake it vigorously. Was hoping to attach it to my washing machine or use it as a bed sensor.

I’ve made this yesterday:

I don’t know if that’s working, I didn’t take the time to check the code but if that can help somebody, maybe use it as an idea…

# Lave-Linge
  - alias: lavelinge_activite
trigger:
  platform: event
  event_type: xiaomi_aqara.movement
  event_data:
    entity_id: binary_sensor.vibration_158d0002b3XXXX
    movement_type: vibrate 
action:
- service: input_boolean.turn_on
  entity_id: input_boolean.lavelinge_timer_automation
- service: timer.start
  entity_id: timer.lavelinge_3min
- service: counter.increment
  entity_id: counter.vibrations_lavelinge

# Timer Zero
  - alias: lavelinge_timer_0
trigger:
- platform: event
  event_type: timer.finished
  event_data:
    entity_id: timer.lavelinge_3min
action:
- service: input_boolean.turn_off
  entity_id: input_boolean.lavelinge_timer_automation
- service: counter.reset
  entity_id: counter.vibrations_lavelinge

# Counter
  - alias: lavelinge_counter
trigger:
  platform: numeric_state
  entity_id: counter.vibrations_lavelinge
  above: 2
action:
- service: input_boolean.turn_on
  entity_id: input_boolean.lavelinge

I’m at work right now, if I’ve some time I’m gonna try to check this tonight, but I will have to wait the next washing machine to test it in real condition :slight_smile:

To explain a little bit the code:

When a vibrate is detected, launch a countdown of 3 minutes and switch-on an input
When the countdown is down to zero, switch off the input

Eventually that will do the job to have a “vibrate” that isn’t forever and will switch back to “off” after 3 minutes

I’m adding a counter to know if that’s just a 1 tap on the vibration sensor or if it is continous, in my application to know if I just touched the door of my washing machine or if it is actually running.

Ok, so I may have found almost a solution:

in automation:

# Lave-Linge
  - alias: lavelinge_activite
trigger:
  platform: event
  event_type: xiaomi_aqara.movement
  event_data:
    entity_id: binary_sensor.vibration_158d0002b312f4
    movement_type: vibrate 
action:
- service: timer.start
  entity_id: timer.lavelinge_4min

# lave-linge en marche
  - alias: lavelinge_working
trigger:
- platform: state
  entity_id: timer.lavelinge_4min
  to: "active"
  for:
    minutes: 10
action:
- service: input_boolean.turn_on
  entity_id: input_boolean.lavelinge

# Fin Lavage
  - alias: lavelinge_fini
trigger:
- platform: event
  event_type: timer.finished
  event_data:
    entity_id: timer.lavelinge_4min
condition:
  condition: state
  entity_id: input_boolean.lavelinge
  state: 'on'
action:
- service: input_boolean.turn_off
  entity_id: input_boolean.lavelinge
- service: notify.join
  data:
    title: "Lave-Linge | Maison"
    message: "Lave-Linge Terminé"
    data: {"icon":"https://i.imgur.com/XXXX.png"}

in configuration:

timer:
  lavelinge_cycle:
    duration: '01:20:00'
    icon: mdi:washing-machine

  lavelinge_4min:
    duration: '00:04:00'

The code seems to me simple enough to not explain everything, if you have questions don’t mind asking them.

This is not a perfect solution, but that may be working well enough for a washign machine or a dryer.

1 Like

Thank you MrDje :). One thing I dont underestand why do you have lavelinge_cycle? when it will be activated, because in automation I cant see that you use it there.

I’ve changed and enhanced my code but nobody was looking the post so I’ve wasn’t thinking it was usefull to post the updated version :wink:

The automation uses a xiaomi Vibration sensor, trigger a 4 minutes timer when detecting a vibration.
If the timer is trigerred for more than 10 minutes, he consider that the dryer is working.

The next time the timer get to zero, homeassistant consider the dryer over and send some notification on our phones and a vocal message to the google home mini in the living-room.

We love this thing since I’ve installed it! Really nice addition to my installation

# Seche-Linge
  - alias: sechelinge_activite
trigger:
- platform: event
  event_type: xiaomi_aqara.movement
  event_data:
    entity_id: binary_sensor.vibration_158d000xxxxxxxx
    movement_type: vibrate 
action:
  - service: timer.start
    entity_id: timer.sechelinge_4min

# Seche-linge en marche
  - alias: sechelinge_working
trigger:
- platform: state
  entity_id: timer.sechelinge_4min
  to: "active"
  for:
    minutes: 10
action:
  - service: input_boolean.turn_on
    entity_id: input_boolean.sechelinge

# Fin Sechage
  - alias: sechelinge_fini
trigger:
- platform: event
  event_type: timer.finished
  event_data:
    entity_id: timer.sechelinge_4min
condition:
  condition: state
  entity_id: input_boolean.sechelinge
  state: 'on'
action:
- service: input_boolean.turn_off
  entity_id: input_boolean.sechelinge
- service: notify.join
  data:
    title: "Maison | Seche-Linge"
    message: "Seche-Linge Terminé"
    data: {"icon":"https://i.imgur.com/zbLlIci.png"}
- service: notify.ios_iphone_de_xxxxxxxxx
  data:
    title: "Maison | Seche-Linge"
    message: "Seche-Linge Terminé"
- service: media_player.turn_on
  entity_id: media_player.salon_2
- service: tts.google_say
  entity_id: media_player.salon_2
  data:
    message: 'Le linge est sec'

the configuration part:

timer:
 sechelinge_4min:
 duration: '00:04:00'

And, usefull but not required:

binary_sensor:
  - platform: template
sensors:
  sechelinge_sensor:
    friendly_name: Seche Linge
    value_template: "{{ states.input_boolean.sechelinge.state == 'on' }}"
    entity_id: input_boolean.sechelinge
    device_class: plug

A sensor that I display on my frontend that display whenever or not my dryer is working.

3 Likes

And to answer this question, I’ve been lazy when copy pasting my code, I’ve got 2 sensors, 1 vibration detector for the dryer (the automation above) and I’ve got a door sensor that trigger the washing machine timer (we always use the same cycle, during 1 hour 20 minutes).

When we close the washing machine door, a 1h20 timer is launched and when it is over we have notifications that the washing machine is done.

1 Like

Hello to Everyone!!
Can someone help me to set a Template Binary Sensor for the Xiaomi Vibration sensor?
I don’t have the hub but i have added all the sensor in the zigbee2mqtt addon.
Thanks a Lot
Stefano

I need some help with this too.

I’m trying to create a template binary sensor with state that goes “ON” whenever aqara vibration sensor picks up vibration, tilt, or free_fall and resets back to “OFF” after 1 minute.

binary_sensor:
    - platform: template
      sensors:
         4csw_vibrate_last:
            device_class: vibration
            friendly_name: 4csw_vibrate_last
            delay_off:
                minutes: 1
            value_template: >-
                {{ is_state_attr("binary_sensor.4csw_vibration","last_action","vibrate") 
                    or is_state_attr("binary_sensor.4csw_vibration","last_action","tilt") 
                    or is_state_attr("binary_sensor.4csw_vibration","last_action","free_fall") }}
            attribute_templates:
                last_action: >-
                    {{ state_attr("binary_sensor.4csw_vibration","last_action") }}

I’m stuck here because delay_off is not supposed to be used this way.

Thanks in advance for any help.

Me too have this issue … any news?
Tnx in advanced

Any news? :frowning:

Hi,

I got this as value template. if there is change in last_updated, binary set to true. I dint get to test this but should work.

1st condition, when hass restarted, last_action is none, set to off.
2nd condition, if the sensor updated more than 1 second, set to off
otherwise set to on

set delay off to 1 minute. this should work

binary sensor on/off

{% if state_attr('binary_sensor.vibration_sensor','last_action') is none %}
off
{% elif 2 < (as_timestamp(now()) | int -  as_timestamp(states.binary_sensor.vibration_sensor.last_updated) | default(0) | int) %}
off
{% else %}
on
{% endif %}

sensor tilt,vibration,free_fall

{% if state_attr('binary_sensor.vibration_sensor','last_action') is none %}
off
{% elif 2 < (as_timestamp(now()) | int -  as_timestamp(states.binary_sensor.vibration_sensor.last_updated) | default(0) | int) %}
off
{% else %}
{{ state_attr("binary_sensor.vibration_sensor","last_action") }}
{% endif %}

Please note the sensor will not update to off unless you set automation to trigger
homeassistant.update_entity 1 minute after templete sensor changed.

Does the vibration attribute ever change status? Mine never does, keep showing as “off”

vibration_sensor

you probably wont see it in your card, but perhaps you could find it in the history as small lines. its more of an event then a state change.

binary_sensor:
  - platform: template
    sensors:
      genri:
        friendly_name: Генри сам себе хозяин
        device_class: vibration
        value_template: >-
          {{ is_state('sensor.vib_com', 'vibration')
          or is_state('sensor.vib_com', 'tilt')
          or is_state('sensor.vib_com', 'drop') }}
        delay_off:
          minutes: 1

Так мой попугай Генри открывает себе шторы сам, когда на улице хорошая погода и он проснулня раньше обычного времени =)

I’ve been getting the same result, I can see the tilt change, but not vibration.

I’m going to test the steps above to see if they work - they look familiar like the setup I needed to get the push buttons working.