Trying to figure out an automation for trash w/ aqara vibration sensor

Hey guys, I have an Aqara vibration sensor on my outdoor trash can that gets picked up by our removal service weekly. The plan was to toggle a home assistant switch when vibration is detected so that I know whether the trash was taken out or if its still inside. However, I only want to detect vibrations that are longer than, say, 30 seconds, since that is about how long it takes for me to bring the trash down the driveway. Any other vibrations that are just a few seconds will happen when I open the trash lid to put a bag inside of it.

On the home assistant trigger, I had it set as below, with the thought that this was looking for the duration of the vibration. However, this didn’t work, and any vibration immediately triggers the automation regardless if it is 30 seconds or not:

platform: state
entity_id: binary_sensor.trash_vibration_sensor_3018
from: 'off'
to: 'on'
for:
  hours: 0
  minutes: 0
  seconds: 30
  milliseconds: 0

What is the best way to go about doing this kind of automation properly with minimizing false positives? I’m wondering if setting up a “wait for trigger” event would be better, although I’ve never messed around with that before.

Doing something like this might help:

alias: Trash Day
trigger:
- platform: state
  entity_id: binary_sensor.trash_vibration_sensor_3018
  to: 'on'
  for:
    seconds: 30
condition: []
action:
- wait_for_trigger:
  - platform: state
    entity_id: binary_sensor.trash_vibration_sensor_3018
    to: 'off'
    for:
      seconds: 30

The vibration sensor are very finicky and seem to detect when they want to.

Thanks, I will try this out.

Unfortunately, since the vibration duration doesn’t register, this doesn’t seem to work. The sensor will only register if there is a vibration or not, it doesn’t actually note the duration. I’ve tried to do something similar to:

  1. Detect vibration
  2. Delay 20 seconds
  3. Wait for trigger of detecting vibration again. If so, toggle the switch.

However, this doesn’t seem to work either since if detects vibration in step 1 for just a second, it still waits the 20 seconds for step 2, but step 3 never happens. So it could be days later, but when any vibration happens again, it will toggle the switch. I need to be able to timeout the “wait for trigger” step 3 after a few minutes I think.

Gonna try:

alias: 'Trash outside'
description: ''
trigger:
  - platform: state
    entity_id: binary_sensor.trash_vibration_sensor_3018
    from: 'off'
    to: 'on'
    for:
      hours: 0
      minutes: 0
      seconds: 0
      milliseconds: 0
condition: []
action:
  - delay:
      hours: 0
      minutes: 0
      seconds: 20
      milliseconds: 0
  - wait_for_trigger:
      - type: motion
        platform: device
        device_id: 167c1fabd4ee694975e19047b5027ea4
        entity_id: binary_sensor.trash_vibration_sensor_3018
        domain: binary_sensor
    continue_on_timeout: false
    timeout: '00:00:30'
  - service: input_boolean.toggle
    target:
      entity_id: input_boolean.trash_is_outside
  - service: notify.mobile_app_s9
    data:
      message: Trash vibration detected
mode: single