I am currently running Core 2024.7.2 using the HassOS image running in a Proxmox VM on a stand-alone x86-64 based machine. Supervisor and HAOS versions are 2024.06.2 & 12.4 respectively.
Several months back, in an attempt to create a 24 hour rain tally, from a weather integration hourly rain sensor, I created a Utility Meter sensor as follows:
sensor.daily_rain:
device_class: precipitation
unit_of_measurement: 'in'
My utility_meter.yaml file is included from configuration.yaml
utility_meter: !include utility_meter.yaml
This daily rain sensor is woking as expected, however, Iâve noticed in the system logs the following warning after every HA restart:
âWARNING (MainThread) [homeassistant.components.sensor] Entity sensor.daily_rain (<class âhomeassistant.components.utility_meter.sensor.UtilityMeterSensorâ>) is using state class âtotal_increasingâ which is impossible considering device class (âprecipitation_intensityâ) it is using; expected None or one of âmeasurementâ; Please update your configuration if your entity is manually configured, otherwise create a bug report at Issues ¡ home-assistant/core ¡ GitHubâ
In reviewing the sensor entity docs I believe the âstate classâ of âtotal_increasingâ is correct for this sensor:
Similar to total, with the restriction that the state represents a monotonically increasing positive total which periodically restarts counting from 0, e.g. a daily amount of consumed gas, weekly water consumption or lifetime energy consumption. Statistics of the accumulated growth of the sensorâs value since it was first added is updated every 5 minutes. A decreasing value is interpreted as the start of a new meter cycle or the replacement of the meter.
But the âdevice classâ should be âprecipitationâ not âprecipitation_intensityâ and thus the âunit_of_measurementâ should be âinâ and not âin/hâ.
To modify the âdevice classâ and âunit_of_measurementâ I added the following to my customize.yaml file:
sensor.daily_rain:
device_class: precipitation
unit_of_measurement: 'in'
My customize.yaml file is included from configuration.yaml:
homeassistant:
customize: !include customize.yaml
I restarted HA and then from Developer tools > States I verified the dail_rain sensor attributes:
state_class: total_increasing
- status: collecting*
- last_period: â0â*
- last_valid_state: None*
- last_reset: â2024-07-12T05:02:00.001544+00:00â*
- next_reset: â2024-07-13T00:02:00-05:00â*
- unit_of_measurement: in <== new value, was in/h*
- device_class: precipitation <== new value, was precipitation_intensity*
- icon: mdi:weather-pouring*
- friendly_name: Daily Rain*
Unfortunately there is now a different warning message:
The unit of sensor.daily_rain (in) cannot be converted to the unit of previously compiled statistics (in/h). Generation of long term statistics will be suppressed unless the unit changes back to in/h or a compatible unit. Go to Link to Developer tools: statistics â My Home Assistant to fix this
Going to the provided link took me to: http://homeassistant.local:8123/developer-tools/statistics
Here the daily rain sensor was listed indicating the unit of this entity changed from in/h to in and a FIX ISSUE button was highlighted.
Clicking the Fix Issue popped up an actionable dialog:
The unit of this entity changed to âinâ which canât be converted to the previously stored unit, âin/hâ.
- If the historic statistic values have a wrong unit, you can update the units of the old values. The values will not be updated.*
- Otherwise you can choose to delete all historic statistic values, and start over.*
How do you want to fix this issue?
(1) Update the unit of the historic statistic values from 'in/h' to 'in', without converting.
(2) Delete all old statistic data for this entity
I chose the first option and after the action completed I restarted HA again to verify there were no further daily_rain sensor warnings.
Well damn, the exact original warning is back. Going back to Developer tools > States I can see the âdevice classâ and âunit_of_measurementâ are still what I modified them too. The warning still indicates, however, that the device_class is precipitation_intensity, which it no longer is, per the Dev tools.
In further exploring this issue I discovered that the core.entity_registry file contains the following, note in this file it has the âdevice_classâ as âprecipitation_intensityâ: {âaliasesâ:[],âarea_idâ:âsantaritaranchâ,âcategoriesâ:{},âcapabilitiesâ:{âstate_classâ:âtotal_increasingâ},âconfig_entry_idâ:null,âdevice_classâ:null,âdevice_idâ:null,âdisabled_byâ:null,âentity_categoryâ:null,âentity_idâ:âsensor.daily_rainâ,âhidden_byâ:null,âiconâ:âmdi:weather-pouringâ,âidâ:â6d749158bc572c11631233b7e99a0d64â,âhas_entity_nameâ:false,âlabelsâ:[],ânameâ:null,âoptionsâ:{âconversationâ:{âshould_exposeâ:false},âsensorâ:{âdisplay_precisionâ:3}},âoriginal_device_classâ:âprecipitation_intensityâ,âoriginal_iconâ:null,âoriginal_nameâ:âDaily Rainâ,âplatformâ:âutility_meterâ,âsupported_featuresâ:0,âtranslation_keyâ:âutility_meterâ,âunique_idâ:âdaily_rain_single_tariffâ,âprevious_unique_idâ:null,âunit_of_measurementâ:null},
I manually edited core.entity_registry (yeah I know this might be risky, but I had a full backup & a backup of this file) changing original_device_class to precipitation and then restarting HA. The original warning was still seen in the logs. Looking at the core.entity_registry file again I found the device_class was again precipitation_intensity.
I also found that the file core.restore_state contains the following, which shows the modifications as well as the original settings:
{
-
"state": {"entity_id":"sensor.daily_rain","state":"0","attributes":{"state_class":"total_increasing","status":"collecting","last_period":"0","last_valid_state":"None","last_reset":"2024-07-12T05:02:00.001544+00:00","next_reset":"2024-07-13T00:02:00-05:00","unit_of_measurement":"in","device_class":"precipitation","icon":"mdi:weather-pouring","friendly_name":"Daily Rain"},"last_changed":"2024-07-12T15:09:19.063063+00:00","last_reported":"2024-07-12T15:09:19.062959+00:00","last_updated":"2024-07-12T15:09:19.063063+00:00","context":{"id":"01J2KQVMAQE7SB5B31KW60X164","parent_id":null,"user_id":null}},*
-
"extra_data": {*
-
"native_value": 0,*
-
"native_unit_of_measurement": "in/h",*
-
"last_period": "0",*
-
"last_reset": "2024-07-12T05:02:00.001544+00:00",*
-
"last_valid_state": null,*
-
"status": "collecting",*
-
"input_device_class": "precipitation_intensity"*
-
},*
-
"last_seen": "2024-07-12T15:09:23.783175+00:00"*
- }*
I manually modified the input_device_class and native_unit_of_measurement with the new values and restarted HA. Just like the core.entity_registry, the contents of core.restore_state reverted back to previous values.
Not sure where these persistent values are stored, but itâs clear thereâs a lot I still donât yet understand about HA.
Iâve re-verified, via Dev tools, the attributes of the daily_rain sensor and the âdevice_classâ and âunit_of_measurementâ are set to the values defined within the customize.yaml file.
The one thing I havenât tried yet is removing the sensor altogether and then recreating it, but since this has been working for months, I would first really like to understand why my daily_rain attribute changes are not resolving this issue or even why the initial settings were as they appeared, especially since HA knows the two different settings it assigned are not compatible.
Iâd really appreciate it if someone could educate me on the proper way to setup a utility meter sensor for the purpose of accumulating hour data over a 24 hour period.