Syntax question for Loop to find "Unavailable" or "Unknown"

I need this toi determine which sensors have an issue to see if it is always the same ones. I am having Yolink stability issues - so, I have this for a couple of sensors in my configuration.yaml:

template:
  - binary_sensor:
      - name: "Any Yolink Unavailable"
        state: "{{ integration_entities('yolink') | select('is_state', 'unavailable') | list | count > 0 }}"
        unique_id: any_yolink_unavailable

  - binary_sensor:
      - name: "Any Yolink Unknown"
        state: "{{ integration_entities('yolink') | select('is_state', 'unknown') | list | count > 0 }}"
        unique_id: any_yolink_unknown

This will of course return the correct values in the Developer Tools → Templates area as well - but in the same template tools section how do I (using a for loop or the like) to make it just show the unavailable or unknown sensors (their names)?

The integration_entities() function returns the entity ID, so you just need to remove the comparison and count, i.e.

{{ integration_entities('yolink') | select('is_state', 'unavailable') | list }}

Adding it as an attribute will maintain it as a list.

template:
  - binary_sensor:
      - name: "Any Yolink Unavailable"
        state: "{{ integration_entities('yolink') | select('is_state', 'unavailable') | list | count > 0 }}"
        unique_id: any_yolink_unavailable
        attributes:
          entity_id: "{{ integration_entities('yolink') | select('is_state', 'unavailable') | list }}"

      - name: "Any Yolink Unknown"
        state: "{{ integration_entities('yolink') | select('is_state', 'unknown') | list | count > 0 }}"
        unique_id: any_yolink_unknown
        attributes:
          entity_id: "{{ integration_entities('yolink') | select('is_state', 'unknown') | list }}"

Depending on what you want, it is also possible to sort them by any attribute of the individual entities.

1 Like

Thank you @Didgeridrew