Creating a new Sensor from different sensor entities

Hello,

I’d like to create a new sensor using templates that combine attributes from different sensor entities (climate.thermostat and humidifier.thermostat). I’ve followed the sensor template instructions (many Youtube videos too) but the new sensor that is created is always “unavailable”, and the attributes associated to the new sensor are missing. I’m wondering if this is because 1) the device sensor entities that I’m reading inputs from may not be “known” by HA yet upon startup? 2) Or I simply screwed up in creating the sensor template (snippet from configuration.yaml is posted below). Eventually I don’t want to “hard code” the referenced sensor entities, but have them provided via a variable (but that’s a different topic).

Here is my template for your review and guidance - thank you in advance!

template:
  - sensor:
    - name: "HVAC System"
      state: "{{ state('climate.thermostat') }}"  
      attributes:
        action: "{{ state_attr('climate.thermostat', 'hvac_action') }}"    
        preset: "{{ state_attr('climate.thermostat', 'preset_mode') }}"
        humidifier: > 
          {% if state_attr('climate.thermostat', 'equipment_running').find('humidifier') >= 0 %}
            "on"
          {% else %}
            "off"
          {% endif %}
        humidifier_mode: "{{ state_attr('humidifier.thermostat', 'mode') }}"

        fan: >
          {% if state_attr('climate.thermostat', 'equipment_running').find("fan") >= 0 %}
            "on"
          {% else %}
            "off"
          {% endif %}
        fan_mode: "{{ state_attr('climate.thermostat', 'fan_mode') }}"
        furnace: >
          {% if state_attr('climate.thermostat', 'equipment_running').find('auxHeat') >= 0 %}
            "on"
          {% else %}
            "off"
          {% endif %}

        humidity: "{{state_attr('humidifier.thermostat', 'humidity')}}"
        humidity_actual: "{{state_attr('climate.thermostat', 'current_humidity')}}"

        temperature: "{{state_attr('climate.thermostat', 'temperature')}}"
        temperature_actual: "{{state_attr('climate.thermostat', 'current_temperature')}}"

Copy-paste the Template Sensor’s configuration into the Template Editor and see what it reports for each option.

Hello Taras, that’s is how I initially tested all references to ensure I didn’t get any of them wrong. I just tried it again though but somehow my “states()” became “state()”… must have accidently deleted it.

I should have 3x checked.

Thx

If {{ states('climate.thermostat') }} reports a proper value in the Template Editor, I fail to see why it always reports unavailable when used in the Template Sensor. There’s a missing clue to this puzzle.


EDIT

Moments after writing my post, I saw that you added the detail about using state() instead of states(). There’s the missing puzzle piece. I should have been able to catch that one in your posted example but also missed it.

Thank you for your help any way Taras - I’m new to this so I was convinced I was doing something wrong. :wink:

I works great now !