Notification in case no values have been recorded since X

Hi all,

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?

Thanks,
Till

Are you recording a sensor’s value? If yes, you can create an automation to notify you if the sensor goes to unavailable state.

trigger:
  - platform: state
    entity_id: sensor.helloworld
    to: unavailable
    for: '00:01:00'
action:
  - service: notify.mobile_app_your_name
    data:
      message: Alert!

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."
8 Likes

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 must have missed this part in my reply:

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”.

How can I add more sensors to the automation? For example all temperature sensors.

Probably with a template that’s more complex than the simple one in this 2 year-old topic.

The example in this post can serve as a starting point:

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?

Currently, that’s an inescapable consequence of a restart.

I see.

Do you happen to know of another way to achieve this? (I’m restarting every night for a backup of my HA virtual machine).

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.

Unfortunately, I don’t have available free time to speculate about what may or may not work or to experiment with other people’s proposals

I suggest you test your idea and report back if it works. Good luck!