Cameras - HA-ZoneMinder Integration - ONVIF triggering of start/stop recording on Tapo Cameras is too fast - producing too many very short recordings

Hi,

I own a bunch of Tapo C520WS cameras that I integrated with HA (latest version) by using the core TP Link Integration, ONVIF Integration, ZoneMinder Integration and Telnet Integration.
Instead of using ZoneMinder continuously analyzing the RTSP streams, I chose to use the cameras embedded detection logic (person detection), using HA to receive the ONVIF detection events and controlling (commanding) ZoneMinder to start/stop recording. Please note that currently ONVIF is still a work in progress in ZoneMinder (not working).

Summary of my Home Assistant Zone Minder Integration - focusing on only one camera:

  • in configuration.yaml I added the following:
camera:
  - platform: zoneminder
  
switch:
  - platform: telnet
    switches:
      camera_1_person_record:
        resource: XXX.XXX.XXX.XXX
        port: 6802
        # id|action|score|cause|text|showtext
        command_on: "1|on|50|HA-CAM1-Person|on"
        command_off: "1|off|50|HA-CAM1-Person|off"
      camera_2_person_record:
	... etc
  • then I defined two automations (one for start recording and the other for stopping recording), pasting the YAML content - screenshots are hard to capture in full
alias: CAM-1-Person-Start-Recoding
description: ""
triggers:
  - type: motion
    device_id: 91a35bfd6c29fc62840c92cec5990e9d
    entity_id: 90371312f0a352fc245621f93192dcd1
    domain: binary_sensor
    trigger: device
conditions:
  - condition: state
    entity_id: switch.camera_1_person_record
    state: "off"
actions:
  - action: switch.turn_on
    metadata: {}
    data: {}
    target:
      entity_id: switch.camera_1_person_record
mode: single
alias: CAM-1-Person-Stop-Recording
description: ""
triggers:
  - type: no_motion
    device_id: 91a35bfd6c29fc62840c92cec5990e9d
    entity_id: 90371312f0a352fc245621f93192dcd1
    domain: binary_sensor
    trigger: device
conditions:
  - condition: state
    entity_id: switch.camera_1_person_record
    state: "on"
actions:
  - action: switch.turn_off
    metadata: {}
    data: {}
    target:
      entity_id: switch.camera_1_person_record
mode: single

Now, everything works fine, except the Tapo cameras firmware logic considers a person detection event to stop a second after there is no movement (and I have no means to fine-tune it). Thus, I receive a lot of start/stop ONVIF person detection events and consequently I record a lot of very short (2-3 seconds) recordings. It’s a mess, hard to manage the files (hundreds per day) and follow the events in Zone Minder.

I was goofing around in the HA automation, trying to insert some delay in the CAM-1-Person-Stop-Recording automation, inserted a 30 seconds delay before the action: switch.turn_off and I got extra 30 seconds recorded in Zone Minder for every person detection event.
However, if there is another person detection event occurring (HA receiving trough ONVIF) during these 30 seconds, then the CAM-1-Person-Start-Recoding automation is not executed anymore. Weird.

A second approach was to try to put a delay before stopping the recording (action: switch.turn_off) in the CAM-1-Person-Stop-Recording automation and then stopping (cancelling) all (previous) CAM-1-Person-Stop-Recording sessions/automations, keeping executing only the automation currently running (the last one) by using the sequence automation.turn_off (CAM-1-Person-Stop-Recording) - delay 10 seconds - automation.turn_on (CAM-1-Person-Stop-Recording) from here:

Problem is, if I execute automation.turn_off (CAM-1-Person-Stop-Recording) from within the CAM-1-Person-Stop-Recording automation then it exits the automation and the next line automation.turn_on (CAM-1-Person-Stop-Recording) is not executed anymore, ZoneMinder will not stop recording.

Another dumb approach would be to cancel the CAM-1-Person-Stop-Recording altogether and use only the CAM-1-Person-Start-Recoding by always recording at least 1 minute, even if there are no person detection events after the one that triggered it. It’ll be a waste of storage space, but at least I maybe won’t have to manage hundreds of 2-3 seconds long recording per day.

Any ideas/experiences/hints on how to cancel(ignore and keep the last one as relevant) the many ONVIF stop person detection events and creating longer recordings are welcomed.

Thanks in advance!

Forgot to add an excerpt from HA Logbook highlighting the behavior I described in my original post. I was walking in front of one of the cameras (uhu2) and haven’t stopped for more than a second:

binary_sensor.uhu_2_person_detection detected motion
21:54:40 - 2 hours ago
camera_2_person_record turned off triggered by automation UHU-2-Person-Stop-Recoding triggered by state of binary_sensor.uhu_2_person_detection
21:54:19 - 2 hours ago
UHU-2-Person-Stop-Recoding triggered by state of binary_sensor.uhu_2_person_detection cleared (no motion detected)
21:54:18 - 2 hours ago
binary_sensor.uhu_2_person_detection cleared (no motion detected)
21:54:18 - 2 hours ago
camera_2_person_record turned on triggered by automation UHU-2-Person-Start-Recoding triggered by state of binary_sensor.uhu_2_person_detection
21:54:18 - 2 hours ago
UHU-2-Person-Start-Recoding triggered by state of binary_sensor.uhu_2_person_detection detected motion
21:54:18 - 2 hours ago
binary_sensor.uhu_2_person_detection detected motion
21:54:18 - 2 hours ago
camera_2_person_record turned off triggered by automation UHU-2-Person-Stop-Recoding triggered by state of binary_sensor.uhu_2_person_detection
21:54:17 - 2 hours ago
UHU-2-Person-Stop-Recoding triggered by state of binary_sensor.uhu_2_person_detection cleared (no motion detected)
21:54:17 - 2 hours ago
binary_sensor.uhu_2_person_detection cleared (no motion detected)
21:54:17 - 2 hours ago
camera_2_person_record turned on triggered by automation UHU-2-Person-Start-Recoding triggered by state of binary_sensor.uhu_2_person_detection
21:54:16 - 2 hours ago
UHU-2-Person-Start-Recoding triggered by state of binary_sensor.uhu_2_person_detection detected motion
21:54:16 - 2 hours ago
binary_sensor.uhu_2_person_detection detected motion
21:54:16 - 2 hours ago
camera_2_person_record turned off triggered by automation UHU-2-Person-Stop-Recoding triggered by state of binary_sensor.uhu_2_person_detection
21:52:47 - 2 hours ago
UHU-2-Person-Stop-Recoding triggered by state of binary_sensor.uhu_2_person_detection cleared (no motion detected)
21:52:47 - 2 hours ago
binary_sensor.uhu_2_person_detection cleared (no motion detected)
21:52:47 - 2 hours ago
camera_2_person_record turned on triggered by automation UHU-2-Person-Start-Recoding triggered by state of binary_sensor.uhu_2_person_detection
21:52:47 - 2 hours ago
UHU-2-Person-Start-Recoding triggered by state of binary_sensor.uhu_2_person_detection detected motion
21:52:46 - 2 hours ago
binary_sensor.uhu_2_person_detection detected motion
21:52:46 - 2 hours ago
camera_2_person_record turned off triggered by automation UHU-2-Person-Stop-Recoding triggered by state of binary_sensor.uhu_2_person_detection
21:52:45 - 2 hours ago
UHU-2-Person-Stop-Recoding triggered by state of binary_sensor.uhu_2_person_detection cleared (no motion detected)
21:52:45 - 2 hours ago
binary_sensor.uhu_2_person_detection cleared (no motion detected)
21:52:45 - 2 hours ago
camera_2_person_record turned on triggered by automation UHU-2-Person-Start-Recoding triggered by state of binary_sensor.uhu_2_person_detection
21:52:43 - 2 hours ago
UHU-2-Person-Start-Recoding triggered by state of binary_sensor.uhu_2_person_detection detected motion
21:52:43 - 2 hours ago
binary_sensor.uhu_2_person_detection detected motion
21:52:43 - 2 hours ago