How do I report average Battery levels averaged over 24 hours?

My battery levels in my Ikea Tradfri Zigbee remotes bounce around a lot. That’s fine, I understand they’re polling the voltage levels. So I’d like to report on the 24 hour average of the voltage level.

As you can see from the image some devices really bounce all over the place. So when I try to report on low battery levels I’m always getting false positives like this:


(by the way I built that sensor list using the auto-entities card which is pretty cool)

So my question is:
how can I make ALL of my batteries report their 24 or 48 hour average? I suspect I could probably template each one of them and create a jinja2 calc off each individual device, but I have >20 battery powered devices. So is there a way I can dynamically calculate the average of a range of sensor batteries?

Thanks is there any way I can apply a statistic to a group of sensors programmatically?
e.g.
entities:

  • pattern: battery

Not as far as I am aware.

To the group itself of to any member in the group?

For those who are interested, here is where I’m at so far. I had to add an entry for every battery under sensor section of my configuration.yaml. Ikea remote battery levels are problematic and need to be smoothed.

I’ve started recording the 24 hour average of the battery readings for each battery. I couldn’t find a way to do it automatically for all entities matching a glob* pattern.

  - platform: statistics
    name: "0x84fd27fffe9f13d2_battery 24hr"
    entity_id: sensor.0x84fd27fffe9f13d2_battery
    state_characteristic: mean
    max_age:
      hours: 24

  - platform: statistics
    name: "0x8cf681fffe48bbf4_battery 24hr"
    entity_id: sensor.0x8cf681fffe48bbf4_battery
    state_characteristic: mean
    max_age:
      hours: 24

But then I realised that unless the statistics are being recorded a simple reboot of HA will cause me to lose statistics. So I had to turn on the recorder, like this:

recorder:
  purge_keep_days: 4

It has levelled out the battery recorder readings so I can alert on a consistently low battery reading:

In my dashboard I’m using auto-entities to see the worst batteries:

type: custom:auto-entities
card:
  type: entities
filter:
  include:
    - options: {}
      entity_id: '*battery_24hr'
  exclude: []
sort:
  method: state
  reverse: false
  numeric: true