Door knock notifications on sliding door

I migrated from smartthings and used to have a webcore automation that would send a notification if there was knocking on my back door but it would only send this notification if there was vibration while the door was closed. I didn’t save my automations and was able to recreate all but this one. I have it setup but it also triggers just opening the door. I can’t find a way to use a condition in which it makes sure the door contact sensor didn’t change in x amount of time before notifying.

Please share the automation yaml. It would be helpful.

alias: Back door knocking
description: ''
trigger:
  - type: moving
    platform: device
    device_id: 347070566aaf666b13ee61816a14a5aa
    entity_id: binary_sensor.back_door_sensor_accelerometer
    domain: binary_sensor
condition:
  - type: is_not_open
    condition: device
    device_id: 347070566aaf666b13ee61816a14a5aa
    entity_id: binary_sensor.back_door_sensor_contact
    domain: binary_sensor
    for:
      hours: 0
      minutes: 0
      seconds: 10
action:
  - service: notify.notify
    data:
      message: Knocking at the back door. Do the dogs need to come in?
mode: parallel
max: 10

what are states made by this sensor? is it on/off or open/close or anything else. And also for the below sensor.

Contact is open/closed
Accelerometer is moving/not moving

This is a smartthings multi-purpose sensor.

Try if this works.

alias: Back door knocking
description: ''
trigger:
  - platform: state
    entity_id: binary_sensor.back_door_sensor_accelerometer
    from: 'not moving'
    to: 'moving'
condition:
  - condition: state
    entity_id: binary_sensor.back_door_sensor_contact
    state: 'closed'
    for:
      hours: 0
      minutes: 0
      seconds: 10
action:
  - service: notify.notify
    data:
      message: Knocking at the back door. Do the dogs need to come in?
mode: parallel
max: 10

This is basically the exact thing I have. I don’t see a difference other than it’s calling the state instead of the device.

Go to Developer Tools > States and examine the state values for these two binary_sensors:

  • binary_sensor.back_door_sensor_contact
  • binary_sensor.back_door_sensor_accelerometer

Normally, a binary_sensor’s state values are on or off (i.e. binary) as opposed to moving/not_moving or open/closed (if it isn’t on/off then it’s not conforming to Home Assistant’s convention for a binary_sensor).

If a binary_sensor is assigned a device_class like door then in the Lovelace UI it will display Open/Closed but its state values will still be on/off.

In contrast, a sensor’s state values can be anything.

I’ve never used that page before. It will be useful. It doesn’t seem to live update cause when I change the state of the door it doesn’t change. None the less, my current automation works but I begin opening the back door the accelerometer detects movement before the contact sensor is open so the knocking fires still. I used to have a variable that would check if the door contact sensor had changed state in the last 3 seconds and if so wouldn’t trigger knocking. How would I look for this and incorporate that?

Well that’s very odd because the States page normally does report an entity’s current state (i.e. it is a “live” view).

You overlooked to mention the state values reported by each binary_sensor in the States view.

It is currently off for both

I was looking at the wrong sensor, they both update live and the binary state is on/off

When opening the door the accelerometer goes on before the contact sensor.

OK, so it stands to reason that the two conform to Home Assistant’s convention for binary_sensors and report their states as on or off. However, if they fail to change in the States view, when you operate the actual device, then something is amiss somewhere.

This automation triggers when the accelerometer turns on and then checks if the contact sensor has been off for at least 10 seconds. If it has then it will send a notification. However, it’s unlikely to work if, according to your observations, the states of the binary_sensors never change from off.

alias: Back door knocking
trigger:
  - platform: state
    entity_id: binary_sensor.back_door_sensor_accelerometer
    to: 'on'
condition:
  - condition: state
    entity_id: binary_sensor.back_door_sensor_contact
    to: 'off'
    for: '00:00:10'
action:
  - service: notify.notify
    data:
      message: Knocking at the back door. Do the dogs need to come in?

If the door has been closed for at least 10 seconds it will still trigger when opening the door as the accelerometer triggers before the contact. It’s an old door so the motion is not fluid.

Are these two entities part of two separate physical devices or just one?

If it’s just one device then I can’t see how this automation will ever work. It’s triggered the moment the device detects acceleration but that movement suggests the contact sensor may have also just changed state. That means the automation’s condition, 10 seconds of closure, can never be satisfied.

Is it possible for this device to report acceleration without the contact portion changing state?

It’s the same device. This was previously accomplished on smartthings via webcore. When the contact sensor changed state it set a variable of %door_state to 1 for 10 seconds then if accelerometer = on AND %door_state = 0 THEN notify. It essentially required 2 parts.

I believe I found my direction. I just need one automation to set an input_boolean and the door knock automation to condition this

I believe a helper is needed here.

Pseudo automation:

automation 1
trigger on contact change to on (closed)
set state of boolean helper to off.
delay 10 seconds
set state of boolean helper to on.

automation 2
tigger on motion.
condition: boolean helper is on
action: knock detected.

This way you have a boolean that looks at how long the door is closed (or at least 10 seconds).
Having for will not work since that requires time ahead, whereas this looks back in time.

I was just figuring this out via Google, haha. Thanks!

Why do you need that when the contact sensor indicates when, and for how long, the door is closed?