How to monitor/track unavailable devices

If you’re looking for a list of your sensors that have a status of ‘unavailable’ this would do it.

{{ states.sensor | selectattr('state', 'eq', 'unavailable') 
                 | map(attribute='name')
                 | list }}
3 Likes

@anon43302295, @Oliviakrk

I think this condition would do what you guys were looking for. Personally I would put this into the trigger so you’d get a notification right away instead of waiting for a specific time but that’s me.

condition: template
value_template: >
  {% set unavails = states.sensor | selectattr('state', 'eq', 'unavailable') 
                 | map(attribute='name')
                 | list
                 | length  %}
  {{ unavails > 0 }}
6 Likes

It works!

Thanks.

I made two automations: one to inform me a device has just died and a second one as a daily report.

Glad I could help. I had some time this afternoon so I played with this a bit more and came up with a nifty little unavailable sensor senor. Thought you might find it interesting.

4 Likes

Is this the proper syntax, using the template as the Trigger?

- alias: Alert when entity is unavailable
  trigger:
    platform: template
    value_template: "{% for item in states %}\n  {% if item.state == 'unavailable'\
      \ %} true\n  {% else %} false {% endif %} \n{% endfor %}\n"
  condition: []
  action:
  - service: notify.mobile_app_snote8
    data_template:
      message: "{%- for item in states -%}\n  {%- if is_state('item', 'unavailable')\
        \ -%} {{ item.attributes.friendly_name }} unavailable  {%- endif -%} A\n{%-\
        \ endfor -%}"

I have created/added this yaml file, but how do I use this in an automation? Will the Trigger be this sensor?

I think that gist is an older version of the sensor. There is another thread where there was a collectively improved version. I would use this instead of my gist code linked here. If you have questions I would ask them in that thread, it was way more active than this one.

As for your question, you can use the state of this sensor to trigger an automation as you would any other sensor. Since the state of this sensor is a numeric value with anything other than 0 meaning there is an unavailable sensor you can just use a numeric value trigger.

Thank you!

Anchio ho lo stesso problema, qualcuno ha risolto ? Grazie

Since this thread is so long, I’m compiled what you need to do in a single blog post. Hope it saves you guys some time!

3 Likes

Great guide, many thanks!
If i understand correct this monitors all entities except ignored ones, right? Right now i have my set up reversed: i monitor only entities i want and i put those ones in “included_entities” group. Maybe it would be a good idea to add this guide, too (if you have time, sure…) Of course, both versions have good and bad side… but i prefer this way, since i always “tinker” with HA and modules, so i have pretty much constantly some offline entities and very often different ones. So i would had to add exclusions constantly…

I did exactly that - very simple change to the code to include rather than exclude. Works great.

Very good!
But it should be possible to add domains in the exclusion group, for example medai_player* (wilcard ?)

1 Like

could you share how you did this? I want to do this, but I cant seem to be able to add groups in the yaml configuration (only for binairy sensors, lights etc.)

I ended up using package, i think it’s THIS ONE. Works great, althoug now i see that i have outdated version (author did quite some changes from back then). But it works perfect. I ended up using original version - all unavailable entities are shown except ignored ones. Using it reversed is - well, a bit “dangerous” since it’s very easy to forget to add new sensos/device and you don’t have a control over it.

Nice guide, and I’m glad you found the template useful. But the very least you could have done was attributed and linked back to the original source. @Protoncek has done that for you here, perhaps you should consider doing the same on your blog.

@jazzyisj im using the GIT code and it works great, but what I am now finding is i really dont care about the entity as much as I care about the device. At the end of the day, in most cases, fixing the device fixes several of its entities. How do i get the parent device from the entity?

1 Like

1 Like

Hi,
Anyone tried to use the code which have as example on documentation?

Didn’t work?

  • has_value('sensor.my_sensor') will test if the given entity is not unknown or unavailable. Can be used as a filter or a test.

I had a similar issue with an unavailable device upsetting my values. The following code in configuration.yaml worked for me;

template:
  - sensor:
    - name: "Total Solar Power"
      unique_id: total_sol_power
      unit_of_measurement: "W"
      device_class: power
      state_class: measurement
      state: >
        {% if is_state('sun.sun', 'below_horizon') %}
          {{ 0 }}
        {% elif is_state('sensor.pv4_power', 'unavailable') %}
          {{ states('sensor.pv1_power') | float | round(3) + states('sensor.pv2_power') | float + states('sensor.pv3_power') | float }}
        {% else %}
          {{ states('sensor.pv1_power') | float | round(3) + states('sensor.pv2_power') | float + states('sensor.pv3_power') | float + states('sensor.pv4_power') | float }}
        {% endif %}