I would like to have a sensor that shows me how much another sensor changed over the last hour (or whatever time interval I chose). From the posts I read this should somehow be possible with a template and a statistics sensor, but documentation is so bad that I cannot figure it out myself.
In my specific case, I would like to graph the DNS queries blocked by AdGuard within a 1h time interval, to see activity going up and down. The sensor.adguard_dns_queries_blocked
is cumulative and keeps increasing all the time, so that’s difficult to read in the frontend.
I tried something like this:
# AdGuard DNS queries blocked in last hour
- platform: statistics
name: adguard_dns_queries_blocked_stats_1h
entity_id: sensor.adguard_dns_queries_blocked
max_age:
minutes: 60
- platform: template
sensors:
adguard_dns_queries_blocked_1h:
value_template: "{{ state_attr('sensor.adguard_dns_queries_blocked_stats_1h', 'change') }}"
unit_of_measurement: "ads/h"
But the resulting sensor actually gives negative numbers, which doesn’t make sense for a result, so something must be wrong.
Any advice?