Average Sensor

You are right.

But this are so simple only if entities is temperature sensor.
Other entities have no so simple structure.
As example, climate entity are store many attributes, include current and target temperature.

All this special entities are process differently

well, attributes make it more difficult for sure.

in what way and does that really matter in your sensor’s context?

Special processing need special code for it. Current version of sensor are enough for me. But i can improve it if it need for others.

I wouldn’t overcomplicate it if not needed :wink:

1 Like

That post above I’ve published for future users. :wink:
Who knows what needed for them…

Of course. Will see…

https://www.patreon.com/posts/published-1-2-1-26504933

Can i use this sensor to calculate average of non-temperature readings? I want to calculate average value of PM2.5 particle sensor.

Unfortunately, now the sensor only works with temperature data. If you try to use it somehow differently, it will throw errors, because It will not fade to convert the obtained values to temperature.

In the near future I will try to find the time and fix the sensor so that it understands other input data. Or, you can do it yourself and send a pull request.

UPD. Or you can use min-max sensor in mean mode. https://www.home-assistant.io/components/min_max/

Maybe this can do it…

1 Like

I redid the sensor. Use the following code: GitHub - Limych/ha-average: Average Sensor for Home Assistant

And from now the old average sensor is deprecated.

Thank you!
I just installed it and compared with SQL query, your average sensor is more accurate because it takes time in account.

My SQL sensor reading - 19.57

  - platform: sql
    queries:
      - name: 'Pm 2.5 24 hour avg'
        query: >
                  SELECT ROUND(AVG(state),2) 'value'
                  FROM states
                  WHERE entity_id = 'sensor.bedroom_dust_2_5um'
                  AND state != 'unknown'
                  AND state != ''
                  AND created > datetime('now', '-24 hours')
                  GROUP BY DATE(entity_id);
        column: 'value'

New average sensor reading - 18.27

  - platform: average
    name: 'Pm 2.5 day avg'
    duration:
      days: 1
    entities:
      - sensor.bedroom_dust_2_5um

image
I will use it from now on.

Thank you again.

I wanted to support you via PayPal but it shows an error “This recipient is currently unable to receive money.”

Noticed one thing about performance.
I have really a lot of values, update time is approx. 1 second and i can’t extend it.
When I switched to the Average component - my raspberry processor use jumped from 4% to 27%.
Overall system started to work slowly.
So I had to move back to sql sensor.
image

Is it possible to set update interval? Maybe it will help with my performance problem.

Please test this version of sensor: https://github.com/Limych/ha-average/tree/develop/custom_components/average

I know about it.
This is due to the strange policies of my state. Now PayPal requires me a lot of pieces of paper, which I’m not sure I want to give them.
I think what to do with it …

I tried it but it halted my system :frowning:
I used the version from the link, created sensor in the configuration:

  - platform: average
    name: 'Pm 2.5 day avg'
    duration:
      days: 1
    entities:
      - sensor.bedroom_dust_2_5um

And restarted home assistant.
After that I could not access GUI, it just never load.

Had to use my Poratiner to edit configuration.yaml and restart home assistant.

Very strange.
Did you manage to get any logs?

Once again made changes.

Now the logic of work is as follows:

  • If the duration parameter is specified, updating the sensor value occurs regularly, but no more than once every 20 seconds;
  • If this parameter is not specified, the sensor value is updated every time any of the sensors is updated, where the source values ​​come from.

You can test again :slight_smile:: https://github.com/Limych/ha-average/tree/develop/custom_components/average

Hi,

thanks for that custom component!
I just added some sensors for testing and wonder if i have to add all the custom sensors to my recoder include when using the history graph card?