First attempt at templating for me/ I’m trying to do a simple value adjustment for a temperature sensor. It works OK except there is always an error in the log when the entity is unavailable (flaky bluetooth connection!)
and the log error is ValueError: Sensor sensor.calibrated_pool_temperature has device class 'temperature', state class 'measurement' unit '°C' and suggested precision 'None' thus indicating it has a numeric value; however, it has the non-numeric value: 'unavailable' (<class 'str'>)
So I’m unclear how to handle the unavailable state. I don’t do any math if the state isn’t a number but apparently that’s not good enough!
I must have missed something obvious in the docs but I can’t find it
If I’m understanding you correctly, I’d need to add another template for Availability? If so, where would I do that? I can’t find the YAML that the UI created.
You can create a Template Sensor via the UI (referred to as a Template Sensor helper).
You can create a Template Sensor via YAML.
A Template Sensor helper only offers a subset of the features available in its more capable YAML-based version.
In order to take advantage of a Template Sensor’s additional features, like availability, you will have to create it in YAML (i.e. replace the Template Sensor helper you currently have).
I’m hoping that a Template Sensor helper will eventually support all the features of a Template Sensor. Currently it’s an MVP implementation (minimum viable product).
You could use none when the state of the source sensor is not a number. That is accepted (will not generate errors in your log) and the template sensor will become unknown
@TheFes
I’m still learning Jinja so your second example is interesting.
The thing is {{ states('sensor.ibs_th_0373_temperature') }}
is what craps out in the log. I think because I defined the sensor as a measurement class which is a number whereas {{ states('sensor.yadayada...}} returns a string if the state is unknown. It makes sense but this is my first template sensor so there is a lot to learn
This is what I ended up with which works quite well: