Alert if sensor didn’t have a stable period in the day?

So this is related to a trigger sensor in some way. My issue is this - there was a pipe broken in the ground at my property. That leak was undetectable until I happened to look at charts of my well energy. I noticed it was steadily increasing, even in periods without house or irrigation demand. That struck me as unusual, and after investigation, I found the leak.

What I”m thinking about doing is creating an automation that alerts me if there isn’t a “flat” period in the graph for some predetermined amount of time. It’s a very irregular use, so I can’t just look at, say, 2am-3am or something, because in the summer I’m irrigating wine grapes and an orchard, sometimes most of the night. But at some point in the day, there should be at least a 30-45 minute period that is unchanging.

Thoughts on this? I’m guessing I can figure it out, but I’m curious if there are better ideas out there, besides metering the well itself.

I think you could set up a Trigger-based binary sensor with a state trigger like:

template:
  - trigger:
      - trigger: state
        entity_id: sensor.irrigation
        to: ~
        for: "00:30:00"
    binary_sensor:
      - name: Irrigation Static
        state: "{{ true }}"
        auto_off: "00:01:00"

Then use a History Stats sensor to run a rolling count:

sensor:
  - platform: history_stats
    name: Irrigation Static period count
    entity_id: binary_sensor.irrigation_static
    state: "on"
    type: count
    start: "{{ now() - timedelta(hours=24) }}"
    end: "{{ now() }}"

Trigger your notification automation off the History Stats sensor’s value falling below 1.

EDIT: Corrected typo noted below

2 Likes

What about a derivative helper. Wouldn’t it be near zero when the energy use is constant? You could trigger an automation if there are no zeros in a 24 hr. period.

There is also a trend sensor that could help I guess

I think this solution works pretty well. For anyone coming later to the party, auto-off is actually auto_off in the docs, so that needs to change.

Thanks for the assist. Seems like this could be used for checking for vampire drain as well if used more broadly.

1 Like