Mark entities or sensors unavailable that did not send messages for a certain time

Is there any way to mark devices or as unavalable or mark them if they did not send messages for some time. I try to find this our with my RFXtrx433 senssors, but would like to know this for other devices and entities also.

When looking at devices with http://homeassistant.local:8123/config/devices/dashboard I see all devices known to the system. And with http://homeassistant.local:8123/config/entities I can see ann entities. There is no column that shows when the device or entity has been seen last time.

Background:

  • The Oregon sensors that I use send messages every x seconds. I would like to know if there is a sensors not sending updates for some hours
  • The X10 sensors that I use send messages if something changes, but also sends keepalive messages every hour.

Ist there any way to mark sensors as unavaliable when they did not send messages? Or show when the last update occured as a list?

Or is this something only the RFXtrx integration could do? If yes, is there any discussion list für RFXtrx integration

Welcome to the forums, wil!

A simple display would be this:

# last changed
type: markdown
content: |2-
    {% for x in states.sensor
    |sort(attribute='last_changed', reverse=true)
     %}
    <b>
    {%- if x %}
      {%- set name = x.name %}
      {%- set time = x.last_changed.strftime('%T') %}
      {{- '• ' ~ name ~ ': ' ~ time -}}
    {% else %}
    {% endif %}
    </b>
    {% endfor %}

or


# last updated
type: markdown
content: |2-
    {% for x in states.sensor
    |sort(attribute='last_updated', reverse=true)
     %}
    <b>
    {%- if x %}
      {%- set name = x.name %}
      {%- set time = x.last_updated.strftime('%T') %}
      {{- '• ' ~ name ~ ': ' ~ time -}}
    {% else %}
    {% endif %}
    </b>
    {% endfor %}

The code above can be more specified if you tell the attributes of your sensors you want to monitor.

Thanks a lot. The Display cards are very flexible. Great!

Nice would be to have the current time and subtract this from last seen. And just display the items that did not update for xxx seconds.

Where can I find more information of the scripting you did? Any pointer would be fine.

Google told me that Homeassistant uses jinja as a scripting language for the Display cards. Any other pointers on documentation to script? Do I have to import datetime to use datetime for the current time?

I am willing to extend this on my own.

See the link to the Jinja2 documentation in Developer Tools —> Template or here: Template Designer Documentation — Jinja Documentation (3.1.x)
and Templating - Home Assistant

The example below takes an ignore time into account and computes the relative time since last changed:


type: markdown
content: |2-
    {% set ignore = now() - timedelta(seconds=30) %}
    {% for x in states.sensor
    |rejectattr('last_changed','>=',ignore)
    |sort(attribute='last_changed', reverse=true)
     %}
    <b>
    {%- if x %}
      {%- set name = x.name %}
      {%- set time = relative_time(x.last_changed) %}
      {{- '• ' ~ name ~ ': ' ~ time ~ ' ago' -}}
    {% else %}
    {% endif %}
    </b>
    {% endfor %}

Note that the frontend will not update automatically.

1 Like

Great. Thanks a lot!

1 Like

Note that last_updated is actually the time of the last change. So if the sensor did update but the value did not change last_updated is not updated