I’m using a HA setup, which is somehow restriced concerning how I can access the system and therefore, I only check recorded values once I’m sitting in front of a dedicated PC.
Last week, something happened and the HA stopped recording temperature values and no one noticed that, because recently no one has been using the dedicated PC.
Therefore my question is: is there something already availabe to e.g. write a log and to put this one to a samba share (which I could check from another PC). Or is there an idea existing, concerning how this isolated system could make itself heard?
One way to detect if a sensor’s value is stale (i.e. has not changed for a long time) is to compare the entity’s last_changed to the current time. If it’s more than some threshold value, like 30 minutes, that means the entity’s value hasn’t changed in the past half-hour.
You can create an automation with a Template Trigger that triggers when the monitored temperature sensor is stale. The action can be whatever you want. It can log the incident to a file, notify you, do both and more. In the example below it simply posts a notification to all notification services you have configured.
alias: example abc123
trigger:
- platform: template
value_template: "{{ now() - states.sensor.temperature.last_changed >= timedelta (minutes=30) }}"
action:
- service: notify.notify
data:
title: Stale Temperature
message: "{{ now().timestamp() | timestamp_local }} Value unchanged for the past 30 minutes."
Thank you both for your answer. The issue is still that the system is isolated, so it cannot simply send me a notification on my mobile phone or similar actions. Therefore my idea was to log those issues somewhere into a file placed in a shared folder. Is there a well known way to do that?
You can use the File integration to send notifications to a file.
The file platform allows you to store notifications from Home Assistant as a file.
If you want the file to reside not on the host machine but a shared Samba drive on the network, you will need to mount it (using your Linux skills). Search online for “linux mount samba drive”.
Would this approach work even though the “last_changed” property is reset when you restart Home Assistant? I mean, if you restart HA wouldn’t it behave as if your sensor received data and was updated, amd therefore not trigger your notification?
Given that the goal is to determine how long it’s been since the sensor’s value changed, you’ll be hard-pressed to find an alternative to using the state property dedicated to reporting the time of a state-change (last_changed).
Well, yes. But I suppose we should try to avoid using the last_changed property then.
Maybe there’s a way to have an automation which compares a new value to a previous value and see if it is different. This would work well for things like temperature sensors where consecutive readings are often different to each other. Possibly there is a way to check if a restart happened in the last few minutes and dont run the automation action in that case.
Smelly workaround I know, but just looking for ideas.