[Solved] ZoneMinder MQTT to HA

I’m new to MQTT and will probably need a butt kick in the right direction here… :wink:

I have the ZoneMinder integration working but would like to use MQTT to be able to notify new events with image.
I have tried both the Event Notification Server (without hooks) and the built in MQTT support in ZoneMinder 37, but no luck.
I cant see any errors in any logs, or any signs of information sent from ZM or received in HA.

I have installed the Mosquitto broker in HA and added a new user under Settings/Persons/Users for ZM to use.
If I publish a test packet from the MQTT integration it shows up in the listening section below.

It feels like I have missed something fundamental here.
I have HA and ZM on virtual machines on the local network.
I use the local IP for HA as the MQTT server adress on port 1883, and the username and password I created i HA.

As I mentioned, need a butt kick in the right direction here…

Is there some reason you can’t use the zoneminder integration?

As I understand it’s not possible to get the actual event number from the ZoneMinder integration, only the different summarized numbers of events.
Or is it possible to do that?

I don’t know frankly, so let’s see about your mqtt.

If you enter the zm vm, can you access the mqtt broker? Try

mosquitto_sub -u user -P passwd -h ipofha -t '#'

I looked for the zm mqtt docs. There are none. Looks like it isn’t finished

https://forums.zoneminder.com/viewtopic.php?p=131065&hilit=Mqtt#p131065

Yes, I have read that. It’s not finished, but I tried it as an alternative as iconnor says “Last I looked it worked, but you have to realise that I just roughed in the bare elements” hoping it should spit out something, but nope…

Anyway, did you compile mqtt into zm?

Have you tried what I suggested above?

I have installed ZM master (v37.40) following the Installation Guide and today updated it to 37.41.
I have not installed any specific for MQTT in ZM outside that guide.

The Event Server was installed following Installation of the Event Server (ES)
As remember I installed the stable version, but now I’m not 100% sure… How can I check that?

I tried the mosquitto_sub command, but it was not found. I suppose that means I don’t have the Mosquitto package installed on the ZM/ES vm. Is that a requirement?
The only MQTT related installation I have done is this, as a part of the ES installation.

perl -MCPAN -e "install Net::MQTT::Simple"

I started the Event Server in debug using
sudo -u www-data /usr/bin/zmeventnotification.pl --debug
and as I understand it looks like I’m on v6.1.28, but it doesn’t find any events.
I have set up a zone around the minute digit to force an alarm every minute, but it looks like ES don’t see it.
The monitor in ZM is set to record on motion and the minimum event time is 10s which should be more than enough for the 5s update in ES.

Here is a snippet from the debug:

07/23/23 00:14:11.149787 zmeventnotification[11681].INF [main:338] [Running on WebSocket library version:0.004]
INF:2023-07-23,00:14:11 PARENT: using config file: /etc/zm/zmeventnotification.ini
07/23/23 00:14:11.211448 zmeventnotification[11681].INF [main:1048] [PARENT: using config file: /etc/zm/zmeventnotification.ini]
INF:2023-07-23,00:14:11 PARENT: using secrets file: /etc/zm/secrets.ini
07/23/23 00:14:11.244919 zmeventnotification[11681].INF [main:1048] [PARENT: using secrets file: /etc/zm/secrets.ini]
DBG-2:2023-07-23,00:14:11 PARENT: Got secret token !ZMES_PICTURE_URL
DBG-2:2023-07-23,00:14:11 PARENT: Got secret token !ZM_USER
DBG-2:2023-07-23,00:14:11 PARENT: Got secret token !ZM_PASSWORD
DBG-2:2023-07-23,00:14:11 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)............... 0

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

Port ................................. 9000
Address .............................. 0.0.0.0
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............. high
Android FCM push ttl.................. (undefined)
Log FCM message ID.................... NONE
Log RAW FCM Messages...................no
FCM V1 URL............................ https://us-central1-ninja-1105.cloudfunctions.net/send_push
FCM V1 Key.............................default
 
Token file ........................... /var/lib/zmeventnotification/push/tokens.txt

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

SSL enabled .......................... yes
SSL cert file ........................ /etc/zm/apache2/ssl/cert1.pem
SSL key file ......................... /etc/zm/apache2/ssl/privkey1.pem

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............yes
Monitor rules JSON file................(undefined)

Use Hooks............................. no
Max Parallel Hooks.................... 0
Hook Script on Event Start ........... '/var/lib/zmeventnotification/bin/zm_event_start.sh'
User Script on Event Start.............(undefined)
Hook Script on Event End.............. (undefined)
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://portal/zm/index.php?view=image&eid=EVENTID&fid=objdetect&width=600
Include picture....................... yes
Picture username ..................... ZMES
Picture password ..................... (defined)

INF:2023-07-23,00:14:11 PARENT: Push enabled via FCM
07/23/23 00:14:11.431441 zmeventnotification[11681].INF [main:1048] [PARENT: Push enabled via FCM]
DBG-2:2023-07-23,00:14:11 PARENT: fcmv1: --> FCM V1 APIs: 1
INF:2023-07-23,00:14:11 PARENT: MQTT Enabled
07/23/23 00:14:11.447372 zmeventnotification[11681].INF [main:1048] [PARENT: MQTT Enabled]
INF:2023-07-23,00:14:11 PARENT: |------- Starting ES version: 6.1.28 ---------|
07/23/23 00:14:11.460139 zmeventnotification[11681].INF [main:1048] [PARENT: |------- Starting ES version: 6.1.28 ---------|]
DBG-2:2023-07-23,00:14:11 PARENT: Started with: perl:/usr/bin/perl and command:/usr/bin/zmeventnotification.pl
Can't ignore signal CHLD, forcing to default.
DBG-1:2023-07-23,00:14:11 PARENT: ES invoked manually. Will handle restarts ourselves
DBG-2:2023-07-23,00:14:11 PARENT: Parent<--Child pipe ready
INF:2023-07-23,00:14:11 PARENT: Event Notification daemon v 6.1.28 starting

07/23/23 00:14:11.631080 zmeventnotification[11681].INF [main:1048] [PARENT: Event Notification daemon v 6.1.28 starting]
DBG-1:2023-07-23,00:14:11 PARENT: Initializing FCM tokens...
INF:2023-07-23,00:14:11 PARENT: Initializing MQTT with auth connection...
07/23/23 00:14:11.643417 zmeventnotification[11681].INF [main:1048] [PARENT: Initializing MQTT with auth connection...]
DBG-1:2023-07-23,00:14:11 PARENT: Intialized MQTT with auth
DBG-1:2023-07-23,00:14:11 PARENT: Total event client connections: 1

DBG-1:2023-07-23,00:14:11 PARENT: -->checkNewEvents: Connection 1: ID-> IP->(none) Token->:... Plat: Push:
INF:2023-07-23,00:14:11 PARENT: Re-loading monitors
07/23/23 00:14:11.658256 zmeventnotification[11681].INF [main:1048] [PARENT: Re-loading monitors]
DBG-2:2023-07-23,00:14:11 PARENT: ESCONTROL_INTERFACE is disabled. Not saving control data
DBG-2:2023-07-23,00:14:11 PARENT: checkEvents() new events found=0
DBG-2:2023-07-23,00:14:11 PARENT: About to start listening to socket
INF:2023-07-23,00:14:11 PARENT: Secure WS(WSS) is enabled...
07/23/23 00:14:11.677452 zmeventnotification[11681].INF [main:1048] [PARENT: Secure WS(WSS) is enabled...]
INF:2023-07-23,00:14:11 PARENT: Web Socket Event Server listening on port 9000
07/23/23 00:14:11.691270 zmeventnotification[11681].INF [main:1048] [PARENT: Web Socket Event Server listening on port 9000]
DBG-2:2023-07-23,00:14:16 PARENT: ----------> Tick START (active forks:0, total forks:0, active hooks: 0 running for:1 min)<--------------
DBG-2:2023-07-23,00:14:16 PARENT: After tick: TOTAL: 1,  ES_CONTROL: 1, FCM+WEB: 0, FCM: 0, WEB: 0, MQTT:1, invalid WEB: 0, PENDING: 0
DBG-2:2023-07-23,00:14:16 PARENT: There are 0 active child forks & 0 zm_detect processes running...
DBG-2:2023-07-23,00:14:16 PARENT: checkEvents() new events found=0
DBG-2:2023-07-23,00:14:16 PARENT: There are 0 new Events to process
DBG-2:2023-07-23,00:14:16 PARENT: ---------->Tick END (active forks:0, total forks:0, active hooks: 0)<--------------
DBG-2:2023-07-23,00:14:21 PARENT: ----------> Tick START (active forks:0, total forks:0, active hooks: 0 running for:1 min)<--------------
DBG-2:2023-07-23,00:14:21 PARENT: After tick: TOTAL: 1,  ES_CONTROL: 1, FCM+WEB: 0, FCM: 0, WEB: 0, MQTT:1, invalid WEB: 0, PENDING: 0
DBG-2:2023-07-23,00:14:21 PARENT: There are 0 active child forks & 0 zm_detect processes running...
DBG-2:2023-07-23,00:14:21 PARENT: checkEvents() new events found=0
DBG-2:2023-07-23,00:14:21 PARENT: There are 0 new Events to process
DBG-2:2023-07-23,00:14:21 PARENT: ---------->Tick END (active forks:0, total forks:0, active hooks: 0)<--------------
DBG-2:2023-07-23,00:14:26 PARENT: ----------> Tick START (active forks:0, total forks:0, active hooks: 0 running for:1 min)<--------------
DBG-2:2023-07-23,00:14:26 PARENT: After tick: TOTAL: 1,  ES_CONTROL: 1, FCM+WEB: 0, FCM: 0, WEB: 0, MQTT:1, invalid WEB: 0, PENDING: 0
DBG-2:2023-07-23,00:14:26 PARENT: There are 0 active child forks & 0 zm_detect processes running...
DBG-2:2023-07-23,00:14:26 PARENT: checkEvents() new events found=0
DBG-2:2023-07-23,00:14:26 PARENT: There are 0 new Events to process
DBG-2:2023-07-23,00:14:26 PARENT: ---------->Tick END (active forks:0, total forks:0, active hooks: 0)<--------------

I think you’d be better going to the zm forums, we’re getting very specific to zm.

Some progress here!! :smiley:
Found this: Encourage people to pick the master branch
After updating to the latest master branch, not the latest stable, version of Event Server it find the events in ZM and the MQTT messages are now sent and received by the broker and showed up in HA.
Now I can go to sleep… 01:35… :grinning_face_with_smiling_eyes: :sleeping:

1 Like