I have a ‘Battery Time Remaining’ sensor I created to give an estimate of house battery charge. In the Template section of Dev Tools I can see that the code works and returns an hr:min format.
However, as an Entity, it returns/displays only ‘Unknown’ as the result.
I’m relatively new to HA, so I’ve very likely i’ve done something silly or just missed something altogether.
‘it’ was the Dev Tool Template simulator. It’s given me errors for any other mistake, I think.
I’ve changed it now anyway and same issue. The Template preview shows Hr:Min return, but the sensor itself is ‘Unknown’.
If you include unit_of_measurement then it expects the sensor’s value to be numeric. However, in your case, it’s not numeric but a string in this format 6:40 and that’s why it reports unknown.
Not related to the main issue:
I also wonder what is a meaning of using “float(xxxx)” after calculations?
Usually “float(default=xxxx)” is used to convert a state or an attribute.
Same about “int(00)”.
Removing the Units has done it!!! I was thinking that might be it. Thanks for the tip regarding string vs numeric. I should have twigged it when the Template return was also showing the first few lines of code.