Forgive me… I’m a noob.
i’ve read many posts here talking about yaml formating being the cause of templates not working.
i’ve tried many of the suggested fixes… the error remains.
2024-01-17 22:56:19.257 ERROR (MainThread) [homeassistant.config] Invalid config for ‘template’ at templates.yaml, line 2: ‘template’ is an invalid option for ‘template’, check: template
the code in my templates.yaml files is:
template:
- sensor:
friendly_name: "Average Home Temparature"
unit_of_measurement: "°C"
value_template: "{{ (float(states('ssensor.thermostat_ecobee_kitchen_temperature')) + float(states('sensor.air_sensor_3_temperature_2')) + float(states('sensor.air_sensor_ecobee_2nd_bedroom_temperature')) + float(states('sensor.air_sensor_ecobee_master_bedroom_temperature')) + float(states('sensor.air_sensor_2_temperature_2')) + float(states('sensor.air_sensor_1_temperature'))) / 6 | round(2) }}
"
any suggestions would be welcomed.
thanks
Pierre
I tried re-writing based on the documentation.
template:
- sensor:
- name: "Average Home Temparature"
unit_of_measurement: "°C"
state: >
{% set kitchen = states('sensor.thermostat_ecobee_kitchen_temperature') | float %}
{% set LivingRoom = states('sensor.air_sensor_3_temperature_2') | float %}
{% set BedRoom2 = states('sensor.air_sensor_ecobee_2nd_bedroom_temperature') | float %}
{% set MasterBedroom = states('sensor.air_sensor_ecobee_master_bedroom_temperature') | float %}
{% set Bathroom2 = states('sensor.air_sensor_2_temperature_2') | float %}
{% set MasterBathroom = states('sensor.air_sensor_1_temperature') | float %}
{{ ((kitchen + LivingRoom + BedRoom2 + MasterBedroom + Bathroom2 + MasterBathroom) / 6) | round(1, default=0) }}
same results
tom_l
January 18, 2024, 5:29am
3
In your configuration.yaml file you have this:
template: !include templates.yaml
Now imagine what would happen if you removed that !include
and just put the config from your file under it (this is what the include does):
template:
template:
- sensor:
- name: "Average Home Temparature"
unit_of_measurement: "°C"
state: >
{% set kitch..etc
Do you see the problem?
Remove the line template:
from your templates.yaml file and adjust your indentation so that the templates.yaml file contains:
- sensor:
- name: "Average Home Temparature"
unit_of_measurement: "°C"
state: >
{% set kitch..etc
There are other issues with your template though. What happens if one or more sensors are unavailable?
A simpler approach might be to use this:
It can be set up from the UI or by using YAML:
sensor:
- platform: min_max
nmae: Average Home Temperature
type: mean
round_digits: 1
entity_ids:
- sensor.thermostat_ecobee_kitchen_temperature
- sensor.air_sensor_3_temperature_2
- sensor.air_sensor_ecobee_2nd_bedroom_temperature
- sensor.air_sensor_ecobee_master_bedroom_temperature
- sensor.air_sensor_2_temperature_2
- sensor.air_sensor_1_temperature
It will calculate the mean temperature of the available sensors, ignoring sensors that are unavailable.
1 Like
thanks,
took your advice, removed the templates.yaml, the !include statement, and created a helper in the UI.
that worked but the Min/Max was not in the list but the “Combine the state of several sensors” worked great.
Thanks