Trigger Automation When Integer Increases

Im attempting to setup Zoneminder with alerts integrated via HA. The issue I’m having is that the trend sensor is not valid. Zoneminder simply increases event count each time there is motion detected, however this value never resets. If i have 1 event, then events stays at 1. When events increase from 0 to 1, the trend sensor turns on. Since event stays at 1, the trend never resets to off. When events go from 1 to 2, the sensor is pointless because it has been on since the first event. Trend would only be useful if zoneminder reset events to 0, but that would mean deleting events within ZoneMinder (which i do not wish to do as that has the recording).

What I’m looking is for a way to monitor the integer value of:
states.sensor.zmLivingRoom.state

If the value increases, I’d like to trigger an automation to alert me. Once it increases again, after a certain rest period, alert again.

I have found this is not as easy and straight forward as I’d hoped it to be. Currently the sensor looks like this:

sensor.lrcam_events.state: 4

I’m thinking one way to achieve this would be to create an input_number, immediately set it equal to sensor.lrcam_events.state, and then each time it increases, reset the input_number. I could then do constant checks against input_number.lrcam_events.state and if the former is > the latter, trigger an alert.

Is there not an easier way?

This will trigger every time the sensor changes:

trigger:
  platform: state
  entity_id: sensor.zmLivingRoom

Compare its current state:

trigger.to_state.state

to its previous state:

trigger.from_state.state

EDIT

Something like this:

- alias: 'alert when increasing'
  trigger:
    platform: state
    entity_id: sensor.sensor.zmLivingRoom
  condition:
    condition: template
    value_template: '{{ trigger.to_state.state | int > trigger.from_state.state | int }}'
  action:
    service: notify.notify
    # etc ...
15 Likes