Aqara vibration sensor orientation to trigger automation

Hey guys,
I’m pretty new to HA, I got a Aqara vibration senson and added it to my vacuum robot. I now want to trigger an automation when I close my robot after cleaning my dust bin. I tried to use the orientation value of the sensor in an automation, but it didn’t work. How can i get the second value (1) to trigger my automation?

Thank you!

I think the first thing you need to do is capture the events from the sensor using Developer Tools - Events, enter “zha_event” and press “Start Listening” and you should see something like this:

You can then use this information in an automation trigger and conditions as per the example below:

alias: Aqara D1 Automation
description: Under test
trigger:
  - event_data:
      device_ieee: '00:15:8d:00:04:77:6a:37'
    event_type: zha_event
    platform: event
condition: []
action:
  - choose:
      - conditions:
          - condition: template
            value_template: '{{ trigger.event.data.command in [''left_single''] }}'
        sequence:
          - device_id: 5320c28c7c1e45c580aa9a5ad9bc4432
            domain: light
            entity_id: light.kitchen_lights
            type: toggle
      - conditions:
          - condition: template
            value_template: '{{ trigger.event.data.command in [''right_single''] }}'
        sequence:
          - device_id: 92c52b6d053e42e5a472e7b017c60032
            domain: switch
            entity_id: switch.sonoff03
            type: toggle
      - conditions:
          - condition: template
            value_template: '{{ trigger.event.data.command in [''left_double''] }}'
        sequence:
          - entity_id: input_select.kitchen_scenes
            service: input_select.select_previous
      - conditions:
          - condition: template
            value_template: '{{ trigger.event.data.command in [''right_double''] }}'
        sequence:
          - entity_id: input_select.kitchen_scenes
            service: input_select.select_next
      - conditions:
          - condition: template
            value_template: '{{ trigger.event.data.command in [''left_long press''] }}'
        sequence:
          - device_id: 5320c28c7c1e45c580aa9a5ad9bc4432
            domain: light
            entity_id: light.kitchen_lights
            type: toggle
      - conditions:
          - condition: template
            value_template: '{{ trigger.event.data.command in [''right_long press''] }}'
        sequence:
          - device_id: 92c52b6d053e42e5a472e7b017c60032
            domain: switch
            entity_id: switch.sonoff03
            type: toggle
    default: []
mode: queued
max: 3

I don’t have a vibration sensor so I could be wrong however there would be no harm trying the above.

1 Like

try this

@lonebaggie Do I need to have the Aqara bridge for this? Because I connected my vibration sensor directly to my conbee II.

@Jonah1970 Sadly nothing happens when listening to zha_event.

OK, sorry it did not help.

1 Like

Sorry yes my solution use the xiaomi hub

I found someone who got it to work. He uses the y angle to trigger. But sadly he doesn’t respond.

This is his code, I tried to adapt it, but I failed. Anyone got an idea how to make it work?

- id: vacuumdustbinemptied
  alias: Roborock Staubbehälter geleert
  trigger:
  - event_data:
      data: /roborock-geleert
    event_type: telegram_callback
    platform: event
  - below: '-25'
    entity_id: sensor.vibration_sensor_roborock_action
    for: 00:00:10
    platform: numeric_state
    value_template: '{{ state.attributes.angle_y}}'
  - platform: tag
    tag_id: roborock
  condition:
  - condition: and
    conditions:
    - condition: or
      conditions:
      - condition: state
        entity_id: input_boolean.daily_vacuum_first_run
        state: 'on'
      - condition: numeric_state
        entity_id: counter.reinigung
        above: 0
    - condition: state
      entity_id: input_boolean.vacuum_dust_bin_emtpied
      state: 'off'
  action:
  - data:
      entity_id: input_boolean.vacuum_dust_bin_emtpied
    service: homeassistant.turn_on
  - data:
      entity_id: counter.reinigung
    service: counter.reset
  - delay: 00:00:05
  - data:
      data:
        type: announce
      target:
      - group.echo_notification
      message: Hey, vielen Dank, dass du den Staubbehälter meines Kumpels Rocky geleert
        hast.
    service: notify.alexa_media
  - data:
      callback_query_id: '{{ trigger.event.data.id }}'
      message: Alles klar :)
    service: telegram_bot.answer_callback_query
  - data:
      chat_id: '{{ trigger.event.data.chat_id }}'
      inline_keyboard: []
      message_id: '{{ trigger.event.data.message.message_id }}'
    service: telegram_bot.edit_replymarkup

I added a sensor in my sensor.yaml. Now I get the three angles as own sensor.

    # Angle Sensor Roborock
        roborock_angle:
            value_template: "{{ state_attr('binary_sensor.vibration_1', 'orientation')}}"
            friendly_name: Angle Sensor Roborock
            unit_of_measurement: '°'
1 Like

I guess you now have all 3 axes in one sensor value.

How would I proceed when I only want to monitor one specific Angel (like the y-axis e. g.)?