Automation Hangs and Never Completes

I have an automation that records a short video when motion is detected using my Reolink doorbell camera. I have been using this automation for over 1 year without issue. Recently it has been failing.

Each time it fails, I see the following in the Trace Timeline:

Triggered by the state of binary_sensor.doorbell_person at January 9, 2025 at 8:37:02 AM

Test Test if template renders a value equal to true

Perform action 'Camera: Record' on Doorbell Fluent

There are many additional actions that never occur because the ‘Camera: Record’ action hangs and never completes.

How can I find additional information to diagnose why this is happening?

Below is the full automation:

alias: Doorbell Motion Video
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.doorbell_person
    from: "off"
    to: "on"
    for:
      hours: 0
      minutes: 0
      seconds: 0
condition:
  - condition: template
    value_template: >-
      {{ (as_timestamp(now()) -
      as_timestamp(states.automation.doorbell_motion_video.attributes.last_triggered
      | default(0)) | int > 150)}}
    enabled: true
  - condition: time
    before: "22:00:00"
    after: "06:00:00"
    enabled: false
action:
  - target:
      device_id: []
      area_id: []
      entity_id: camera.doorbell_fluent
    data:
      filename: /config/www/tmp/video.mp4
      lookback: 5
      duration: 18
    enabled: true
    action: camera.record
  - data: {}
    enabled: true
    action: shell_command.video_delete
  - data: {}
    enabled: true
    action: shell_command.video_convert
  - data: {}
    action: shell_command.copy_video
    enabled: true
  - delay:
      hours: 0
      minutes: 0
      seconds: 5
      milliseconds: 0
    enabled: true
  - data:
      message: >-
        Front door {{
        as_timestamp(states.automation.doorbell_motion_video.attributes.last_triggered)
        | timestamp_custom("%-I:%M %p") }}
      title: Motion Detected
      data:
        notification_icon: mdi:doorbell-video
        channel: Doorbell
        importance: max
        group: Doorbell
        video: /local/tmp/video2.mp4
        ttl: 0
        priority: high
        clickAction: /lovelace-mine/gallery
    action: notify.mobile_app_chris
  - delay:
      hours: 0
      minutes: 0
      seconds: 5
      milliseconds: 0
    enabled: true
  - data:
      message: >-
        Front door {{
        as_timestamp(states.automation.doorbell_motion_video.attributes.last_triggered)
        | timestamp_custom("%-I:%M %p") }}
      title: Motion Detected
      data:
        notification_icon: mdi:doorbell-video
        channel: Doorbell
        importance: max
        group: Doorbell
        video: /local/tmp/video2.mp4
        ttl: 0
        priority: high
        clickAction: /lovelace-mine/gallery
    action: notify.mobile_app_tina_pixel_4a
    enabled: true
trace:
  stored_traces: 40
mode: single

Is it possible there is an issue with the storage, maybe there is not enough available? If it is on an SD Card maybe it is out of room or corrupted? Possibly the most file last created was corrupted and the storage medium sees it as read-only so it cannot be replaced by the newer recording?

Once you do figure it out if it has something to do with the storage I would suggest that every recording is a new file and then right after the recording then the files be erased (or moved to some permanent storage) - ?

Thank you for the suggestions.

I am using an SSD for storage, plenty of room remaining. Not sure of the health.

I will look into deleting the file after use, although the automation has been working without issue for over a year.

It could also be the ssd is bad. I had an unreliable HA installation running on an brand new SSD that was literally driving me nuts. There were all kinds of problems that came up pretty often, and the problems were always different. As it was a new SSD I assumed that could not be the issue. By the time I realized it had a few corrupt areas (sectors?) that were causing errors randomly, I ended up exchanging it for a new one (it was just under 30 days) and all of my problems disappeared.

It litrerally dove me nuts and I struggled with it for a few weeks. argh!!(&^^%

Do a check on the SSD!

Good luck

How do I go about checking SSD health on my Pi4? Is there a native way to do so from home assistant?

YOu can google various ways, the below I got from Chatgpt for checlking from a command line

On a Raspberry Pi, several tools are available to check the health of an attached SSD. These tools can assess drive health, monitor performance, and detect potential issues.


1. smartctl (from the Smartmontools Package)

  • Purpose: Checks the SMART (Self-Monitoring, Analysis, and Reporting Technology) data of the SSD.
  • Installation:
sudo apt update
sudo apt install smartmontools
  • Usage:
    • Enable SMART on the SSD (if not already enabled):
sudo smartctl -s on /dev/sdX
  • Check drive health:
sudo smartctl -H /dev/sdX
  • Display detailed SMART data:
sudo smartctl -a /dev/sdX
  • Run a self-test:
sudo smartctl -t short /dev/sdX

Replace /dev/sdX with the correct device name (e.g., /dev/sda).


2. hdparm

  • Purpose: Provides basic drive information and performance testing.
  • Installation:
sudo apt update
sudo apt install hdparm
  • Usage:
    • Check SSD information:
sudo hdparm -I /dev/sdX
  • Test read performance:
sudo hdparm -tT /dev/sdX

3. fsck (File System Check)

  • Purpose: Checks and repairs file system errors.
  • Usage:
    • Unmount the SSD:
sudo umount /dev/sdX1
  • Run fsck:
sudo fsck /dev/sdX1

Replace /dev/sdX1 with the correct partition name.


4. iostat (from the sysstat package)

  • Purpose: Monitors SSD I/O performance and usage.
  • Installation:
sudo apt update
sudo apt install sysstat
  • Usage:
    • Monitor I/O statistics:
iostat -x /dev/sdX