I have a “utility_meter” setup from my configuration.yaml.
I want to be able to look back a few months at historical values.
The utility_meter has a monthly cycle… so although it’s constatly increasing, it’s mainly the value just before it cycles I’m looking for.
The sensor look like this in my configuration.yaml:
utility_meter:
house_solar_saving_montly:
source: sensor.house_solar_saving_last_hour
cycle: monthly
delta_values: true
offset: '00:00:20'
unique_id: "house_solar_saving_monthly"
name: House Solar Saving Monthly
#unit_of_measurement: SEK
Trying to look at last month, I have nothing in my history.
But, I also read that there is something called LTS (Long Term Statistics) and that I should be able to see this data for my sensor as it has a native “state_class: total_increasing”.
The data should become visible when adding it to a statistics card.
But when I do so… I still only see the sensor data that gets purged.
You’d have to wait for it to populate that data. The system does not create things in the past. When you add an entity to the system, your LTS and Regular history start the moment you add the entity.
You’ll need a unit of measurement for it to be numerical.
You may need device_class: monetary for it to work.
For your statement 2, do I solve this by removing the # in front of my “unit of measure” in the configuration.yaml file?
Seems I was playing around with this at the time I created this sensor, but I’ve not sure why I left it out by adding the #
1) I created the sensor ~a year ago, so this should not be the issue
2) I tried adding a unit if measurement to my utility_meter as we (although it already has a unit_of_measurement based on the source sensor it’s tracking (sensor.house_solar_saving_last_hour):
utility_meter:
house_solar_saving_montly:
source: sensor.house_solar_saving_last_hour
cycle: monthly
delta_values: true
offset: '00:00:20'
unique_id: "house_solar_saving_monthly"
name: House Solar Saving Monthly
unit_of_measurement: "SEK"
I have exactly the same problem. My utility meter sensors are not show in the long term statistic. Adding unit_of_measurement or device_class are leading to errors in the config as shown above.
I also cannot add an utility meter sensor to a “Statistics graph Card”.
Does anyone have a solution how to bring utility meter sensors to the long term statistic? @Piffis maybe?
To add to this. A good place to start is in Developer Tools and States. This will show you how the sensor/entity is defined in HA. If it does not have state_class it will not save to LTS.
Sorry for answering so late. Unfortunately customize seems not to work as solution for me. I have added state class and unit of my Utility Meter sensor like this:
Setting state_class to “total_increasing” is also not working too.
As I had the problem of missing long term statistics also for other sensors which are originally missing state_class I opened a more general thread. Now I learned that customize cannot be used to enable long term statistics (at least for non-legacy sensors):
So there seems to be no way to enable the long term statistic for my Utility Meter sensor.
If nobody else has any other idea, I will de-install Utility Meter and use my own logic with template triggered sensors again. Not as elegant but working but I can use LTS if I want to.
The root cause have been, that the source sensor has set unit_of_measurement to “kWh” but state_class to “measurement” which does not really fit together. The Utility Meter uses state_class “total_increasing” for kWh. After changing the source sensor to “total_increasing” (and waiting 10 days) everything works fine now. The long term statistic works as expected.