Zoneminder event - Automation trigger

Hi all,

I have ZM properly configured in HASS, and can see the live video feed, the status of the monitor, and the amount of events.
I am simply trying to create an automation trigger when the event count increases, but can’t find a way to get it done.
Sounds pretty simple:
Trigger: If eventcount = eventcount+1
Action: fire notification.

I have no problem with the notification, only the trigger.
Thanks all!

If you can provide details of what the zoneminder sensor entity looks like that would help. E.g., go to the Templates page and in the template editor enter:

{{ states.sensor.xxx }}

where, of course, you replace xxx with the appropriate name from your zoneminder sensor.

Taking a stab here in the meantime:

- alias: ZM eventcount increased
  trigger:
    - platform: state
      entity_id: sensor.zm
  condition:
    - condition: template
      value_template: >
        {{ trigger.to_state.attributes.eventcount|int > trigger.from_state.attributes.eventcount|int }}
  action:
    ...

Thanks for your help.
The answer I get is:

<template state sensor.monitor1_events=3; unit_of_measurement=Events, friendly_name=Monitor-1 Events @ 2018-07-20T20:33:56.621266-04:00>

I will give your value template a try…
I was also looking at creating a variable that I could compare with, but HASS doesn’t seem to have this available.

Another way would be to reset the event to 0 every time, and trigger when >0.

I may also look into zoneminder uploading the files to an FTP server, and use a folder watch to send mqtt messages for HASS (I had done this directly with the camera which worked fine, but Zoneminder offers a lot more flexibility in motion detection than the camera itself. Camera will triggers if a bug flies by, ending with tons of false alarms!)

It’s weird that HASS has a Zoneminder component, but has no ability out of the box to notify when events are detected.

Thanks!!

Ok, if the state itself is the count of events, then that changes (and simplifies) things a bit:

- alias: ZM eventcount increased
  trigger:
    - platform: state
      entity_id: sensor.monitor1_events
  condition:
    - condition: template
      value_template: >
        {{ trigger.to_state.state|int > trigger.from_state.state|int }}
  action:
    ...

And if you can reset the count to 0 each time, it gets even simpler:

- alias: ZM eventcount increased
  trigger:
    - platform: numeric_state
      entity_id: sensor.monitor1_events
      above: 0
  action:
    # Put service call that resets count to zero here
    # Followed by whatever other actions you want to do...
    ...

@pnbruckner, thanks for this. I’m trying to adapt what you’ve put here to turn on a light in my garage when motion is detected and off 10 minutes after motion is detected. I can’t figure out the off part. Any suggestions?

Well, that’s a very different use case then what this topic discusses. And what you’re trying to do has probably been discussed in about 4,637 topics on this forum at least! :smile: lol! Of course, with so much discussion, it’s often hard to find a relevant topic and useful answer. :wink:

Anyway, when you ask for help, it’s good to provide some specifics. Like what entity indicates motion, and how does it behave? E.g., is it a binary sensor with only ‘on’ and ‘off’ states, or does it have some numeric value, and if so, what value(s) indicate motion, or maybe something else entirely? How long does it generally stay in the “motion detected” state after it first detects motion? Etc.

But, in general, a common way to do this is to (re)start a script when motion is detected. The script turns the light on, delays the amount you want, and then turns the light off. The idea is, if the automation is triggered again (by new motion) before the time expires, the script (and therefore delay) is restarted.

An alternative method is for the automation that is triggered by motion to turn the light on, then start a timer. Again, if it is triggered again before the timer expires, the timer is restarted. Then you have a second automation that is triggered by the timer expiring, which turns off the light.

If you can provide some of the details I mentioned above, and indicate which approach you prefer, I can give you a more concrete example if you like.

1 Like