Get outdoor temperature attribute from climate

Hi, I’m not be able to get a temperature attribute from entity climate.
I tried In developer tool:

      outdoor_temperature:
        friendly_name: "Temperatura esterna"
        unit_of_measurment: '°C'
        value_template: {{ states("sensor.climate.142936511728477_climate.attributes.outdoor_temperature") | float(default=0) }}

and get

Screenshot temp

while real outdoor temperature is 33 °C

as you can see at entity state attributes
Screenshot temp

Try something like:

{{ state_attr('climate.142936511728477_climate', 'outdoor_temperature') }}

Given that climate.142936511728477_climate ist the correct entity id of your climate device.
You can check that in devtools/states

This contains two three mistakes:

        value_template: {{ states("sensor.climate.142936511728477_climate.attributes.outdoor_temperature") | float(default=0) }}
  1. The template is missing outer quotes. Wrap the template in single quotes.
  2. It’s using the states() function incorrectly. You want the value of an entity’s attribute so use the state_attr() function.
  3. It references an entity using both sensor and climate domains. It’s one or the other, not both.

Example

        value_template: '{{ state_attr("climate.142936511728477_climate", "outdoor_temperature") | float(default=0) }}'

References

  1. Important Template Rules
  2. Templating - States

This is the solution, thanks.

This code not work, I get 0

Then you did something wrong because, for all practical purposes, it’s the same as what elfrinjo suggested.

Elfrinjo’s suggestion:

{{ state_attr('climate.142936511728477_climate', 'outdoor_temperature') }}

My suggestion:

{{ state_attr("climate.142936511728477_climate", "outdoor_temperature") | float(default=0) }}

The reason it will report 0 is because either you misspelled the entity_id (or attribute) or the value of outdoor_temperature is non-numeric.

Plus elfrinjo overlooked to mention that you forgot to wrap the template in quotes; Home Assistant will reject it without the quotes (unless you moved to the template to a separate line and used a line-continuation character).

1 Like

Sorry, you are right, I copied incorrectly