Detecting sawteeth patterns

Hi,

What approach can be used in Home Assistant to detect sawteeth-like patterns in the metrics?
The picture shows how my gas boiler behaves when its water filter should be cleaned, so I’d like to detect it as early as possible.

Thanks!

Average is above 10 but also below 60 in a period of one hour.
I would try with that.
Use the average helper or statistics sensor or something like that to get the average.

Thanks, but I am afraid that the average stats won’t help - it stays in the middle section during normal behavior as well - see the updated picture.

Probably, I should compare counts (ratio) of zero and non-zero measures with some minimal thresholds both for the numerator and denominator to reduce noise during idle (summer) periods.

First I would create a Threshold helper (this is a binary sensor) that is on when the value is high and off when the value is low. Choose the threshold so that sensor has relatively quick on/off behavior when the spikes are there (the first yellow block) and remain on during normal operation (the second yellow block)? I’d probably pick 10 as the upper limit, no lower limit and 2 as hysteresis.

Then I would create a history stats helper of type count, counting how many times the Threshold sensor was on in the last x period. If that sensor exceeds a certain number of times then you have the spiking behavior. That is because long stable on will only count as one and long stable off as 0. Lets say you count ‘on’ over a period of one hour. Then you’d want to see more than five or six or something like that to detect spiking.

1 Like

I don’t have the data you do.
My first guess was probably too high, but set up a few sensors and see what works.
You can probably set the average above 5 and below 30.
If you create the sensors then it will all become clear but before this, it’s mostly a guessing game.

This sounds like solid advice. My first guess was to set up a derivative sensor and take the mean of the absolute value of it. I think @Edwin_D 's solution is better.

1 Like

You can play with the time duration of the history stats. If you make it longer, then the sensor will be slower to respond but also remain high longer in the periods with little activity. Make it too short and you wan’t be able to see if you have the spikes. You will need a decent count over that periond.

I use something similar to detect when my pool robot is getting stuck on the stairs, it creates a similar pattern when it’s stranded.

These are the sensors I use - beware: this whole setup is about 3ish years old, so it probably uses some outdated conventions; it still works fine for me, though:

- platform: template
  sensors:
    poolbot_exceeds_120w:
      friendly_name: Poolbot Exceeds 120W
      value_template: "{{ states('sensor.robot_power') | int >= 120 }}"


- platform: history_stats
  name: "PoolBot Count Exceeds 120W"
  entity_id: sensor.poolbot_exceeds_120w
  state: "True"
  type: count
  end: "{{ now() }}"
  duration:
    minutes: 5

I then use the counter as the trigger in my notification/automation and the id as part of the notification text:

alias: PoolBot Issue Notification
description: ""
triggers:
  - entity_id:
      - sensor.poolbot_count_exceeds_120w
    from: "5"
    to: "6"
    id: above 120W 6x
    trigger: state
  - entity_id:
      - sensor.poolbot_count_exceeds_120w
    from: "7"
    to: "8"
    id: above 120W 8x
    trigger: state

While I think that @Edwin_D’s solution is more elegant, this hack got it working when some of the features weren’t available yet.

Folks, thanks a lot!
It seems that counting the number of “jumps” from 0 to anything else over a few last hours will be sufficient for me. It filters out the cases when the value stays at 0 (in summer time) or above 0 (normal heating) for the long enough time. Here is a plan.

  1. Use Trigger-Based Template Entities feature for creating an entity that returns True every time when the monitored value goes from zero to non-zero
  2. Use history_stats to count the number of such cases in the reasonable sliding time window (1-2 hours in my case)
  3. Fire a notification when that count exceeds my threshold

Thanks everybody!

1 Like