Filter, maximum - "peak" detection

Dear ESPhome gurus,

I’ve only recently discovered the magic of esphome and I’m really impressed!

I’ve got a MPU6050 vibration sensor connect and it nicely sends the data to HA.

Now, I’d like to get my esp32 to read the acceleration values at “high” frequency and only send the maximum of the acceleration amplitude of a given period. e.g. read the sensor every second and only send once a minute a value (the maximum seen during the last minute) to HA. I could find filters that return the average value, but not a “peak” detection.

Does someone know if/how this is possible?

Cheers,
Ulrich

Did you ever get an answer or figure it out?

Hi,
I m interested in this peak detection function.

A good ideas are here: algorithm - Peak signal detection in realtime timeseries data - Stack Overflow

A way is to use custom code in ESPhome (like in C) that we can found in link above… but I don’t have the full skill to make it.

The best, is to implement the cose in ESPhome, so i will try to open a FR in ESPhome GitHub.

Here’s a somewhat clumsy way to approach it in ESPHome (doesn’t compare to the algorithm you referenced, but could tell you the highest value seen):

Use an ‘interval’ component and a global variable.
Have the interval run a lambda periodically (e.g. once per second).
The lambda fetches the current reading and compares it to the value stored in the global. If higher, it replaces the global with this new value.
Have a template sensor component (with its own update period, e.g., once per minute) update itself from the global, then reset the global to 0 for the next round.

This could suffice but only if the peaks last longer than one second, else the probability is high that the per-second sample does not occur at the exact moment a peak is also occurring.