Monitor unavailable state of (rest) integrations

Yeah, am just trying to find out how…

I’m experimenting with this but doesnt work unfortunately. It doesnt show me one currently unavailable rest integration

type: custom:auto-entities
card:
  type: entities
  title: Unavailable REST integrations
  show_header_toggle: false
filter:
  include:
    - domain: rest
      state: 'unavailable'
sort:
  method: name
  ignore_case: true

Got some help from TheFes…
{{ integration_entities('rest') }}
gives you all the rest sensors, from there on you can filter on state and fire this through an automation that could send either the list or a notification per entry

The result of this is empty unfortunately:

{{ integration_entities('rest') | selectattr('state', 'eq', 'unavailable') | list }}

Your template shows all rest integrations but I think it doesnt have any additional information like state

They are strings so not object with attr. My (possibly non efificient) solution would be to iterate over them and find the object via expanding sensors, then you can use attr… let me know if I need to provide some help…repeating that I am not the specialist but it will get you what you want (likely)
EDIT: am away from server rright now so no examples

vingerha is on the right track, expand will take the list of entity_id’s and convert it to a list of state objects, and then the filtering will work. Then it can be mapped back to an entity_id or a friendly name depending on what output you want.

{{ integration_entities('rest') | expand | selectattr('state', 'eq', 'unavailable') | map(attribute='entity_id') | list }}

However there are more polished solutions for listing all unavailable entities.

There are more solutions to list entities/devices but the OP stated to aim for ‘rest’ only hence. In order to send a notification it requires a list of rest entities in a certain state if (!) you want to use automations. Sending a list with unavailable things can also be done with (hacs) watchman

I’m just going off this statement.

Many ways to skin this cat, all have their own pros and cons.

@mekaneck
The links you’ve shared is about monitoring devices and entities.
I’m looking for the rest integrations or all integrations.
any suggestions for this?

I was thinking about renaming all rest sensors to include the word “rest” at the beginning.
this way I can filter easily.
or maybe better: I see that all of my rest sensors have attributes. When a rest sensor doesn’t pull its data > it doesn’t contain an attribute ( but it still shows available in HA!? )
maybe I can filter those rest sensors that doesn’t have any attributes.

Maybe we’re not using the same language here. Integrations don’t go unavailable and in fact they don’t have a state at all. Neither do devices. In HA, entities are the only things that have a state.

But you could, for example, look for which entities are unavailable and then determine which devices or integrations they belong to.

Or if you want to detect integrations that have errors (like the ones that have a red box around them when you view all your integrations by navigating to settings → devices and services) you could monitor for specific log errors. To do this, you can configure HA to fire events when items are posted to the log, and you can trigger off those events. Here is a post about that.

If none of this is getting what you want, it would be helpful if you could explain a bit more about what you’re actually trying to accomplish.

Or as a list… you would have to play around a bit

{% set ns = namespace(restlist=[]) %}
{% for x in integration_entities('rest') %}
{% set y = (states.sensor | 
   selectattr('entity_id', 'eq', x)) | selectattr('state', 'eq', 'Green') | map(attribute='name') | list  %}
{% set ns.restlist = ns.restlist + y %}
{% endfor %}
{{ ns.restlist }}

That’s the more complicated way of doing this

Yep… as I mentioned earlier…not the specialist, just a hacker with ideas

thanks for thinking along!

After some further research, filtering by state may not be the right way to do it after all. My rest integrations/sensors remain in the same status even though they cannot retrieve data.
That’s why I was looking for a way to detect the Rest sensors that don’t have custom attributes (i.e. attributes that I defined myself). but this seems difficult to me.

I’m out of options right now. Except the solution described here: Unavailable / Unknown Entity Monitoring - Template Sensor

Does provide a little bit what I was looking for, although I would have liked to see an overview per (rest) integration or bundled somehow.

I donot understand this too well as you have no examples and I no reference. When my rest fails the state usually goes to unknown or unavailable…so maybe you should review how to setup your rest integrations?

For instance one of my rest sensors:

sensor:
- platform: rest
  scan_interval: 60
  resource: !secret solax_local_ip
  payload: !secret solax_local_realtime_payload
  method: POST
  headers: 
    X-Forwarded-For: 5.8.8.8
  name: "solax_rest_local"
  json_attributes:
    - SN
    - ver
    - type
    - Data
    - Information
  value_template: 'Active'
  availability: >-
    {{ is_state('binary_sensor.192_168_2_35','on') }}

and when it successfuly retrieve its data, it shows:


the issue: when its unable to retrieve its data > it doesn’t shows its attributes (like SN, ver, type and Data).
but it still shows Active as state.

What I’m after: I want to know whenever the rest sensors is unable to retrieve data

You have hardcoded the state…why not make that a template-based value? Possibly it kicks back a datetime?

hm maybe I can put something like this in the state:

      {% if value_json is defined and value_json.get('Data') is not none %}
        Active
      {% else %}
        Unavailable
      {% endif %}

something like that…no clue what you get back if it fails to connect, maybe there is an error in thjson response ?

Weird that I didn’t thought about it before. I have changed the state to the template example for all RESTful sensors.
If no data is retrieved now, I will see unavailable as state. Based on this I can make automations or a lovelace card. It can be that simple haha ​​thanks for your patience