Esphome make average of sensor reading

Hello, I tried to make average reading but by the documetation I think it was quite complex and I did not succeed in doing it well.

Can please someone advise me how to trigger ten readings let’s say 0,1s apart, then calculate average and return to homeassistant only the average value? I understand I would have two sensors, one internal reading every 0,1s and other extrnal that takes average of internal and sends it out. My problem is that I only know how to make internal sensor read every 0,1s all the time and then report moving average of last 10 values. I need the fast internal sensor to perform only 10 readings, return average and then wait until it is triggered by the external sensor, which reads every 4 hours.

Are there other sensors/relays attached to the esp that you need all the time? The sleep component will do what you ask but the whole board will sleep. Nothing attached to it will be available when it is in sleep mode.

Yes I use deep sleep. I just dont want the sensor to read every 0,1s if I dont need the values. I think I figured it out:

sensor:
  platform: adc
  pin: vcc
  name: Vcc Average
  filters:
    - throttle: 0.1s
    - sliding_window_moving_average:
        window_size: 5
        send_every: 5
    - heartbeat: 4h
2 Likes

Hey @janbenes - I know this post was a couple of years ago, but I’m actually interested in doing what you described in your original post, I want my esp to take readings every 0.1 seconds and only update Homeassistant every 5-10 seconds or so, ideally with either the average or the maximum measured.

You posted your successful code for sending it every 4 hours, but do you have any memory of how you originally setup the averaging? Thanks in advance, may your install be stable, and your database clean.

Hello @jjphoto

yes set the moving average “send_every:” to 50 or 100. That means the moving average is taking readings every 0.1s but sending them out on the 50th or 100th reading. Adjust to suit