Home Assistant integration

Discussions related to the 1.36.x series of ZoneMinder
Post Reply
sh7977
Posts: 1
Joined: Wed Jun 16, 2021 7:54 pm

Home Assistant integration

Post by sh7977 » Wed Jun 16, 2021 7:57 pm

Does anyone have a successful integration with Home Assistant? If so could you post that part of your configuration.yaml?

I'm using this page: https://www.home-assistant.io/integrations/zoneminder/

But, after restarting, I don't see any camera entities.

Bearded_Beef
Posts: 17
Joined: Thu Mar 11, 2021 5:51 pm

Re: Home Assistant integration

Post by Bearded_Beef » Thu Jun 17, 2021 11:07 am

I had to move back to 1.34 due to issues, but this configuration worked on 1.36 for me as well:

Code: Select all

zoneminder:
  - host: !secret zm_host
    path: /zm/
    path_zms: /zm/cgi-bin/nph-zms
    ssl: true
    verify_ssl: false
    username: !secret zm_username
    password: !secret zm_password

Code: Select all

camera:
  - platform: zoneminder
That should be all that's needed to give you the camera entities. The host should be a domain name or straight IP address. Maybe try without SSL if you're having issues, just for troubleshooting purposes. I also make use of zoneminders sensors quite a bit for events, notifications and switches (note the value template portion is only useful if you're using object detection and are looking to parse object based events):

Code: Select all

sensor:
  - platform: zoneminder
    include_archived: true
    monitored_conditions: hour
  - platform: mqtt
    state_topic: "zoneminder/1"
    name: "driveway_alerts"
    value_template: "{{ value_json.detection.labels[0] }}"
    force_update: true
    expire_after: 120

tsp84
Posts: 82
Joined: Thu Dec 24, 2020 4:04 am

Re: Home Assistant integration

Post by tsp84 » Thu Jun 17, 2021 1:27 pm

Doesn't that Jinja only give you the 0 index of the labels dict though? So if you have 2 or more labels it will only show the first one. Couldn't you use a for loop or something to iterate through the indexes of "labels" ?

Bearded_Beef
Posts: 17
Joined: Thu Mar 11, 2021 5:51 pm

Re: Home Assistant integration

Post by Bearded_Beef » Thu Jun 17, 2021 1:35 pm

tsp84 wrote:
Thu Jun 17, 2021 1:27 pm
Doesn't that Jinja only give you the 0 index of the labels dict though? So if you have 2 or more labels it will only show the first one. Couldn't you use a for loop or something to iterate through the indexes of "labels" ?
Good point. I mostly just use HA to throttle the events and I guess I settled on "good enough". But now I *have* to look into that :lol:


That second label would be helpful if you have multiple objects or have facial recognition enabled.

tsp84
Posts: 82
Joined: Thu Dec 24, 2020 4:04 am

Re: Home Assistant integration

Post by tsp84 » Thu Jun 17, 2021 6:34 pm

value_template: "{{ value_json.detection.labels }}"

Will show the full list but not "pretty"

Bearded_Beef
Posts: 17
Joined: Thu Mar 11, 2021 5:51 pm

Re: Home Assistant integration

Post by Bearded_Beef » Thu Jun 17, 2021 8:14 pm

Code: Select all

  value_template: >
    {% set data = namespace(entities=[]) %}
    {% for detected in value_json.detection %}
    {% set data.entities = data.entities + [detected.labels] %}
    {% endfor %}
    {{ data.entities | join(",") }}
This is what I am going to try when I get home. Think it'll work? (I'm script kiddie-ing the crap outta this)

Corvus85
Posts: 26
Joined: Sun Jun 27, 2021 4:12 pm

Re: Home Assistant integration

Post by Corvus85 » Sun Jun 27, 2021 4:19 pm

Hey all,

I'm having similar problems. This is incredibly difficult for me because I haven't ever done any programming before.

Despite this, I've managed to edit my config file and my HA logs show no issues with ZM. However, I can't see any sensors or switches for zoneminder anywhere, even after multiple restarts.

I've got ZM and Frigate installed in Dockers on my Unraid server, and my HA is running on a VM inside that same server.

This is my current config.

Code: Select all

zoneminder:
  - host: 192.168.0.20:8443
    ssl: true
    verify_ssl: false
    username: XXXXXXXX
    password: XXXXXXXXX
sensor:
  - platform: zoneminder
    include_archived: true
switch:
  - platform: zoneminder
    command_on: Record
    command_off: Monitor
Basically I just want to be able to use Frigate's person/object detection as a trigger to start recording on ZM. When Frigate doesn't detect anything, all I want ZM to do is to monitor the cameras - no motion detection. I don't even need to display any cameras in HA, because I've got that covered with ZMninja.

So how can I make this work?

Bearded_Beef
Posts: 17
Joined: Thu Mar 11, 2021 5:51 pm

Re: Home Assistant integration

Post by Bearded_Beef » Wed Jun 30, 2021 4:04 pm

I ended up scrapping this whole thing, fwiw. I got the events to work the way that I liked and then had a power outage. It took down HA but I have ZM on a UPS so I was able to graciously shut down. When everything came back up MQTT wasn't working consistently, and I noticed that I was no longer getting events in ZM anymore. I disabled MQTT and events started working again. Maybe something screwy happened, but this is my security system and I just don't want multiple points of failure on it.

tsp84
Posts: 82
Joined: Thu Dec 24, 2020 4:04 am

Re: Home Assistant integration

Post by tsp84 » Thu Jul 01, 2021 2:28 am

My biggest problem is that Home Assistant keeps throwing a log error for 'State longer than 255 characters' and I wanted mqtt cameras to work with the detected object image/gif. I send the image to home assistant to let it decide if it sends a pushover push based on certain conditions etc.

I ended up coding an mqtt addon into the object detect python stuff, it sends the objectdetect.jpg (or .gif) if there is one and alarm/snapshot if no objectdetect image/gif. It hooks into the settings in zmeventnotification.ini [mqtt] section, supports secure/insecure (verified host/CN) TLS, mTLS and is fairly easy to configure and play with.

Code: Select all

06/30/21 20:11:43.12014 ZMLog[DBG1] zm_detect:800->[zm_detect:mqtt: constructing object... ]

06/30/21 20:11:43.130204 ZMLog[DBG1] mqtt:83->[mqtt:init: image to be used is: /nvr/4/2021-06-30/13329/objdetect.gif]

06/30/21 20:11:43.134501 ZMLog[DBG2] mqtt:119->[mqtt:connect: connecting to hassio.homelab:8883]

06/30/21 20:11:43.136384 ZMLog[DBG1] mqtt:129->[mqtt:connect: trying mTLS -> tls_ca: /nas/mqtt_certs/ca.crt tls_client_key: /nas/mqtt_certs/client.key tls_client_cert: /nas/mqtt_certs/client.crt]

06/30/21 20:11:43.148675 ZMLog[DBG2] mqtt:156->[mqtt:connect: waiting for broker to reply (timeout: 10)]

06/30/21 20:11:43.155706 ZMLog[DBG1] mqtt:62->[mqtt:connect: connected to broker]

06/30/21 20:11:43.249974 ZMLog[DBG2] mqtt:180->[mqtt:publish: sending -> topic: zmes/picture/4  data: <serialized bytearray>  size=1.18 MB]

06/30/21 20:11:43.252573 ZMLog[DBG2] mqtt:177->[mqtt:publish: sending -> topic: 'zmes/picture/notify/4' data: 'on']

06/30/21 20:11:43.254076 ZMLog[DBG2] mqtt:177->[mqtt:publish: sending -> topic: 'zmes/data/4' data: '{"monitor": "4", "name": "[s76] detected:person(98%) Motion: Walkway", "eventid": "13329"}']

06/30/21 20:11:43.256266 ZMLog[DBG2] mqtt:177->[mqtt:publish: sending -> topic: 'zoneminder/4' data: '{"detection": "{\"labels\": [\"person\"], \"boxes\": [[298, 132, 350, 264]], \"frame_id\": \"76\", \"confidences\": [0.9778180718421936], \"image_dimensions\": {\"original\": [1080, 1920], \"resized\": [450, 800]}}"}']

06/30/21 20:11:43.257878 ZMLog[DBG2] mqtt:192->[mqtt:close: disconnecting from mqtt broker: hassio.homelab:8883]

06/30/21 20:11:43.272583 ZMLog[DBG2] zm_detect:817->[perf: 4-->13329: total:7.325458 sec detection:3.410899 sec writing images/animations:3.914512 sec mqtt:0.152398 sec]

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests