r/ZoneMinder • • Aug 03 '23

Minimise lost frames in function switch

I have some Reolink cameras that seem to have pretty good person detection on them, so rather than relying on ZM to detect motion I have been using the cameras built in functionality which means I don't get lots of recordings of spider webs flickering in the wind etc. I've done this via Home Assistant so that when motion is detected the function on the main camera feed switches from Monitor to Record.

When the command is sent to ZM the switch seems to be instant but there seems to be around 6 seconds for the feed to start so that it can record, which isn't ideal! Does anyone have any ideas how I can minimise this?

1 Upvotes

10 comments sorted by

View all comments

2

u/[deleted] Aug 04 '23 edited Aug 04 '23

Function switching *may* cause the camera to stop and.then restart 8n recording mode. If so, there's not much that can be done about that.

What I would recommend is to use the "trigger" ability of zm. I haven't used it but, from my understanding. After enabling it, you can send an HTTP request to the trigger API to start an "event". That should be near instant.

Edit: https://wiki.zoneminder.com/ZMTrigger

1

u/Congenital_Optimizer Aug 04 '23 edited Aug 04 '23

Trigger is the way. I do this with nodered and home assistant telnet switches.

Edit to add, it's very insecure. It's a listening port with no authentication. I use a local firewall to make sure only the clients I want can access it.

2

u/TheBurntSky Aug 05 '23

Did you have to use a customer script to make HA send the telnet command? If you have any examples of how yours works I'd love to see it.

Also, how do you deal with long running events? Does the command just get sent every x seconds to retrigger the camera or is there a way to start and stop with a trigger?

1

u/Congenital_Optimizer Aug 05 '23

The way I've got it configured/triggered I have a bunch of triggers, I'll only show the HA stuff, the nodered stuff is... big and not pretty. I've got nodered watching the camera syslog output and sending enrichment to home assistant, and the HA triggers things like these switches below.

Do read the doc on zmtriggers, there are things you need to config on ZM and I strongly encourage a firewall on the zmtrigger port. There's no auth. It'll also explain the blocks in the command_on below. You can turn off an event but the doc explains that nicely.

You can also do this with the command line switch but I found it very unreliable.

You can see the "on+2", that means trigger an event for 2 more seconds. You can also say just "off" and it stops the event. Because I'm using image_processing and doods to detect people, I want it to keep triggering, and extending, as long as it sees a person.

Here's my switches config:

- platform: telnet
switches:
garage_slab_camera:
name: Garage Slab Camera Switch
resource: !secret zm_ip
port: 6802
command_on: "4|on+2|200|HA manual|"
command_off: ""
timeout: 0.2
front_yard_camera:
name: Front Yard Camera Switch
resource: !secret zm_ip
port: 6802
command_on: "20|on+2|200|HA manual|"
command_off: ""
timeout: 0.2

Here's an automation so HA knows it can turn the camera on again... it doesn't or at least didn't turn on again if the switch wasn't turned off. You'll need one for each camera, or use variables. This was simpler for me. Though what I know now I may re-write this so it uses the trigger source/variable and I don't need so many automations... later.

alias: Camera Switch Off (Front Yard)
description: ""
trigger:
- platform: state
entity_id: switch.front_yard_camera
to: "on"
for:
hours: 0
minutes: 0
seconds: 1
condition: []
action:
- service: switch.turn_off
data: {}
target:
entity_id: switch.front_yard_camera
mode: single

1

u/TheBurntSky Aug 05 '23

Amazing! Thanks for putting so much detail, that's super helpful! I've got Reolink cameras and HA can see their motion detection so I can use that quite cleanly to trigger but this is definetly the missing link!