Power Notifications

Greetings,

I am having some issues trying to determine how to build out an automation to accomplish this task.

I have sensors in homeassistant that log power usage of certain circuits that I would like to alert on, specifically my well pump. When the Well pump has been going on and off (not a constant on, but fluctuating frequently between a on and off state) for a prolonged period of time. This could potentially indicate a leak. What would be the proper method to alert on this?

in a automation

trigger:
  plateform: state
  entity_id: the pump entity id name

so this will trigger when it goes ON and OFF

but

trigger:
  plateform: state
  entity_id: the pump entity id name
  to: 'on'

will only trigger when change to on

now the Action what do we want to happen when this trigger happens

  action:
  - data_template:
      title: "Home Assistant"
      message: "{{ trigger.to_state.attributes.friendly_name }} was {% if trigger.to_state.state == 'on' %} Open {% else %} Closed {% endif %}"
    service: notify.stephan_phone

this action send a notify to my phone when a door is open/closed

You could write one automation that increments a counter.
Another automation resets the counter periodically (e.g. every day, every 6 hours, or every hour).
A third automation triggers an alert notification if the counter reaches a value you consider would indicate a leak.