giovanni
(Giovanni)
November 9, 2021, 6:30pm
1
I’m feeling like an idiot because I can’t figure it out but I am quite sure that this is all about an indentation issue…
sensor:
- platform: template
sensors:
- name: "Outside temperature"
unit_of_measurement: "°C"
state: >
{% set livingroom_outside = states('sensor.ac_livingroom_outside_temperature') | float %}
{% set kitchen_outside = states('sensor.ac_kitchen_outside_temperature') | float %}
{% set bedroom_outside = states('sensor.ac_bedroom_outside_temperature') | float %}
{{ ((livingroom_outside+kitchen_outside+livingroom_outside) / 3) | round(1, default=0) }}
AllHailJ
(J Gent)
November 9, 2021, 6:38pm
2
Here is one way to do it. Create a sensor
sensor:
- platform: min_max
name: "Upstairs Average Temperature"
type: mean
round_digits: 1
entity_ids:
- sensor.flood_sensor_air_temperature_2
- sensor.owner_bath_toilet_leak_sensor_air_temperature_2
- sensor.flood_sensor_air_temperature_2_2
- sensor.upstairs_temperature
- sensor.wbath_leaksensor_air_temperature_2
All the documentation for this is here:
or I think you are using the old syntax.
template:
- sensor:
- name: "Average temperature"
unit_of_measurement: "°C"
state: >
{% set bedroom = states('sensor.bedroom_temperature') | float %}
{% set kitchen = states('sensor.kitchen_temperature') | float %}
{{ ((bedroom + kitchen) / 2) | round(1, default=0) }}
giovanni
(Giovanni)
November 9, 2021, 6:42pm
3
@AllHailJ thank you so much for the new solution. I had indeed tried to start from the documentation. Could you please tell me, for the purpose of learning, what did I do wrong in my previous code?
Many thanks again,
Giovanni
AllHailJ
(J Gent)
November 9, 2021, 6:50pm
4
try using
template:
- sensor
- name: "Outside temperature"
unit_of_measurement: "°C"
state: >
{% set livingroom_outside = states('sensor.ac_livingroom_outside_temperature') | float %}
{% set kitchen_outside = states('sensor.ac_kitchen_outside_temperature') | float %}
{% set bedroom_outside = states('sensor.ac_bedroom_outside_temperature') | float %}
{{ ((livingroom_outside+kitchen_outside+bedroom_outside) / 3) | round(1, default=0) }}
You also had livingroom twice in the average.
giovanni
(Giovanni)
November 9, 2021, 7:00pm
5
So it doesn’t go into the - sensor
section of configuration.yaml?
AllHailJ
(J Gent)
November 9, 2021, 7:03pm
6
See here
I believe this is the new recommended way. It can if you want to use the min max platform
I use the min_max integration because to me it is simpler. It takes care of all the details and I just list the entities. It can also do Min, Max and Median.
1 Like