How to get the RIGHT temperature?
What is the real outside temperature?
My sensors reported temperatures ranging from 13.7° to almost 19°??
Temperature sensors in my system:
- Zigbee – Philips Hue indoor/outdoor motion sensor
- Bluetooth – XIaomi temp sensor
- 433 Mhz – Oregon scientific sensors (fantastic devices!)
- Zigbee – Aquara temp sensor (horrible)
- Wifi – Shelly
- MQTT – Ulanzi clock temp sensor
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?
- 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.
- Use the external service temperature as the default fall-back of the local sensors.
#1 – template sensor: create the average sensor in your configuration.yaml (note that in the next steps the code below is improved).
- Go to the HA Helper section and add a new helper
- Helper type: template
- Template type: Template a sensor
- Paste the template code below. This
{{ ( ( states('sensor.motion_frontdoor_temp') | float() + states('sensor.motion_garage_temp') | float() + states('sensor.outside_temp') | float() ) / 3 ) | float(0) | round(1) }}
If any of the above sensors fails or is unavailable, the template sensor breaks. How to fix this?
#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(10)
This uses a default value of “10”. Why 10 °C? That is the average temperature in the Netherlands. If any of the temperature sensors fail. The example below uses a default of “10” for each failing sensor. Note that the example below has an additional “round(1)” to round the temperature to one decimal. The updated template for the template helper:
{{ ( states('sensor.motion_frontdoor_temp') | float(10) + states('sensor.motion_garage_temp') | float(10) + states('sensor.outside_temp') | float(10) ) / 3 | round(1) }}
Could we make it more accurate?
That can be done by including data from an external service like the Buienradar integration (in the Netherlands) .
#3 – including an external sensor from a weather service. Updated helper template:
{{ (( states('sensor.motion_frontdoor_temp') | float(10) + states('sensor.motion_garage_temp') | float(10) + states('sensor.outside_temp') | float(10) + states('sensor.buienradar_temperature') | float(10) ) / 4) | 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(10)” for that sensor is important.
Ideally you may not want to use a fixed value for the default “in case it fail” temperature (10 °C)
When it’s not this temperature it will make it unreliable.
FIX? Use the external integration temperature value.
#4 – use external sensor as fallback for the other sensors. Updated helper template:
{% set mytemp = states('sensor.buienradar_temperature') | float(10) %} {{ (( states('sensor.motion_frontdoor_temp') | float(mytemp) + states('sensor.motion_garage_temp') | float(mytemp) + states('sensor.outside_temp') | float(mytemp) + mytemp ) / 4) | round(1) }}
What happens in this template?
- Create variable with the external Buienradar temperature value (w/10 degrees as a fallback)
- Calculate the average of local sensors and the external Buienradar temperature
- Each having a fallback of the external Buienradar temperature.
Congratulations with your MEGA OVERENGINEERED temperature.
update: this is what I also realized and now only use the Buienradar temperature as the outside temperature! :-)
So this was all for nothing?
No. It’s about the thought process and how do you go from problem to solution. This knowledge can be used in a lot more places!
Bonus: Card
The card below uses the very valuable card_mod plugin in order to customize things like colors and spacing. It’s best to install card_mod via the HACS plugin.
The last “card-mod” changes the spacing between entities displayed on the card.
type: entities entities: - entity: sensor.temp_rfx_atticfront_temperature name: FRONTDOOR hue - entity: sensor.temp_rfx_outside_temp name: GARAGE hue - entity: sensor.temp_rfx_office_temperature name: OUTSIDE - entity: sensor.temp_rfx_bedroom_temperature name: Outside AVERAGE card_mod: style: hui-generic-entity-row: $: .info.pointer: | .text-content { color: DeepSkyBlue; font-weight: 600; vertical-align: top; } - entity: sensor.buienradar_temperature name: Buienradar ..temp card_mod: style: hui-generic-entity-row: $: .info.pointer: | .text-content { color: lime; vertical-align: top; } title: Average Outside Temp card_mod: style: .: | ha-card div#states div { margin-top: -15px !important; margin-bottom: -15px !important; }
Liked it?
Or feedback? Let me know!