Value template calculation based on statistic platform stopped working

Hello everyone,
After a recent update a few of my configurations stopped working. They took me a long time to cobble together because I am not a coder. I’ve been trying to find out why they stopped working but I can’t seem too figure it out.
It’s an snmp value captured from my LTE modem,

  - platform: snmp
    name: 'wr11_in_wan_snmp'
    host: 192.168.1.1
    baseoid: 1.3.6.1.2.1.2.2.1.10.2
    community: 'R2HnypsUPxF7jon3LP_onsrQNSGyAE'
    version: '2c'
    scan_interval: 1

put into a statistic template

  - platform: statistics
    name: 'wr11_in_wan_stats'
    entity_id: 'sensor.wr11_in_wan_snmp'
    sampling_size: 2
    max_age:
      hours: 24

and then this calculation is supposed to spit out the Mbps. This is where comes out as “unavailable”. The developers tools template thing spitss out “TypeError: unsupported operand type(s) for -: ‘NoneType’ and ‘int’”

  - platform: template
    sensors:
      wr11_in_wan_mbps:
        value_template: "{{ (state_attr('sensor.wr11_in_wan_stats','change_rate')|float*8*(state_attr('sensor.wr11_in_wan_stats', 'sampling_size')-1)/1000000)|round(2) }}"
        unit_of_measurement: 'MBps'
        unique_id: 'wr11_in_wan_mbps'
      wr11_out_wan_mbps:
        value_template: "{{ (state_attr('sensor.wr11_out_wan_stats','change_rate')|float*8*(state_attr('sensor.wr11_out_wan_stats', 'sampling_size')-1)/1000000)|round(2) }}"
        unit_of_measurement: 'MBps'
        unique_id: 'wr11_out_wan_mbps'  - platform: template

After that I filter it with this crude filter but that seemss to still work

  - platform: filter
    name: 'wr11_in_wan_mbps_filtered'
    entity_id: 'sensor.wr11_in_wan_mbps'
    filters:
      - filter: outlier
        window_size: 40
        radius: 40.0

I’d love to solve this but I’m stuck by myself.

The statistics sensor has changed. Familiarise yourself with the new options here:

Thanks tom. I figured as much.

It does not say from what to what the values I used changed so I am kind of stuck.

To what did “sampling_size” change?
To what did “change_rate” change?

If I substitute these with the new options, will my value template calculations work again?

Read the state characteristics… The attributes didn’t change, they were removed.

Ok so I guess my question then becomes: How do I change my calculation so it’ll work like before?
Without the change rate value handily available, I have no idea how to calculate this myself.

I’m guessing you still haven’t read the state_characteristics, what you want still exists. You just need to choose the correct one…

You no longer get one sensor with all the attributes you had before. You need to make a seperate sensor for each of these that you want. See the example. For your change rate you need to use the change_second state characteristic.

Hi,

I keep my home assistant always up2date. I mostly read the release notes but that one I seemed to have missed… I am currently looking through my logs and saw that I had the exact same errors with same configuration (for quite a while now).
When looking for a solution I found this thread which lead me to the right direction.

I now did and after reading it twice I now understand what tom meant with

Here is my code for everyone who needs another “push” for better understanding:

First you have you sensor, in our case its an SNMP sensor

sensor:
    - platform: snmp
    version: '3'
    host: 192.168.3.9
    name: "Dockerhost_enp2s0f0_Octets_IN"
    username: 'hass'
    auth_key: !secret dockerhostSNMPauth
    auth_protocol: 'hmac-sha'
    priv_key: !secret dockerhostSNMPencr
    priv_protocol: 'aes-cfb-128'
    baseoid: 1.3.6.1.2.1.2.2.1.10.2
    accept_errors: true

Then you create a new Statistics Sensor. Here is the breaking change: Every Attribute needs to be a new own sensor. For our behavior its only the change_second attribute needed. So we leave it with that.

  - platform: statistics
    name: 'Dockerhost enp2s0f0 in changesecond Stats'
    entity_id: sensor.dockerhost_enp2s0f0_in
    sampling_size: 4
    state_characteristic: change_second
    max_age:
      hours: 24

And now the template to calculate what we really want. The change_second mostly does what we had to calculate before. Watch out: It’s now in the template section and not in sensor anymore.
It’s now simply:

template:
  - sensor:
      - name: dockerhost_enp2s0f0_in_mbps
        state: "{{ ( ( float(states('sensor.dockerhost_enp2s0f0_in_changesecond_stats'), default=0) * 8) / 1000000 ) | round(2) }}"
        unit_of_measurement: 'MBps'

Hope it’s helpful for anyone.

Notes: I use SNMPv3 and store my credentials in a seperate configuration file. Please adjust the correct values when copying. :slight_smile: