I have some utility meters based on state of a power meter’s state:
e.g., one of the utility meters:
grid_consumption_general_energy_daily:
source: sensor.grid_consumption_energy_general_tariff
cycle: daily
…which is based on:
- sensor:
- name: "Grid consumption energy (general tariff)"
unit_of_measurement: 'kWh'
device_class: energy
state_class: total
state: "{{ states('sensor.iammeter1_importenergy')|float }}"
unique_id: 2452716747549
I have run utility_meter.calibrate to set them to zero, and am using them in an Apex chart:
![image](https://community-assets.home-assistant.io/original/4X/c/5/8/c5853b7f7ef4faf25bc1b863dcd28bd780a2bb0c.png)
Now the issue:
I originally had the state_class set to total_increasing. I calibrated the utility_meter to zero, and it started accumulating the daily statistics. BUT when the meter drops to unavailable, e.g. wifi drops from the meter, which can be seen to happen 4 times here:
…the utility_meter sees that as a reset, and when the meter came back, the value was adding each time. See as an example, it had reached 1.86kWh, the meter dropped four times, and it ended up at 1,073 (the “raw” reading is 269).
I’ve set the state_class to “total” instead of “total_increasing” - is this the correct way? I need the statistic to NOT reset when/if the entity it uses goes unavailable/0, but just to wait until it comes back and resume - until it hits its “daily” cycle at night.
Hints and tips to get this to do what I need would be appreciated.
It’s still resetting and getting original values, even set to state_class: total.
Meter drop:
Utility meter resetting and picking up its previous value:
So I’m a bit stumped here. How do I get this to reset to zero on a daily cycle so the statistic is managed and showing a daily total, but does not pick up and add previous values if it drops?
1 Like
I note that regardless of how I configure the sensor, the utility_meter based on it always shows as total_increasing. So I suspect that every time the meter drops unavailable, I’m not going to be able to stop it from resuming and picking up historical values.
Yet the Energy Dashboard does not show the same issue - it’s daily statistics are correct. An alternate solution would be if I can access the Energy Dashboard’s internal entities and statistics instead of defining my own and having issues with it. Are the Energy Dashboard’s statistics accessible via yaml/entities?
I think I have resolved this by adding ‘availability’ to my sensor definitions. So using the ones from my first post here as an example:
Utility_meter:
grid_consumption_general_energy_daily:
source: sensor.grid_consumption_energy_general_tariff
cycle: daily
Based on sensor:
- sensor:
- name: "Grid consumption energy (general tariff)"
unit_of_measurement: 'kWh'
device_class: energy
state_class: total
state: "{{ states('sensor.iammeter1_importenergy')|float }}"
unique_id: 2452716747549
availability: >-
{{
is_number(states('sensor.iammeter1_importenergy'))
}}
I think they should probably be total_increasing, but will see how this goes.
1 Like