Value_template for multiple entities using numeric_state

How can do i use templating inside the value_template to reference the list of entities I have passed in the entity_id list below?

The goal of what i want to do is get the temperature of each one of the entities and average them. However, while i know I can use {{ state_attr('climate.upstairs_thermostat_mode', 'current_temperature') }} inside the value_template, i want to know if there is a way to reference the entities in the list I am passing sort of like the same principle of principle 7 here

  - condition: numeric_state
      - climate.upstairs_thermostat_mode
      - climate.downstairs_thermostat_mode
    value_template: '{{  }}'
    below: 70

Use the minmax sensor to create a new sensor with the average reading, and use that sensor in your numeric_state condition.

Or use a template condition.

  • Principle 7 isn’t referencing the entities listed in entity_id.
  • The template has no visibility into entity_id.
    - The Template integration will be changing and the entity_id option is being deprecated. my mistake; this is a condition

Long story short, don’t waste your time and just write the template without employing entity_id.

Are those two entities the only climate components you have in your system or are there others?

There’s a thought, but try to limit the amount of extra sensors I make, but I will look into this thank you!

1 Like

I think you are right in saying this

Long story short, don’t waste your time and just write the template without employing entity_id .

Actually i’m using the following 2 entities for now:

- sensor.upstairs_thermostat_air_temperature
- sensor.downstairs_thermostat_air_temperature

These are the 2 entities only, for now. I do plan later to add more, potentially to have a whole home temp reading. I’m trying to make my automation be when I arrive home to read the current temp of the house and based on that it can set the temperature and the hvac_mode (cool or heat).

This calculates the average current_temperature of all climate entities.

    value_template: >
      ​{% set t = states.climate | map(attribute='attributes.current_temperature') | list %}
      {{ t | sum / t | count }}

Be advised that it doesn’t guard against a divide-by-zero error (which will happen if there are no climate entities).

1 Like

Damn you are really good at templating, this is not the first time you have helped me… :slight_smile:

However, the more I thought about this, the more I think this may be easier to do in appdaemon. Reason being my intention for this automation was

Alarm changes from armed_away > disarm
IF average temp > 70 THEN set climate to cool and 73
IF average temp <= 70 THEN set climate to heat and 71

BUT I just remembered the way automations work, at least as far as I know, they stop after the first false occurs in conditions so now I think this will not work for me.

Beginning with version 0.113, an automation can use choose to permit branching in the execution flow. In other words, you can now use choose like an if-elif-else or select-case.

See: Script Syntax - Home Assistant

Ahh this is why i am using these automations now. Trying to learn more. Never have done, as you can tell automations in HA mainly since I found them not as intuitive as appdaemon and nodered, but trying to put the simpler automations in yaml.

Thank you! I will use chooser and I actually did this template, but may use the min/max sensor instead given it can account for unavailable sensors. Haven’t decided need to play with it.

value_template: "{{ (float(states('sensor.downstairs_thermostat_air_temperature')) + float(states('sensor.upstairs_thermostat_air_temperature')))/2 > 70 }}"

FWIW, the template I posted can be easily enhanced to reject unavailable entities.

Anyway, your original question has been answered.

and them some, thank you!

1 Like