At the beginning I was getting a lot of this kind of values when my zigbee devices were providing and “unknonw” value. After correcting the code, This is the only one I’m getting and I don’t understand the reaso why, becouse I’m filtering the non numeric values in the template configuration.
This is the error:
ValueError: Sensor sensor.salon_target_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: ‘unknown’ (<class ‘str’>)
And this is my template configuration (done with the UI)
That’s the complete template code. It is configure in the UI, not in the configuration.yaml
Whit that code i’m getting the same i’m usually getting with my template, a number with the value of the variable in my zigbee device. The problem is that when there is a problem on the zigbee network or the HAOS or zigbee addon is restarting, I’m getting this unknown value and the error appears in the logs.
At the beggining I was getting a lot of errors with multiple templates from zigbee variables. A similar template configuration as the above solved all except this one.
sorry, but if I understand your code correctly, it is defining a default value = 0. Is my asumption correct?
That’s not an option because I’m using this template to replicate the setpoint temperature across multiple climate entities (radiator valves). If the value is set to 0 everytime there is an error in the zigbee network, it will change the setpoint of the radiators valves to 0.
This would cause the valve to move from 100% open to 0% and coming back to 100% when the actual value is read, consuming the batteries of the valves.
As you can see is a different problem. That problem was solved correcting the templating format, but in this case the problem is with the non-numeric values
I am not trying to be difficult and want to help. I just came across the previous thread.
I tested your code against my climate device multiple ways, but where we disagree is that a default needs to be set .
In my opinion, when setting the temperature across multiple climate entities (radiator valves) there still needs to be a default value if representing an integer.
Your template does not sufficiently account for how the this variable works when the new sensor entity is created.
{% set T1 = state_attr('climate.termostato_salon','temperature') %}
{% if T1 | is_number %}
{{ (T1 ) | round(1) }}
{% else %}
{{ this.state if this is not none
and this.state is defined else None }}
{% endif %}
FWIW, using trigger-based template sensors allows more control without having to use convoluted expressions to handle this. However, they cannot currently be configured as a Helper. You have to add them to your YAML configuration.
template:
- trigger:
- trigger: state
entity_id: climate.termostato_salon
attribute: temperature
condition:
- "{{ trigger.to_state.attributes.temperature | is_number }}"
sensor:
- name: Salon Temperature
state: "{{ trigger.to_state.attributes.temperature }}"