💥 Door Knock Detection

Introduction

Hello everyone. Hope you are all well.

I’ve been here for absolutely ages lurking away and decided finally to make an account to start sharing some stuff I’ve been working on. One in the hopes to give a little back to the community and two to hopefully improve on them with more sets of eyes. This is my first submission of a blueprint here, so please do let me know if there’s anything that can be improved on, or just your experience with it. It’s always good to hear some success stories from something I’ve made.

Door Knock Detection

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

This is my door knock detection blueprint that I devised to detect those lazy buggers who cant be bothered to press my doorbell and would rather knock like a caveman. I ran into a myriad of issues initially when I bought the vibration sensor for this purpose, especially with false knock positives as someone walked through the door. I created this blueprint to remedy those issues and also to apply it to both of my external doors without repeating logic.

I’ve been using this for way over a year now on my own doors and I don’t remember it ever failing.

Features

  • Detects a door knock with any vibration sensor.
  • Robust trigger conditions to enable minimal/zero false positives.
  • Custom action to fire when the knock is detected.
  • Customisable check duration and a “no change” duration to tune it to your setup and sensors.
  • Global custom condition to disable the entire automation from running.

Requirements

  • Contact Sensor for door open/close detection
  • Vibration sensor on the door to detect the knock

Available Settings

Check Duration

This setting is best set as low as possible as it will delay the action from running. I didn’t mind making those who knock wait an extra 3 seconds for my arrival. If they rang the door bell they’d get me 3 seconds earlier! Others may not.

This check duration is there to delay the automation from checking the state of the door. So when the vibration happens, a delay runs for the inputted time before checking the next setting and if the contact sensor is closed. This is due to sensor trigger timing’s more than anything as we don’t live in a perfect world where the vibration always happens before the door changes state. Initially I had a lots of cases where the vibration sensor would go off just after, sometimes just before, the door closed.

Door Inactive Duration

This setting can be whatever you feel comfortable with. It’s just an additional check so we don’t get any false positive triggers. After the door knock triggers, and the check time has passed. This condition looks to see if the door has changed state within the last ‘x’ seconds. This was again to add some robustness to the automation as the vibration doesn’t always happen exactly before the door opens/closes sometimes, with my zigbee sensors anyway, it fired a few seconds after I’d walked through the door and shut it.

Blueprint

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

blueprint:
  name: "Door Knock Detection"
  description: This blueprint will trigger a custom action when a knock at the door is detected by a vibration sensor.
  domain: automation
  author: NotExpectedYet
  homeassistant:
    min_version: 2024.6.0
  input:
    entities:
      name: Entities
      icon: mdi:vibrate
      input:
        virbation_sensor:
          name: Vibration Sensor
          description: The vibration sensor you have attached to the door. This is used to detect the knock.
          default: []
          selector:
            entity:
              domain: binary_sensor
              device_class: vibration
        contact_sensor:
          name: Contact Sensor
          description: The contact sensor you have attached to the door. This is used to detect whether the knock was a knock, or just someone opening/closing the door.
          default: []
          selector:
            entity:
              domain: binary_sensor
              device_class:
                - door
                - opening
                - window
    settings:
      name: Settings
      icon: mdi:cog
      input:
        check_duration:
          name: Check Duration
          description: The duration to wait before making sure the door is still in the "closed" state. This is best set as low as you can reasonably get away with as it will delay the action.
          default:
            hours: 0
            minutes: 0
            seconds: 3
            milliseconds: 0
          selector:
            duration:
        no_change_time:
          name: Door Inactive Duration
          description: When the knock is detected, the door must not have changed state for this amount of time.
          default: 30
          selector:
            number:
              min: 1
              max: 120
              unit_of_measurement: seconds
    action_to_trigger:
      name: Action to Trigger
      description: The action to trigger when a knock has been detected.
      default: []
      selector:
        action:
    global_condition:
      name: Global condition
      description: "Customised condtitions to stop the *entire* automation running."
      default: []
      selector:
        condition:
trigger:
  - platform: state
    entity_id: !input virbation_sensor
    from: "off"
    to: "on"
condition: !input global_condition
variables:
  contact_input: !input contact_sensor
  no_change_time_input: !input no_change_time
  contact_triggered_over_x_ago: >-
    {{(as_timestamp(now()))-(as_timestamp(states[contact_input.split(".")[0]][contact_input.split(".")[1]].last_changed)) > no_change_time_input }}
action:
  - delay: !input check_duration
  - if:
      - condition: template
        value_template: >-
          {{ contact_triggered_over_x_ago }}
      - condition: state
        entity_id: !input contact_sensor
        state: "off"
    then: !input action_to_trigger
mode: single

Future

Dunno! Happy for thoughts and ideas. Currently it does what it says on the tin and I’ve had no personal need to expand it further. I have had an idea now just writing this, there is a limitation currently in that it only detects knocks on a closed door. I wonder if a similar methodology could be applied for open doors, personally it’s not warranted but I may do it if someone asks nice enough.

2 Likes

Hello ,

Thanks for contributing to the community with a new Blueprint.

I have a suggestion for you. Many people who are not familiar with directory structures will have problems installing this without the Home Assistant MY tools.
Adding a MY link for this Blueprint to your top post would help them a lot.
Here is the link to make that.
Create a link – My Home Assistant

Updated with the home assistant ‘MY’ link

Thanks just what i was looking for. Ill give it a go and let you know

1 Like

It would be a bonus if add a camera to it

Do you mean for a notification?

Personally I keep those out of my blueprints because I utilize some hefty scripts to send them. Does the included custom action not help with that?