I am trying to make a sensor to identify when my alarm has gone offline.
It should update every 10 seconds, but if the last update is more than 60 seconds ago, I want to indicate that it is offline.
I have made a template that calculates the time difference between now() and the last update. But the problem is that is only updating every time the “last_update” sensor changes, and when the alarm goes offline, the last_update sensor never changes and my template never updates… mission failed… : (
How do I make the sensor to update every 5 seconds?
Can I use this service somehow?
- service: homeassistant.update_entity
entity_id: sensor.example
Here is my code so far,
alarm_connected:
friendly_name: "Alarm connected"
value_template: >
{% set value = states('sensor.alarm_last_update') %}
{% set last_updated = as_timestamp(strptime(value, "%Y-%m-%d %H:%M:%S")) %}
{% set seconds = now().timestamp()-last_updated %}
{{ seconds }}