A template sensor that averages two thermometers will happily produce nonsense when one of them goes offline, often a zero that ruins your graph. Say when the value can be trusted.
Add availability next to the state:
template:
- sensor:
- name: "Upstairs average"
unit_of_measurement: "°C"
availability: >
{{ has_value('sensor.bedroom_temp') and has_value('sensor.office_temp') }}
state: >
{{ ((states('sensor.bedroom_temp') | float +
states('sensor.office_temp') | float) / 2) | round(1) }}
has_value is false when an entity is unknown or unavailable. While the availability template gives a false result, your sensor reads as unavailable and the state is left alone. Graphs show a gap, which is honest, and automations that react to a temperature don’t fire on a fake one.
Paste the expression into Developer Tools, Template, first to see it evaluate against your real entities.
It also means you can drop the float(0) habit, where a default quietly turns a dead sensor into freezing weather.
The flip side: an unavailable sensor can break something downstream that expects a number, such as another template or a dashboard card with thresholds. Give those the same treatment. And if one source is often flaky, I’d fix the radio link or battery instead of building ever cleverer fallbacks around it.
Further reading: Home Assistant template integration
Going deeper: Guide: Home Assistant backups in Docker, with a failure alert on your phone and a copy off the box