New ZoneMinder API

Would love to see your ZM event server do yolov3 object detection with my Coral USB stick!

1 Like

@pliablepixels, just want to say thanks for all your work. I have only in the last month (in a new home) brought up a new system using HA + Zoneminder + zmeventnotification. All of this is running via docker containers so yes I am leveraging the dlandon docker image you pointed to (also Kudos to dlandon). Thus far I have been using the YOLO3 person detection you provided to relay events into HA via MQTT. Processing these events in HA and retrieving images from Zoneminder is not as clean/elegant as I would like, so just wanted let you know I will try out your pyzm API via AppDaemon. I am stealing the idea to use appdaemon from seanb’s article (thanks for the write-up!).

Nice! Glad you find all of this useful. We just released ZM 1.34 and along with it, pyzm which I am hoping becomes the standard official API(+ES+etc) wrapper for ZM in Python so we can extend/maintain one solution. I just read the article you pointed to and have the following thoughts:

  • When you use pyzm, please use the new token system, not user/pass.
  • The ES supports notification throttling on its own - no need for external throttling, if its just time based (tokens.txt has an interval field per monitor which specifies how long to wait before sending the next one)
  • I’ve also implemented a remote ML component, if running ML in the ZM docker is too expensive and the master branch of the ES now has the ability to fallback to local OD if the gateway fails (as a last resort) - the advantage here is that the gateway is a constantly running service, so the expensive model “load” time is eliminated on a per request basis.

Best of luck and let me know how things work out.

Thanks for the speedy response and pointers.
Regarding tokens, yep I saw that in your docs, I am definitely going to go with pyzm.
Will definitely look into the ES throttling, thanks for the pointer, I am assuming ES is the zm event server you wrote (zmeventnotification).

dlandon was quick to provide 1.34, took me awhile to work through updating in docker (noob on docker) but yes i am already on 1.34.

I will update this thread once I have something. Gotta knock the rust off of my python skills.


1 Like

I’m currently using the dlandon docker as well and finding it hard to get the motion detection images and object classifications from ZM into HA notifications.
So if the use of pyzm makes it easier to extract the detected object from the ZM alert as well as the image then I’m super interested to see how you go.

Currently, I’m getting an alert array sent via MQTT and the alert array is slightly different for person and car object detection which makes it tricky for someone like me with very little programming skill to pull out the detected object and image and feed them into a HA notification service.

No, pyzm is a ‘developer SDK’ not a replacement for dlandon’s docker container. His docker container is meant be ‘run out of the box’ in terms of not needing any programming, but you do need to configure the machine learning options correctly. Your post isn’t clear on what exactly is the issue.

@wjbeckett I agree, pyzm will not make it easier to get the desired notifications out of zoneminder/zmeventnotification-server (ES). Given I recently went through this effort, I found the main areas to focus are on how you invoke dlandon’s docker image (I just set it up to install all the image processing libraries) and properly configuring ES via the .ini files located in /etc/zm internal to the running container. If you are running docker-hassio on the same host as zoneminder, you will need to adjust the exposed listening ports via this same command line.
Debugging iterated through the following steps:

I must say I like the MQTT events as a simple/clean way to push these notifications into HA. I was attempting to use these events to trigger an automation to message/text the notes/info text inside the ES notification plus the objectdetect image associated with the notification event. This is available via the old URL based zoneminder API but have not found it yet in the pyzm API.

Thus far, pyzm is a piece of cake to set and pull info from zoneminder. However, I have yet to find a way to easily pull an event image e.g. objectdetect, snapshot, or explicit fid? I am looking for a method on the Event object or ZMApi and don’t see one. Perhaps @pliablepixels can comment?

That is correct. Pulling an image isn’t actually part of the ZM API per se. It uses https://portal/zm/index.php?view=image (not /zm/api) so as of now pyzm does the api wrapper part but I’m not averse to adding wrappers for direct media access too. Of course, PRs are very welcome - these days I’m context switching so much between zmNinja, zmMagik, zmES and mlapi, I’ve come to a stage where I completely forget what I did a week ago in any of these projects and have to relearn…

Understood, I prototyped a child class of ZMApi with a get_event_image(…) method using that URL template (you provided in your documentation… thanks). I was able to retrieve a local copy of the alarm, snapshot, or objectdetect frame. However, your _make_request(…) method returns the r.json() version of the response which caused problems when trying to pull a raw copy.

Specifying this uri for sending text message was the area I was unhappy with in HA. Trying to code via HA yaml and feed the uri to notify caused me some grief (very cryptic error messages).Using the python requests api (emulating what you did) combined with the token based auth was rock solid in retrieving these image files (beat the heck out of it).

Happy to post a PR to your zmeventnotification github project. I will do that this weekend. LMK if you prefer a different avenue. Thanks again for the fast response.

A PR would be nice. It might be a good idea to extend pyzm.helpers.Event.Event (ref) with functions to return the associated:

  • video
  • arbitrary image at an index (fid, snapshot, objdetect, alarm)

That way we can chain APIs easily.

I do have my docker setup correctly and currently feeding MQTT events into HA. That’s not the problem I have.
The problem I have is that this is the output ZoneMinder is sending to over MQTT:

{"hookvalue":"0","eventtype":"event_start","monitor":"1","state":"alarm","name":"Front Door:(1037) [a] detected:person:52% Motion Driveway","eventid":"1037"}

What I am trying to do is use some of the data from that in my automations.
For example, I currently use Deepstack to process my images and notify if a person is at the front door. However, lately ZoneMinder has been more accurate. So I’d like to be able to use the MQTT data from ZoneMinder but not send all of the above text. I’d like to be able to have a notification just send:
“Person or Car detected at the front door”

However I’m having a hard time extracting just the “Person” or “Car” from the above MQTT data and use that in a HA notify action.

For example, my current deepstack automation looks like this:

- id: person_detection
  alias: Notify when person detected
  initial_state: 'on'
  hide_entity: true
  - condition: state
    entity_id: input_boolean.options_notifications_push
    state: 'on'
    platform: event
    event_type: image_processing.object_detected
      object: person
    - delay: 00:00:02
    - service: notify.telegram
        message: '{{ }} detected at the front door'
            - file: '{{ }}'
              caption: Person Detected

Deepstack gives me the object as “person” or “car” so I can easily use that. I would like to find a way to do it with ZoneMinder. And if I can have the detection image from ZoneMinder included as well, then that would be perfect.

Any suggestion on how I can grab the “person” or “car” plus the detected image from ZoneMinder to use in HA?

1 Like

Ha! You are much more advanced than I :blush:
Yep, I have struggled with parsing the MQTT notification data also.

I did get as far as parsing out the name field using sensor/mqtt yaml descriptions such as this for my garage camera with zoneminder monitor id 1. This breaks out the eventid and the name/description string containing the message from yolo3?

  - platform: mqtt
    name: "garage alert id"
    state_topic: "zoneminder/1"
    value_template: "{{ value_json.eventid }}"
  - platform: mqtt
    name: "garage alert desc"
    state_topic: "zoneminder/1"
    value_template: "{{ }}"

I used the eventid to build a url (zoneminder api) to include the image as part of the text message sent via hangouts. I used the *garage alert desc" as the body of the text message. However, once I tightened up the authentication on zoneminder, the url building became too cumbersome for me. The only way I came up with is to write python code to do the fine grain parsing you are suggesting. I suspect you could do it via function nodes in node red but I elected to use the appdaemon approach and write an app to implement the automation script in python.

BTW, in case you didn’t see it, I provided a link to this blog article which provides the code he wrote for his appdaemon script/app. Note the image at the top of the article is his alert message via pushover. I was trying to duplicate that via hangups.

Below is the automation I used with the above sensor definition. I should note the garage notify boolean is a gate that allows me to easily shut off the alerts. I gave up on it (this automation) as I indicated and am now coding an app. Within the app, I am using pyzm to login to my zoneminder server and pull the objectdetect image associated with the event id.

- id: '1580088839247'
  alias: garage security alert
  description: ''
  - entity_id: sensor.garage_alert_id
    platform: state
  - condition: state
    entity_id: input_boolean.garage_notify
    state: 'on'
  - data_template:
      message: 'Alert {{ states.sensor.garage_alert_desc.state }} at {{ now().strftime(''%H:%M %A %d %B %Y'') }} '
        image_file: "{{ states('sensor.garage_alert_id') }}&fid=objdetect&width=600"
      title: Garage Security Alert
    service: notify.home_hangouts

I see you are using telegram, part of my problem may be trying to use hangouts. Really would like to stick with it since I use hangouts from my desktop browser gmail app and don’t want another messaging app.

Hopefully, this info is of use to you or someone reading this discussion. Apologies for implying you might not have zoneminder set up, obviously you are farther along than me.


1 Like

This is exactly what I needed to get the info into my notifications. Thank you so much!
Now I should be able to use some splits to pull out his the “person” or “car” text from the event name.

Thank you again.

Thanks, nice of you to comment. I am curious which part was helpful?

Cheers - I’ve just made an update to send out a nice JSON structure too. Testing at the moment. It may be a few days before it shows up in dlandon’s docker as he syncs based on his free time and only after I tag the release. If you are adventurous you can manually grab the updated ES+detection modules to test or wait a few days.

@pliablepixels amazing!
If I just replace the updated files, will that be enough?
Are each of your services (zm, zmevent, ml) available as separate containers (I know zm is. But I want the zmevent and ml pieces too)? I’d rather be able to update as soon as you push features.

Honestly, it was just the value templates from the mqtt sensors you setup. And then seeing how they were used. It helped me think of how I could utilise it too.

@pliablepixels Just completed the prototype of the appdaemon app (github:zmnotify)
I wrote up a feature request like we discussed on your github:zmeventnotification.

Working great except I need to understand how to leverage the
throttling you mentioned. Looking at that now.

Here is a snapshot.


1 Like

One item I forgot to mention. Adding the pyzm package required changes to config for the Appdaemon addon. The build of pyzm was failing due to build failure in psutil.

This is version 0.1.2 of AppDaemon 4.

  "system_packages": [
  "python_packages": [
  "init_commands": [
    "apk update"
  "log_level": "info"

@pliablepixels i’m not advanced enough to write something like this, but wondered if this API could be used to create a lovelace card to list alarm events with hook detection and the links to their videos?
I know ZMNinja has an option to show only items that are detected. In theory then, knowing that its been a positive trigger from detection, with the event_id and the portal URL one could pull a list of events from a user specified time period in a lovelace card?
This with Dlandon’s docker would make for a killer HA single Lovelace page for home security