I have experienced self-built D1Mini+Tasmota based sensor units losing its connection to the WiFi and thus stop sending its MQTT values for temperature etc.Remedy is recycling power to the unit. I’d like to implement an alert upon frozen critical values, since I use temperature as input for basic thermostats etc.
Is there a way in Home Assistant to detect if a value, hasn’t been changed for a certain amount of time?
I was thinking along the same lines for my none Tasmota D1 Minis that also record temperature and humidity. I haven’t got around to it yet but my idea was to see how long it is since the last_changed or last_updated changed, then send a notification if they hadn’t updated within an expected update time period.
Below is an example but may not work, not at home and currently no access to my home assistant config:
- alias: Offline sensor
trigger:
platform: template
value_template: {{ (as_timestamp(now()) - as_timestamp(states.sensor.bathroom_temperature.last_updated)) > 600 }}
action:
service: notify.telegram
data:
message: "Bathroom temperature has not updated for 10 minutes, sensor may need restarting."
I was just writing something similar for my circumstance, my sensors send a regular heartbeat similar to ESPhome and could use that, not sure Tasmota does this?
Thanks!
Tried the following (Tasmota sends uptime every 300s by default), but it doesn’t seem to trigger.
When testing it in the template editor it returns ‘true’ after 100s (obviously different value than in the automation just for the test).
Any ideas as to why it doesn’t seem to trigger?
- id: '088'
alias: Check Tasmota Communication Living Room
trigger:
platform: template
value_template: '{{ as_timestamp(now()) - as_timestamp(states.sensor.stue_uptime.last_changed) > 500 }}'
action:
service: notify.notifypushbullet
data:
message: "Check living room sensor unit, communication seems frozen."
I am never sure when it comes to quotes and formatting in YAML, but the example on the automation page shows double quotes rather than single around the template. No idea if it will make a difference. That may be because the example already has single quotes as well. If not, then check all the spacing in case you copied and amended my example, it could have wrong spacing or other formatting errors. Won’t be able to check with mine for a couple of hours.
…returns ‘True’ after the correct number of seconds.
I’ve tried both in automation.yaml, but the the automation just does not seem to trigger. I’m lost.
Edit:
You led me into the documentation and I noticed that it states that “Rendering templates with time ( now() ) is dangerous as trigger templates only update based on entity state changes.”
If I understand this correctly, the value_template will not be processed (trigger the automation) unless there is a change in the “uptime” entity. Which was the case I wanted to detect.