I have this template sensor in configuration.yaml which worked fine until a recent update to HA (I had made no changes to it). It is a customized battery sensor that used to have text that would look like this:
Charging: 75%
or the like. Anyone have any ideas (all the details are below):
As you can see from within Developer Tools â States, the sensor shows as unknown - with a weird value forthe battery icon (the sensopr is still unknown if I just hard code the icon to âmdi:batteryâ, and I have checked to make sure all the battery icons (such as âmdi:battery-50â are all still available):
But the same code works in the Developer Tools â Template editor as shown here - even when I try to set a value that is not 100% for the battery, for debugging purposesâŚ
Youâve given it a unit_of_measurement but then set the state to something that isnât a number. Youâll probably find an error about this in the logs. Remove the unit_of_measurement and see if that fixes it.
If it doesnât, please show the state of your battery level sensor.
That was it, thank you - I just commented out the unbit of measurement (and added the % to the end of the Charging / Not Charging text lines), and the issue went away - I do have a unit of measurement log error but that is in in/hr for a weather station so I have to dig into that one separately! Thanks again
One other quick question @Troon , in my syslog before my correction I see I had this error:
May 4 22:02:06 kruse-pi homeassistant[599]: ValueError: Sensor sensor.battery_status_kruse_cell has device class None, state class None unit % and suggested precision None thus indicating it has a numeric value; however, it has the non-numeric value: Not Charging: 97 (<class âstrâ>)#033[0m
And after the correction I still have this âValueErrorâ:
May 5 08:01:26 kruse-pi homeassistant[599]: ValueError: Sensor sensor.battery_status_kruse_cell has device class None, state class None unit % and suggested precision None thus indicating it has a numeric value; however, it has the non-numeric value: Charging: 100 (<class âstrâ>)#033[0m
So, âstring_templateâ instead of âvalue_templateâ doesnt work, âvalue_templateâ does now work but has the above log error⌠idea for what variable to show there instead of âvalue_templateâ since I have seen examples of text being used with a huge number of them still using âvalue_templateâ?
The error still says that sensor.battery_status_kruse_cell has a unit of %. Have you reloaded? Please show a screenshot from Developer Tools / States like this but for your sensor:
@Troon it was a guess - I didnât see anything listed as a template that would fit. Not Chatgpt lol!
Yes I did reload - actually the âreload yamlâ doesnât do it I have to restart HA⌠In any event, here is the screenshot and below that again the most recent syslog error and configuraiton.yaml text - just trying to get rid of the error message now -
May 5 08:01:26 kruse-pi homeassistant[599]: ValueError: Sensor sensor.battery_status_kruse_cell has device class None, state class None unit % and suggested precision None thus indicating it has a numeric value; however, it has the non-numeric value: Charging: 100 (<class âstrâ>)#033[0m
Code in configuration.yaml. It may just be that the error message is showing the additional text now â%â I threw on the end of those linesâŚ