Template sensor shows as « unavailable » yet all tests are OK

Hi,

I’m relatively new to home assistant, and I am really struggling to get a template sensor to work.

My environment :

Home Assistant Green

Installation method Home Assistant OS
Core 2026.2.0
Supervisor 2026.01.1
Operating System 17.0
Frontend 20260128.6

The template sensor is adapted from the example given here :

# Sourcecode by vdbrink.github.io
# configuration.yaml
template:
  - sensor:
      - name: "Temperature difference inside and outside"
        unique_id: template_diff_inside_and_outside
        icon: mdi:thermometer
        unit_of_measurement: "°C"
state: >
          {% set temp1 = states('sensor.average_inside_temperature') | float(0) %}
          {% set temp2 = states('sensor.porche_dentree_netatmo_temperature') | float(0) %}
          ({{ (temp1 - temp2) | round(2, 'ceil')| float(0) }})
availability: "{{ 'sensor.average_inside_temperature' | has_value and 'sensor.porche_dentree_netatmo_temperature' | has_value }}"

In the template developer tool, everything seems OK :

Similarly, the tests of the « states » and « availability » snippets of the template options are positive :


Yet the preview (see just above) shows « unavailable » as does the settings panel of this helper :

I really don’t know what to try to get this to work as expected. Any help would be really appreciated.

It seems (if you copied 100%) that your indentations of state and availability are wrong, they need to be at the same level as ‘unique_id’

Thanks for your reply Vingerha.

Maybe my explanation was not clear, but the YAML code you see is that in the dev-template editor. But as a Home Assistant Green user, I can’t directly create a YAML file, so the actual template is obtained through the template sensor helper, in which case you have just two fields where you can paste in “code”:

  • State
  • Availlability template

Here is what is pasted in the “State” field:

state: >
          {% set temp1 = states('sensor.average_inside_temperature') | float(0) %}
          {% set temp2 = states('sensor.porche_dentree_netatmo_temperature') | float(0) %}
          ({{ (temp1 - temp2) | round(2, 'ceil')| float(0) }})

and here is what is pasted in the “Availability template” field:

availability: "{{ 'sensor.average_inside_temperature' | has_value and 'sensor.porche_dentree_netatmo_temperature' | has_value }}"

One doesn’t have access to any indentation possibilities so, as far as I understand, you can’t make any indentation errors!

Moreover, the tests of both these fields provided by the helper editor show the correct results (see my original post).

tbh, never used this but from what I see your should not add state: > nor availability into these fields
I would expect this to work:…logically it shows unavailable with me as I donot have your sensors

Yes, of course. That’s much better:

Thank you, you’ve made my day(