Mobile notification in case of repeated power drop down

Dear Community,

I would like to get a mobile notification in case of the power of my water pump drops 10 times or more in a hour. My basic script looks like this and I stucked at this point. Every assistance greatly welcome.

triggers:
  - trigger: numeric_state
    entity_id:
      - sensor.water_pump_power
    for:
      hours: 0
      minutes: 0
      seconds: 1
    below: 100
conditions: []
actions:
  - action: notify.mobile_app_iphone
    metadata: {}
    data:
      message:Water pump shut down

You will probably need to create a “counter” entity to keep track of the number of times the power has dipped. To do this for a rolling 1-hour window can be tricky, as an ordinary counter entity probably won’t work. Your automation entity would work, but unfortunately automation triggerings are not states, they are attributes, making it a bit harder to track.

The easiest approach may be to create two entities: a template binary_sensor that turns TRUE whenever your automation runs (i.e. its current attribute > 0), and a history_stats sensor tracking the count of that binary sensor for the past 60 minutes.

template:
  - binary_sensor:
    - name: "Power Drop Automation Running"
      state: >-
        {{ state_attr('automation.automation_name','current') > 0 }}

sensor:
  - platform: history_stats
    name: “Count Power Drops Prev 60min”
    entity_id: binary_sensor.power_drop_automation _running
    state: "on"
    type: count 
    end: "{{ now() }}"
    duration: “01:00”

(It should be possible to do this with a single entity using the SQL integration to query the recorder database directly, but I’d need to be at my desk to figure that SQL code.)

Either way, your automation, just like you have above, will trigger every time the power drops, allowing your stats/sql counter to keep track of the number of times it is happening. But in the actions, add an IF condition that only sends a notification when the counter sensor =10.

1 Like