I have been using a statistics sensor on HA 0.95 and it was working well. I have read many posts that we can’t access the attributes of an entity directly in Lovelace but I somewhere found out that you could do that by appending a underscore to the entity name. This was all working well until I upgraded to 0.98. It seems to be broken now. I know I can create another template sensor based on the desired attribute and then use it in Lovelace but then the earlier method was easier. Was that working by fluke?
My aim is to access the mean (or any other) attribute of the statistics sensor.
My sensor.yaml in HA 0.95
# Overhead water tank
- platform: mqtt
name: "Overhead Tank"
state_topic: "home/overhead_tank/SENSOR"
value_template: '{{ value_json.SR04.Distance }}'
- platform: statistics
name: "Overhead Tank Stat"
entity_id: sensor.overhead_tank
sampling_size: 10
- platform: template
sensors:
water_level:
friendly_name: "Overhead Tank Level"
unit_of_measurement: "%"
value_template: >-
{{ ((150 - states.sensor.overhead_tank_stat_mean.state | int)/ 125 *100 )| int }}
The way I was using it on Lovelace was
sensor.overhead_tank_stat_mean
New config after upgrade to HA 0.98 that works is:
# Overhead water tank
- platform: mqtt
name: "Overhead Tank"
state_topic: "home/overhead_tank/SENSOR"
value_template: '{{ value_json.SR04.Distance }}'
- platform: statistics
name: "Overhead Tank Stat"
entity_id: sensor.overhead_tank
sampling_size: 10
- platform: template
sensors:
water_level:
friendly_name: "Overhead Tank Level"
unit_of_measurement: "%"
value_template: >-
{{ ((150 - states.sensor.overhead_tank_stat.state | int)/ 125 *100 )| int }}
And Lovelace config:
sensor.overhead_tank_stat
After the upgrade I cant use “_mean” anymore. I was able to solve this as the default attribute for statistics seems to be mean and hence when I refer to sensor.overhead_tank_stat
, it gives me the mean. But then if I have to refer to median , that wouldn’t work.
Any help is appreciated.