Template sensor unavailable & Not actualizing values

Hello

I’m trying to set some templates in my HA and my first step was to try the example presented in the HA template guide, basically and average of 2 different temperatures. I’ve configured the templates as follows:

I have 2 doubts:

1- I cannot read the average temperature, the sensor template appears as unavailable. Anybody knows the reason why?
2- The template value should change anytime any of the 2 values changes, but according to the configuration, it will only change when the 1st value changes. Why?

Thanks

You haven’t provided default values for float. Please paste in code, correctly formatted, rather than (or as well as) using screenshots.

Your exact template (as far as I can tell from the screenshot) works for me with entities that are on my system:

{% set T1 = states('sensor.outside_temperature_1')|float %}
{% set T2 = states('sensor.outside_temperature_2')|float %}

{{ ((T1 + T2) / 2) | round(1, default=0) }}

My guess is either a typo in your second entity ID, or that sensor is returning unavailable or unknown.

You could set each sensor’s float default value to the other sensor, such that if one goes offline, the average is simply the state of the other one. Like this, giving up on the inside float:

{% set T1 = states('SENSOR1')|float(states('SENSOR2')|float('unavailable')) %}

I can duplicate your results when the first entity_id in the template either doesn’t exist or doesn’t have a numeric value.

  1. Ensure sensor.salon_temperature is spelled correctly.

  2. Ensure it has a numeric value. To guard against non-numeric values use float(0) in your template, where 0 represents the value you want to use when the sensor’s actual value is not a number.

Thanks for the anwser.

The code is the same as in the example, just replacing the entities, thats the reason why I didn’t paste it. Here you have the code.

{% set T1 = states('sensor.termometro_salon_2_temperature') | float %}
{% set T2 = states('sensor.salon_temperature') | float %}

{{ ((T1 + T2) / 2) | round(1, default=0) }}

I just changed the order of the variables declaration and know it’s listening both entities for changes.

However, the template status remains unvailable. Both entities are reporting values:

image

Any ideas??

Are you sure it’s not temperatura with an “a” as the last letter? Same for the other one?

Can you show these values screenshotted from Developer Tools / States please, like this:

You can paste the template into Developer Tools / Template to see if it works there before adding it to a sensor:

It fixed nothing, just masked the problem. That’s why the end-result is unchanged.

Review the explanation I provided in my previous post. It’s either a spelling error or the sensor’s value is non-numeric (supply float with a default value).

You were right, It was a spelling problem. Was “temperatura” instead of “temperature”. The problem was the TADO integration, that is created with variables of the system with the same language as its settings, in this case spanish.

Thank you very much

1 Like

Pasting the code as text (and formatted correctly) helps other help you. As you saw from other replies, someone replicated your code in their own system, and someone else replied with a suggested edit. With an image only, you’re requiring those people to transcribe from your image which is both tedious, and could introduce new errors that slow down you getting a get response to your question. I’m not trying to scold; I’m just trying to provide helpful context on the reason to use well formatted code text instead of only images.

1 Like

thanks, i’m relatively new in HA and this forum. I’ll do as you indicated.

1 Like