Zoneminder Event Server Notification Anouncments

Tags: #<Tag:0x00007f326b9125b8>

This is my automation, it announced when zmeventnotification detects something or someone.

- id: '1603752449417'
  alias: Zoneminder Advertises
  description: ''
  trigger:
  - platform: mqtt
    topic: zoneminder/1
  condition: []
  action:
  - service: tts.google_translate_say
    entity_id: media_player.cozinha
    data:
      message: Frontal camera detected {{trigger.payload_json.detection.0.label}}
  mode: queued
  max: 10

the mqtt message is something like this

'{"name":"Frontal:(1584) [a] detected:person:52%  Motion Entrada","hookvalue":"0","state":"alarm","detection":[{"confidence":"99.11%","box":[6,226,316,456],"label":"car","type":"object"},{"type":"object","label":"person","box":[265,565,427,677],"confidence":"52.37%"}],"monitor":"1","eventtype":"event_start","eventid":"1584"}'

Note that trigger.payload_json.detection is an array. At my automation, I am only announcing the first object. How can I iterate over the array to announce all the objects?

Can you make the message a template or use a template sensor to generate the text?

Use date_template rather than data and make the message a JINJA statement, e.g.

- id: motion_detected_person_speak
  alias: motion_detected_person_speak
  description: 'Speak then person detected'
  trigger:
    - platform: state
      entity_id: sensor.motion_detected_person_when
  condition:
    condition: template
    value_template: >
      {{ is_state('input_boolean.motion_detected_person_notify','on') }}
  action:
    - service: tts.google_translate_say
      entity_id: media_player.default
      data_template: 
        mode: queued
        max: 10
        message: >-
          Detected {{ states('sensor.motion_detected_person_count') }} person(s)
          from {{ states('sensor.motion_detected_person_camera') }}

Thanks @dcmartin, I am using templates. My final code looks like this, case somebody needs to do similar stuff.

- alias: Zoneminder Announces Camera Detections
  description: ''
  trigger:
  - platform: mqtt
    topic: zoneminder/#
  action:
  - service: tts.google_translate_say
    entity_id: media_player.cozinha
    data_template:
      message: >
        {% set monitor_names={"1": "Frontal", "3": "Backyard"}  %}
        {{ monitor_names[trigger.payload_json.monitor] }} camera detected {{ trigger.payload_json.detection|map(attribute='label')|join(', ') }}
  mode: queued
  max: 10

- alias: Zoneminder Notify Camera Detections
  description: ''
  trigger:
  - platform: mqtt
    topic: zoneminder/#
  condition: []
  action:
  - service: notify.telegram
    data_template:
      message: >
        {% set monitor_names={"1": "Frontal", "3": "Backyard"}  %}
        {{ monitor_names[trigger.payload_json.monitor] }} camera detected {{ trigger.payload_json.detection|map(attribute='label')|join(', ') }}
  mode: queued
  max: 10
2 Likes

I’ve been struggling with ZM for a time now… But you lite snippet of code did my day!
Big thanks for posting this!

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

Screenshot 2021-01-03 212639

Happy to know, @Minglarn. I am curious, what your automation is all about? The picture caught me…

Well, frankly it started with just an idea…
I’ve object detection running on all of my 9 cams.
But 4 off them are facing the road and the entrance of my house.
I do get notifications with the info from pushover with the same image as shown on my dashboard.

I was searching for a way to let HA know WHO and WHAT made my cameras trigger a motion.
Let’s say that my entrance cam reconices my son at the entrance door, well i’ll get a notification that my son is home (i know you can do this with other solutions (like Life360), but on iOS they are hard to keep running).

I just wanted to show the latest known object frames from each camera to be shown on the dashboard, and upon detected object do an action.