How to get the RIGHT temperature?
What is the real outside temperature?
My sensors reported temperatures ranging from 13.7° to almost 19°??
Erhh, wich sensor should I believe?
Temp | Device | Protocol | |
Frontdoor | 15.6 ° | Philips Hue Motion | Zigbee |
Garage | 13.7 ° | Philips Hue Motion | Zigbee |
Outside | 18.9 ° | Oregon THGR 328N | 433Mhz |
Buienradar.nl | 15.5 ° | Website | https |
Note that in the morning the outside sensor seems the most reliable and in the evening the frontdoor sensor.
Then I remembered a BBC video from 2011 where prof. Marcus du Sautoy did an experiment where a large group of people had to guess the number of jellybeans in a big glas jar (containing 4510 jellybeans).
The answers ranged from 400 to almost 50,000 which is crazy…. But…
The AVERAGE of all answers was 4515!
Many individual answers did not make sense but the collective thinking was extremely powerful. Weren’t we talking about temperatures? Yes, let’s get back to the topic.
With that in mind..
I figured, why not use the average of all outside temperature sensors?
Requirement: template-entity-row (community, github this is to display a calculated item)
Here’s how to show the AVERAGE outside temperature based on 3 sensors.
First, display 3 sensors and then display the average.
type: vertical-stack
cards:
- type: entities
entities:
- entity: sensor.motion_frontdoor_temp
name: FRONTDOOR hue
- entity: sensor.motion_garage_temp
name: GARAGE hue
- entity: sensor.outside_temp
name: OUTSIDE rfx
- type: custom:template-entity-row
icon: mdi:temperature
name: AVERAGE outside temperature
state: >-
{{ ( ( ( states('sensor.motion_frontdoor_temp') | float )
+ ( states('sensor.motion_garage_temp') | float ) + (
states('sensor.outside_temp') | float )) / 3 ) |
round(1) }} °C...
This approach has a few problems:
- The average is only visible on that card, nowhere else in the system. Put this data in a sensor and it can be used in automations, cards and scripts.
- It does not account for a problematic sensor without temerature data (battery empty, transmit/receive problem)
- No “official” weather data is used.
Solution?
- Create a template sensor that calculates the average.
- Make the sensor use a default value if any of the sensors does not return the right data.
- In the average calculation, include a temperature sensor created by the Buienradar integration. Use any weather service as long as it provides an entity containing the outside temperature in your area.
Detailed info:
#1 – template sensor: create the average sensor in your configuration.yaml (note that in the next steps the code below is improved)
template:
- sensor:
- name: "Outside Temperature Average"
unit_of_measurement: "°C"
state: >
{{ ( ( ( states('sensor.motion_frontdoor_temp') | float ) + ( states('sensor.motion_garage_temp') | float ) + ( states('sensor.outside_temp') | float )) / 3 ) | float | round(1) }}
#2 – use a default value in case a sensor fails or does not return the right data. Example:
Instead of using:
states('sensor.motion_frontdoor_temp') | float()
Use:
states('sensor.motion_frontdoor_temp') | float(15)
This uses a default value of “15” if any of the temperature sensors fail. In the example below I have added a default of “0” if the overall template sensor fails. Average temperature “0”? Then you know something is wrong. The updated card:
- name: "Outside Temperature Average"
unit_of_measurement: "°C"
state: >
{{ ( ( ( states('sensor.motion_frontdoor_temp') | float(15) ) + ( states('sensor.motion_garage_temp') | float(15) ) + ( states('sensor.outside_temp') | float(15) )) / 3 ) | float(0) | round(1) }}
Something to test: “default” individual sensors or only “default” the total calculation?
#3 – add an external sensor from a weather service. The (FINAL) result:
- name: "Outside Temperature Average"
unit_of_measurement: "°C"
state: >
{{ ( ( ( states('sensor.motion_frontdoor_temp') | float(15) ) + ( states('sensor.motion_garage_temp') | float(15) ) + ( states('sensor.outside_temp') | float(15) ) + ( states('sensor.buienradar_temperature') | float(15) )) / 4 ) | float(0) | round(1) }}
Note that an external (integration dependant) temperature sensor MAY NOT BE AVAILABLE right after startup. That could result in errors appearing in the log. Therefore using the default “float(15)” is important.
create a card
In the below card I have removed formatting configuration. Scroll down for the full card YAML including entity colors and a compressed view (nice!).
type: entities
entities:
- entity: sensor.motion_frontdoor_temp
name: FRONTDOOR hue
- entity: sensor.motion_garage_temp
name: GARAGE hue
- entity: sensor.outside_temp
name: OUTSIDE rfx
- entity: sensor.outside_temperature_average
name: Outside AVERAGE
- entity: sensor.buienradar_temperature
name: Buienradar Temp
title: Average Outside Temp
Next?
- Your feedback?
- IDEA: Turn this into a blueprint?
- IDEA: instead of using a fixed value as a backup temperature (above: 15) you could also take a little risk and use another your most reliable temperature sensor as the backup. One step further: create a sensor that holds your most reliable temp and use that as the backup.
FULL CARD CODE, including lay-out changes:
The last “card-mod” changes the spacing between entities displayed on the card.
type: entities
entities:
- entity: sensor.motion_frontdoor_temp
name: FRONTDOOR hue
- entity: sensor.motion_garage_temp
name: GARAGE hue
- entity: sensor.outside_temp
name: OUTSIDE
- entity: sensor.outside_temperature_average
name: Outside AVERAGE
style:
hui-generic-entity-row:
$:
.info.pointer: |
.text-content {
color: blue;
font-weight: 600;
vertical-align: top;
}
- entity: sensor.buienradar_temperature
name: Buienradar ..temp
style:
hui-generic-entity-row:
$:
.info.pointer: |
.text-content {
color: green;
vertical-align: top;
}
title: Average Outside Temp
card_mod:
style:
.: |
ha-card div#states div {
margin-top: -10px !important;
margin-bottom: -10px !important;
}
Liked it?
Let me know!