Hi,
I want to share what i’m using for get zoneminder (https://www.zoneminder.com) alarm events in HA.
Zoneminder is really good in motion detect and i have been using this solution for a lot of time so now that i’m using HA I needed to integrate the ZM with HA.
Zoneminder alerts in HA
With this integration is possible to get alerts by motion that are generated in ZM for automations in HA.
For achieve this i have use the zmeventnotification server (https://github.com/pliablepixels/zmeventserver) developed by pliablepixels to push notifications from ZM in zmninja (http://pliablepixels.github.io).
This server sends the events from ZM through a WSS server so I have modified this for put events into a MQTT broker, this is my modified version: https://github.com/gonzalezcalleja/zmeventserver/blob/master/zmeventnotification.pl
Also I have created this sensors in HA (one for each monitor in ZM)
- platform: mqtt
state_topic: "zoneminder/7"
name: ZM Cam1
qos: 0
value_template: '{% if value_json.state == "alarm" %} on {% else %} off {% endif %}'
The format for broker topic name is zoneminder/<zm monitor id>
This modified version of zmeventserver only send alerts so it is necessary to create an automation for put the sensor “off” after the alarm state (one for each camera):
- alias: 'Alert from ZM cam1'
trigger:
- platform: state
entity_id: sensor.zm_cam1
state: 'on'
action:
- service: mqtt.publish
data:
topic: 'zoneminder/7'
payload: '{"state":"noalarm"}'
- service: alarm_control_panel.alarm_trigger
entity_id: alarm_control_panel.alarma
View and Change Zoneminder run state in HA
With the ZM run state is possible to setup differents configurations, for example:
- run state “OnHouse”: In this states all internal cameras are in monitor mode and the external cameras are in detect mode.
- run state “OutOfHouse”: In this state all cameras are in detect mode
- etc …
For change the ZM run states from HA like this:
Create this input_select
input_select:
zm_detect_mode:
name: VideoVigilancia
options:
- Solo Exterior
- Solo Entrada
- Interior y Exterior
- Solo Interior
- Desactivada
initial: Solo Exterior
icon: mdi:webcam
Create this sensor
- platform: command_line
name: ZM state
command: "/etc/home-assistance/zm/getstate.sh"
This is the getstate.sh content:
#!/bin/bash
zmdbuser=`cat /etc/zm/zm.conf | grep ZM_DB_USER | awk -F= '{print $2}' | tr -d ' '`
zmdbpass=`cat /etc/zm/zm.conf | grep ZM_DB_PASS | awk -F= '{print $2}' | tr -d ' '`
runstate=`mysql -N -B -u$zmdbuser -p$zmdbpass zm -e "select Name from States where isActive=1 LIMIT 1;"`
echo $runstate
Create this automation for change the input_select value:
- alias: 'Cambia sensor de ZM'
trigger:
- platform: state
entity_id: sensor.zm_state
action:
- service: input_select.select_option
entity_id: input_select.zm_detect_mode
data_template:
option: >
{% if is_state('sensor.zm_state', 'Exterior') %}
Solo Exterior
{% elif is_state('sensor.zm_state', 'Entrada') %}
Solo Entrada
{% elif is_state('sensor.zm_state', 'ExteriorInterior') %}
Interior y Exterior
{% elif is_state('sensor.zm_state', 'Interior') %}
Solo Interior
{% elif is_state('sensor.zm_state', 'Desactivada') %}
Desactivada
{% else %}
{% endif %}
Create this automation for change the zm run status (one for each ZM run state)
- alias: 'Cambiar tipo de Videovigilancia a Exterior'
trigger:
- platform: state
entity_id: input_select.zm_detect_mode
to: 'Solo Exterior'
action:
- service: shell_command.set_zm_alarm_exterior
Create this shell_command (one for each ZM run state):
set_zm_alarm_exterior: '/usr/bin/zmpkg.pl Exterior'
set_zm_alarm_entrada: '/usr/bin/zmpkg.pl Entrada'
set_zm_alarm_exterior_interior: '/usr/bin/zmpkg.pl ExteriorInterior'
set_zm_alarm_interior: '/usr/bin/zmpkg.pl Interior'
set_zm_alarm_desactivada: '/usr/bin/zmpkg.pl Desactivada'