New ZoneMinder API

Well well.
It sucks, so I’m now trying to install zoneminder for real this time and zme.
Let’s see how it goes.

IT works again…
ZM 1.34.22 with the version of zm event server…

Let’s go… :slight_smile:

But, there seems to be changes in MQTT events.
Before I could parse the mqtt json with this:

{{ value_json.detection|map(attribute='label')|join(', ') }}

and I got found objects etc… But there seems to be an change as it wont work anymore.
All I get is empty “labels” from value_json.

Ok, did manage to get all of the labels with try and error…
But i dont know why but I get these brakets… How to remove themn?

{% set value_json = 
{"state":"alarm","eventtype":"event_start","eventid":"3367","hookvalue":"0","name":"Over Parking:(3367) detected:car:54%  Motion All","monitor":"4","detection":{"boxes":[[152,228,404,522]],"image_dimensions":{"resized":[600,800],"original":[480,640]},"frame_id":"snapshot","confidences":[0.53509646654129],"labels":["car"]}}
%}
--> {{ value_json.detection.labels }}  --> ['car']

It depends, if you get more than one label you’ll need some kind of loop, otherwise {{ value_json.detection.labels[0] }} will give you the first label in the list without the brackets.

Ive manged to get all the labels. But I still get the labels with surrounding brackets. How to remove them?

It’s a list, so you have to iterate through the entries or join them, try using:
{{ value_json.detection.labels|join(" ") }}

I just setup my own HA instance with the previously shown examples and this looks quite a nice way to see what’s currently going on (downloader + local_file camera config for each ZM camera instance).

However, is there some simple way to make the older alert pictures visible/browseable via HA ?
Currently I have the local_file camera setup + logbook with sensor._alert_desc on the dashboard, but it would of course be nice to be able to browse the old alert descriptions somehow and also see the related & stored picture. Any ideas how to accomplish this ?

Thanks… will try that and see … :vulcan_salute:

Hi!
Well, i kinda solved that issue with some automations…
As I have ZMevents handler installed with object detection I got MQTT.
When MQTT is triggerd I just simlply download the image and mp4 file to HA.

See this:

alias: ZM_Mot_Parkering
description: ''
trigger:
  - platform: state
    entity_id: sensor.zm_3_eventid
condition: []
action:
  - service: downloader.download_file
    data:
      url: >-
        https://my_secret_domain/zm/index.php?view=image&eid={{
        states('sensor.zm_3_eventid')
        }}&fid=objdetect&username=ZXZX&password=ZXZXZX
      filename: 3_latest.jpg
      overwrite: true
  - service: downloader.download_file
    data:
      url: >-
        https://my_secret_domain/zm/index.php?view=view_video&eid={{
        states('sensor.zm_3_eventid') }}&username=XCXCXC&password=ZXZXZXZX
      filename: 3_latest.mp4
      overwrite: true
mode: single

This script reacts upon zm event id, when it changes it downloads the snapshot and mp4 file and store it in a folder accessible from HA.

You could change the filename so it even saves the timestamp and then do actions upon that.
I’ve made a dashboard with the latest objects detected…
image

Thanks for the example! Can you describe/show, how did you implement the dashboard with the latest objects ? If I already have the pics and videos downloaded, I’m interested about which card/config you use to make them accessible via HA ?

I use a sensor like this:

- platform: mqtt
  state_topic: "zoneminder/1"
  name: "Detected Objects"
  qos: 0
  value_template: "{{ value_json.detection[0].label }}"
  json_attributes_topic: "zoneminder/1"
  json_attributes_template: "{{ value_json.detection[0] }}"

What I was trying to implement is a list of past events & related alarm event pictures in addition to the current/latest event. Unfortunately, it seems that the current picture cards don’t seem to support multiple local pictures / url’s in a card or a list of local files / urls in the card. At least I didn’t find an easy way to implement this for now.

It would be so much easier to quickly browse through the latest event’s in HA, instead of switching to ZM’s Event list web-page.

Revised the value_template.

  value_template: >
    {% set data = namespace(entities=[]) %}
    {% for detected in value_json.detection %}
    {% set data.entities = data.entities + [detected.label] %}
    {% endfor %}
    {{ data.entities | join(",") }}

Result:
image

1 Like

Thanks! That’s much nicer… :slight_smile:

Is this still working for you guys? I only seem to be able to parse the name, which at least gets me notifications under the 255 character limit. When I try anything like [detected.label] or “{{ value_json.detection[0].label }}” I get errors like the one attached

. Before anyone asks, I tried “label” first but it said it didn’t exist, but when I checked the full notification (before parsing anything) there did seem to be a dictionary for “labels”.

ie (output with no parsing):

ERROR (MainThread) [homeassistant.util.logging] Exception in message_received when handling msg on ‘zoneminder/2’: ‘{“eventtype”:“event_start”,“hookvalue”:“0”,“state”:“alarm”,“eventid”:“500”,“monitor”:“2”,“detection”:{“image_dimensions”:{“original”:[1944,2592],“resized”:[600,800]},“confidences”:[0.985492706298828,0.94365668296814],“frame_id”:“snapshot”,“boxes”:[[138,248,216,468],[504,38,546,168]],“labels”:[“person”,“person”]},“name”:“Driveway:(500) [s] detected:person:99% Linked”}’

change it to {{ value_json.detection[0].labels }}

Now I am worried that I have missed a step or something:

Template variable error: list object has no element 0 when rendering ‘{{ value_json.detection[0].labels }}’

Oops the format changed slightly more try:
{{ value_json.detection.labels }}

OR

{{ value_json.detection.labels|join(",") }}
will make the list separated by commas.

Thanks firstof9, this worked for me. I was confused at first (because it was late and I can be dumb), I was getting intermittent dict and list errors, but then I realized that was happening on events that didnt get objects and thus didnt have labels. Every event that has objects detected is working perfectly

1 Like

ohh I’m still having issues - no mqtt coming through.

using dlandon/zoneminder:latest

Do I need to rebuild it with just Yolov4 rather than Yolov3 also? Just the latest?
Everything else seems to be fine I think.
Do you see anything wrong here? running on a container on proxmox. portainer added also.

# sudo -u www-data /usr/bin/zmeventnotification.pl --debug
INF:2021-12-09,15:36:39 PARENT: using config file: /etc/zm/zmeventnotification.ini
12/09/21 15:36:39.793647 zmeventnotification[963].INF [main:985] [PARENT: using config file: /etc/zm/zmeventnotification.ini]
INF:2021-12-09,15:36:39 PARENT: using secrets file: /etc/zm/secrets.ini
12/09/21 15:36:39.806064 zmeventnotification[963].INF [main:985] [PARENT: using secrets file: /etc/zm/secrets.ini]
DBG-2:2021-12-09,15:36:39 PARENT: Got secret token !ZMES_PICTURE_URL
DBG-2:2021-12-09,15:36:39 PARENT: Got secret token !ZM_USER
DBG-2:2021-12-09,15:36:39 PARENT: Got secret token !ZM_PASSWORD
DBG-3:2021-12-09,15:36:39 PARENT: config string substitution: {{base_data_path}} is '/var/lib/zmeventnotification'
DBG-3:2021-12-09,15:36:39 PARENT: config string substitution: {{base_data_path}} is '/var/lib/zmeventnotification'

Configuration (read /etc/zm/zmeventnotification.ini):

Secrets file.......................... /etc/zm/secrets.ini
Base data path........................ /var/lib/zmeventnotification
Restart interval (secs)............... (undefined)

Use admin interface .................. yes
Admin interface password.............. (defined)
Admin interface persistence file ..... /var/lib/zmeventnotification/misc/escontrol_interface.dat

Port ................................. 9002
Event check interval ................. 5
Monitor reload interval .............. 300
Skipped monitors...................... (undefined)

Auth enabled ......................... yes
Auth timeout ......................... 20

Use API Push.......................... no
API Push Script....................... (undefined)

Use FCM .............................. yes
Use FCM V1 APIs....................... yes
FCM Date Format....................... %I:%M %p, %d-%b
Only show latest FCMv1 message........ no
Android FCM push priority............. default

Token file ........................... /var/lib/zmeventnotification/push/tokens.txt

Use MQTT ............................. yes
MQTT Server .......................... 192.168.1.163
MQTT Topic ........................... zoneminder
MQTT Username ........................ xxxxxxx
MQTT Password ........................ (defined)
MQTT Retain .......................... yes
MQTT Tick Interval ................... 15
MQTT TLS CA ........................ (undefined)
MQTT TLS Cert ........................ (undefined)
MQTT TLS Key ........................ (undefined)
MQTT TLS Insecure ........................ no

SSL enabled .......................... no
SSL cert file ........................ /etc/apache2/ssl/zoneminder.crt
SSL key file ......................... /etc/apache2/ssl/zoneminder.key

Verbose .............................. yes
ES Debug level.........................4
Read alarm cause ..................... yes
Tag alarm event id ................... yes
Use custom notification sound ........ no
Send event start notification..........yes
Send event end notification............no
Monitor rules JSON file................(undefined)

Use Hooks............................. no
Hook Script on Event Start ........... '/var/lib/zmeventnotification/bin/zm_event_start.sh'
User Script on Event Start.............(undefined)
Hook Script on Event End.............. '/var/lib/zmeventnotification/bin/zm_event_end.sh'
User Script on Event End.............(undefined)
Hook Skipped monitors................. (undefined)

Notify on Event Start (hook success).. all
Notify on Event Start (hook fail)..... none
Notify on Event End (hook success).... fcm,web,api
Notify on Event End (hook fail)....... none
Notify End only if Start success...... yes

Use Hook Description.................. yes
Keep frame match type................. yes
Store Frame in ZM......................yes

Picture URL .......................... https://192.168.1.245:443/zm/index.php?view=image&eid=EVENTID&fid=objdetect&width=600
https://192.168.1.245:443/zm/index.php?view=image&eid=EVENTID&fid=snapshot&width=600
Include picture....................... yes
Picture username ..................... xxxxx
Picture password ..................... (defined)