- I have a binary sensor
binary_sensor.heating
. The state changes toOn
when it starts heating andOff
when it stops. Sometimes, it isunknown
. - I want statistic measurements that tell me more about how much heat I am using. So I have been using binary statistics.
The config looks like this:
sensor:
# Heater
- platform: statistics
name: "Heating over last 24 hours"
entity_id: binary_sensor.heating
state_characteristic: average_step
max_age:
hours: 24
sampling_size: 1000
- platform: statistics
name: "Heating count over last 24 hours"
entity_id: binary_sensor.heating
state_characteristic: count_on
max_age:
hours: 24
sampling_size: 1000
I haven’t had any heating in the last 24Hrs, so my states currently look like this:
- The count over 24h is correct. But the percentage is not. There haven’t been any
On
orOff
values in the last 24hrs, so I think that is why the percentage is unknown. It isn’t looking at the previous message to know if it has been on this entire time, or off. So maybe that is not a bug, but it is a missing feature. Ok…
Let’s look at the history for the last week:
The count (on the bottom) looks correct.
-
The percentage (in the middle, the top graph) is wildly incorrect though. The actual amount of heat I am using (in this springtime climate) is less than 5%. The percentage goes as low as that sometimes, but then has these steady periods of 30-40%. And when the heat turned off for more than a day, it shows it stuck at 100% (is this just a case where the “unknown” is being misinterpreted by the history graph?).
-
The current value is “unknown”, when it should be 0%. I could make a template sensor to correct that, basing it on the current value of
heating
and thebuffer_usage_ratio
. That seems a little clunky.
The thermostat is my own arduino/esp32 creation. I am guessing I could make this a lot easier on the statistics module if I periodically (every 6 mins) publish the on/off. IIRC, it is coming via MQTT.
Ultimately, I want these statistics to lead to smarter automations, and long term logging (comparing this year’s heating % to last year’s).
Anyone have any tips? Should I report this upstream to HA as an issue? Am I misusing the statistics module? Is there a better alternative?