Doorbell person detection, strictly local, without frigate or similar, including telegram message with pictures and videos

There were a few strange things to troubleshoot, so thought that I would share my solution here. I really like much about the Amcrest AD410 doorbell: high resolution, on-camera person detection, infrared light, great dynamic range, two-way communication. On the other hand, the default requires access to the cloud, and/or use of a closed-source app that accesses the internet, both of which are streng verboten in my setup. There is a way to get nearly all the features while forbidding the camera from accessing the internet, and not using closed-source apps. If you are willing to use the closed-source app, but forbid it from accessing your phone, location or your location, you can also get two-way audio communication with the doorbell.

Here are some of the details.

  1. It is quite simple to install the doorbell, and there are lots of reviews and videos about its merits: Amcrest 4-Megapixel Video Doorbell Camera Pro, Outdoor Smart Home 2.4GHz and 5GHz Wireless WiFi Doorbell Camera, Micro SD Card, PIR Motion Detector, IP65 Weatherproof, 2-Way Audio, 164Âş Wide-Angle Wi-Fi AD410 I found no way to avoid using the app to provision the thing, but once it is hooked up to the internet, you can delete the app, and block the doorbell from reaching the internet. Give it a fixed IP address.
  2. There are multiple ways to integrate it into Home Assistant, but I had good luck using rroller’s Dahua integration, which gives access to many features. When configuring, there is a long list of events to choose from. I used the default ones, which works fine. Maybe some could be removed:

    You need to give it a name, the IP address assigned the doorbell, and the rest as default. This will give you 21 entitities, like motion detection, smart motion detection, human detection, the ability to switch both both the infrared light and ring light on and off, or one of three settings for the LED at the bottom of the doorbell. You also get audio and video from the doorbell to the dashboard. Finally, it gives doorbell presses, and three sensors for evidence of tampering with the device. The important entity name to notice here is human motion detection, which for mine (in the automation below) is binary_sensor.amcrest_front_door_smart_motion_human.
  3. I was unable to get the video to play well with Telegram notifications, so I also added the ONVIF integration. This integration also gave a dozen entities, but I am using only the main RTSP camera feed. These integrations showed no sign of interfering with one another. For the automation I use the entity camera.lexus_mediaprofile_channel1_mainstream (this was the default name chosen by the integration, which found the camera automagically :man_shrugging:).
  4. Now you can add one of the camera feeds to the dashboard (three different resolutions), and some of the above entities, too, if you want. You can also do automations. The first automation detects when a person approaches the door (from Dahua), and triggers taking a snapshot (from ONVIF), which it sends to a telegram notification. Of course, you need to set up the telegram bot first, which you can get from reading the docs. The cool part of the automation is that it also sends a button to the telegram notification. If you click it, it then sends you a video of about 10 seconds before the person is detected and 20 seconds after. The documentation claims that this duration is tunable, but I am not so sure.
  5. Before creating the automation, you need to create a couple counters in your configuration.yaml:
counter:
  photo_counter:
    initial: 0
    step: 1
  person_video_counter:
    initial: 0
    step: 1

These counters label the photos and videos. You also need to whitelist the directories in that yaml file to store the photos and videos:

homeassistant:
  whitelist_external_dirs:
    - /config/www/captures/photos
    - /config/www/captures/person_video

You probably do not want to fill your hard drive with the videos, so you can create a shell_command to clean them up periodically (every 7 days here):

shell_command:
  removepersonvideos: 'find /config/www/captures/person_video/*.mp4 -mtime 7 -exec rm {} \;'
  removedoorbellphotos: 'find /config/www/captures/photos/person_*.png -mtime 7 -exec rm {} \;'
  1. Finally, here is the automation to take the photos and videos, send the photo and a button, and clean up old files:
trigger:
  - type: motion
    platform: device
    device_id: 8d838ec89f11a3c1d64863417fb8498b
    entity_id: binary_sensor.amcrest_front_door_smart_motion_human
    domain: binary_sensor
condition: []
action:
  - service: counter.increment
    target:
      entity_id:
        - counter.photo_counter
        - counter.person_video_counter
    data: {}
  - service: camera.snapshot
    data:
      filename: >-
        /config/www/captures/photos/person_{{states('counter.photo_counter')}}.png
    target:
      entity_id: camera.lexus_mediaprofile_channel1_mainstream
  - service: telegram_bot.send_photo
    data:
      file: >-
        /config/www/captures/photos/person_{{states('counter.photo_counter')}}.png
      caption: Person at Front Door ({{states('counter.person_video_counter')}})
      disable_notification: true
      inline_keyboard: >-
        Request person video
        {{states.counter.person_video_counter.state}}:/person-video-button
        {{states.counter.person_video_counter.state}}
  - delay:
      hours: 0
      minutes: 0
      seconds: 10
      milliseconds: 0
  - service: camera.record
    data:
      filename: >-
        /config/www/captures/person_video/video_{{states('counter.person_video_counter')}}.mp4
      duration: 10
      lookback: 1
    target:
      entity_id:
        - camera.lexus_mediaprofile_channel1_mainstream
  - service: shell_command.removedoorbellphotos
    data: {}
  - service: shell_command.removepersonvideos
    data: {}
mode: single

Note that it makes the notification silently. I don’t want my phone to buzz everytime someone walks by YMMV.

  1. For the button on telegram to work, you need another automation that listens for the message from telegram:
alias: Send person detection video on telegram request (callback)
description: ''
trigger:
  - platform: event
    event_type: telegram_callback
    event_data:
      command: /person-video-button
condition: []
action:
  - service: telegram_bot.answer_callback_query
    data_template:
      show_alert: false
      callback_query_id: '{{ trigger.event.data.id }}'
      message: Requested person detection video {{trigger.event.data.args[0]}}
  - service: telegram_bot.send_video
    data:
      file: >-
        /config/www/captures/person_video/video_{{trigger.event.data.args[0]}}.mp4
      caption: Person detection video {{trigger.event.data.args[0]}}
      disable_notification: true
      timeout: 120
mode: single
  1. I also made an automation that is nearly identical for a button press, except the notification is not silent. That means you need another counter, another shell command, and another directory to whitelist. You can duplicate the two automations, but change the trigger to doorbell. You also have to change the names of the counters, the directories, the buttons and the shell_command to clean up.

  2. If you really want the two-way audio communication, it can be had by using the Amcrest View Pro app. The only permissions it needs are access to files and media (maybe not even that, really), and microphone. I denied it camera, location and phone. It never asked from internet connection. I have read elsewhere that one should not use this app to change settings, because it can brick the doorbell. I did live on the edge and see if I could set the infrared light to switch on automatically. The automation on the doorbell worked, but that was switched off when I used the Dahua integration to switch the light off manually once. I don’t need it, so did not tempt fate a second time.

Hope I didn’t forget anything and that someone else finds this useful.

7 Likes

Thanks for this. I was looking for exactly this functionality, and it is a great write-up. One minor question… The snapshot action creates files named person_*.png, but the shell command to remove them specifies doorbell_*.png. Is this correct? Otherwise, it all works perfectly.

Good catch! You are correct, and I have edited the post. That shell script was for the similar automation involving a doorbell press. I am glad that you found it useful.

In the meantime, I have supplemented this using frigate, double-take and compreface to do facial recognition. It does not really interfere with this, although it probably makes some of it now obsolete. If you have the extra resources to do the facial recognition and NVR on a server (probably too much for a pi or similar), it is worth checking out. I now get a message that tells me who is at the door.