Absolutely. Super simple do with pyzm. Here is the full code that lists only events detected with objects from all monitors for the last 1 day. You can easily integrate this with a card.
import pyzm.api as zmapi
api_options = {
'apiurl': 'https://yourserver/zm/api',
'portalurl': 'https://yourserver/zm',
'user': 'admin',
'password': 'password',
'logger': None # use none if you don't want to log to ZM
}
zmapi = zmapi.ZMApi(options=api_options)
event_filter = {
'from': '1 day ago', # this will use localtimezone, use 'tz' for other timezones
'object_only':True,
}
events = zmapi.events(event_filter)
for e in events.list():
print ('Monitor:{} Event:{} Notes:{} Detected Frame URL:{}'.format(e.monitor_id(),e.id(),e.notes(), e.get_image_url(fid='objdetect')))
Is there an easy way of creating a sensor based on the mqtt data from zoneminder… I’m thinking a person detected sensor that simply shows the time and date the last time a person was detected… it could work like motion sensors showing no detection by default and detected when a person is seen. I’m new to mqtt so feel a bit lost here
The mqtt topics are enabled via configuring the ES (event server). The topic is based on the monitor id e.g. 1 in my example. I break out the event id field, you can use this as a trigger given zoneminder increments the event id as it generates motion events.
I cracked it in the end by writing an app for the app daemon. I set up a virtual pir sensor and powered it using my code so it came “on” for 30 seconds every time a person is detected… I posted about it under the configuration topic on here
I have dlandon’s ZM docker image running on the same server as my docker image of HA. I’ve enabled @pliablepixels ES and have created HA sensors for each of my cameras:
Although I see a lot of work and success with AppDaemon, I have not yet had to install it and am hoping to be able to avoid this. What I would like is to be able to push the picture from an event as a notification.
Reading the ES documentation, I found that the URL: https://<IPADDRESS>:<PORT>/zm/index.php?view=image&eid=<EVENTID>&fid=objdetect
gives you the picture corresponding to the event_id pushed to the MQTT sensor. I have tried to create a simple bash script to either cURL or wget this image, but have had no success.
Is there an easy way to download the image without having to rely on the pyzim library? Is there no way with either cURL or wget to grab the image?
Thanks! It brought me closer, but I get errors in my HA logs as ZM is using a self-signed certificate. It seems the downloader integration chokes on these…
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/urllib3/connectionpool.py", line 670, in urlopen
httplib_response = self._make_request(
File "/usr/local/lib/python3.8/site-packages/urllib3/connectionpool.py", line 381, in _make_request
self._validate_conn(conn)
File "/usr/local/lib/python3.8/site-packages/urllib3/connectionpool.py", line 978, in _validate_conn
conn.connect()
File "/usr/local/lib/python3.8/site-packages/urllib3/connection.py", line 362, in connect
self.sock = ssl_wrap_socket(
File "/usr/local/lib/python3.8/site-packages/urllib3/util/ssl_.py", line 397, in ssl_wrap_socket
return context.wrap_socket(sock)
File "/usr/local/lib/python3.8/ssl.py", line 500, in wrap_socket
return self.sslsocket_class._create(
File "/usr/local/lib/python3.8/ssl.py", line 1040, in _create
self.do_handshake()
File "/usr/local/lib/python3.8/ssl.py", line 1309, in do_handshake
self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate (_ssl.c:1123)
I was able to edit the Downloader integration so that it did not balk at self-signed certificates. The file in question is /usr/src/homeassistant/homeassistant/components/downloader/__init__.py. Line 78, change req = requests.get(url, stream=True, timeout=10) to req = requests.get(url, stream=True, timeout=10, verfiy=False). When you restart HA, all will be good.
I was going to see if I could figure out how to put in a PR, however this did not solve my problem as the file downloaded from https://<ZMIP>:<ZMPORT>/zm/index.php?view=image&eid=<eventID>&fid=objdetect was the html login form, not an image. For whatever reason, HA was not authenticated against ZM.
Looks like I am going to have to go the AppDaemon route–thanks for your help!
Well that was too obvious, thanks! I will look into how to go about submitting an official PR to the Downloader integration to ignore self-signed certs.
Can anyone help me with getting ES sending MQTT messages, I’m using the dlandon docker container, ZM is working correctly, the ES is also running but I’m not getting any MQTT messages from events so I’m guessing it’s my zmeventnotification.ini that’s wrong.
My docker container is set to use port 2080>9000
Do I need to change that in the ini to 2080 or leave it as 9000?
I have
push off
FCM off
MQTT on, server set to 192.168.1.3 (do I need the port)
No MQTT username or password
SSL set to off
Hooks set to off
I must be missing something or doing something wrong here.
Hi, my reply could be late, but still better than never
As workaround (not a good from security point of view, since credentials will be part of URL) You can get the picture from ZM by providing credentials in the URL https://<ZMIP>:<ZMPORT>/zm/index.php?view=image&eid=<eventID>&fid=objdetect& username=<ZMUser>&password=<ZMPass>&
I think it’s acceptable if HA and ZM servers are not available from outside.
I run hassio in a docker container and the dlandon ZM container. I was having similar issues of not receiving mqtt messages. The issue (I think) was the event server wasn’t able to connect to the MQTT broker.
Pretty sure I fixed it by adding the dlandon ZM container to the hassio docker network.
My current issue is i’m receiving the mqtt messages when an event happens but they’re very generic messages. They appear to come from the default zone setup in ZM and not any sort of object detection. Also none of the events in ZM have anything related to object detection.
In zmeventnotification.ini - i’m not using ssl. I have auth enabled, port 9000, fcm enable, mqtt enable,
I’m using the dlandon container with the following environment variables