Hello,
I have several home-made battery powered temperature sensors driving various thermostats.
There have been a couple of occasions where a sensor will stop sending updates (become “stale”) for different reasons:
- Connectivity issue
- Power issue
- User issue
This causes knock-on issues with thermostats driving heaters, which will either not heat or heat without stopping leading to too cold/too hot.
I have setup an automation per sensor to switch off disable any associated thermostats while the issue is fixed, and notify me. I have not yet setup automations to re-enable disabled thermostats once data is received again. This feels quite manual/laborious so my first question is:
1. Can you programmatically create/define automations using arrays of, in my case, sensors and related thermostats? Ideally I would have a list of sensors that I care about, and what to do if they go stale/go back online.
2. If this is not possible, can you include loops inside automations?
Secondly, I’d like to update the display of the sensors to show “NaN” or similar, to flag to me visually when I have stale sensors (sometimes I don’t fix them immediately and forget).
I’ve tried this example I found in the forum, to change a sensor reading if older than 4 hours:
- platform: mqtt
state_topic: "kitchen/temperature"
name: "Kitchen Temperature"
unit_of_measurement: "°C"
value_template: >
{% if (as_timestamp(now()) - as_timestamp(states.sensor.kitchen_temperature.last_changed))/(60*60) > 4 %}
{{ 'NaN' }}
{% else %}
{{states('sensor.kitchen_temperature')}}
{% endif %}
But of course, NaN
leads to:
as, it’s not a number…
Is anyone else dealing with stale sensors and have a solution?
If I use -1
it could switch on thermostats which haven’t been disabled by the above, and given how bad it is when a heater is fully switched on and overheating a living area, I’d like the security of having both the automation and visual cue.
Any tips welcome!
Amadeus