This is part of the climate.thermostat.yaml form my thermostat, copied from dev.tools/states. I want to create a sensor to calculate difference between “temperature” and “current_temperature”
The template below. But it show “unavailable”?
You need to use state_attr() to get attributes, not states().
Also, you should have defaults on the float filters and/or add an availability. Since those attributes are normally already floats, you can probably just leave the filters off if you add an availability:
name: "HVAC Set temperature and ambient temperature diff"
unique_id: '55xxxxxxxxxxxxxxf'
unit_of_measurement: "°C"
state: >
{% set set_temp = state_attr('climate.thermostat','temperature') %}
{% set ambient_temp = state_attr('climate.thermostat','current_temperature') %}
{{ ((set_temp - ambient_temp)) | round(1, default=0) }}
availability: |
{{ state_attr('climate.thermostat','current_temperature') | is_number and
state_attr('climate.thermostat','temperature') | is_number }}
by the way it I input sensor.thermostat_temperature in to dev_tools/states it returns current temperature.
What would be syntax to extract value for the ‘temperature’ from