Help to fine tune statistics sensor

Hi,

I have the following sensor for the wind speed out of my home. It reports the value every 10 seconds.

  - platform: mqtt
    name: "Wind Speed"
    state_topic: "anemometer/wind"
    unit_of_measurement: 'km/h'

I use the following statistics sensor which is doing what I need but it stores a lot of data and I would like to reduce it.

  - platform: statistics
    entity_id: sensor.wind_speed
    name: wind speed ss 90 m4
    state_characteristic: mean
    sampling_size: 90
    max_age:
      minutes: 4

To be honest I made it 2 years ago and until now I am not sure how the particular sensor works.
I have set it to 4 minutes so if I understand correct each minute it gets 6 measurements (1 every 10 sec) so in 4 minutes there are total 24 measurements. ?

If that is right the what the sampling size does?

This sensor produces a graph like this

image

As I said the above measurements are accurate but I am wondering if I can fine tune in order to reduce the file size that it produce in my database (like the following)

Yes your understanding of sample size is correct. You could use a sampling size of 30 and it would work just the same.

If you only use the statistics sensor output you could exclude the mqtt wind speed sensor from the database to reduce the size.

1 Like

ok. Now I have set it to 90 it actually stores 90 measurements?

I have exclude it from the begging.

No, it is limited by the max_age. But it may have allocated that amount of storage to be used, someone better at reading the source than me would have to check.

Then there’s not much else you can do unless you can change the reporting interval.

1 Like

may I ask if you know

  1. How the statistics sensor calculate the mean number? for example in a minute I have 6 measurements. So if it was set to make the calculation every minute then I would get 1 mean every minute. But how does it calculate the second minute/number? Does the result derives from the last 6 measurements of the second minute only?

2. I am using an esp8266 to import the measurements in HA. I used this code

Lately I have installed and use espHome. If I install a new esp8266 in esphome and copy paste this code, do you think it could work?