Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Unavailable Sensor Detection and Notification
#######################################################################################################################
## Package - Unavailable Entities Sensor - Count and list of entities with state of unavailable, unknown, or none (null)
## NOTE: Home Assistant v0.117+ is required
#######################################################################################################################
## REQUIRED this is the template sensor
## state: number of unavailable entities
## attribute - entities: comma separated list of unavailable entity ids
sensor:
- platform: template
sensors:
unavailable_entities:
friendly_name: Unavailable Entities
unit_of_measurement: entities
icon_template: "{{ 'mdi:check-circle' if is_state('sensor.unavailable_entities','0') else 'mdi:alert-circle' }}"
value_template: >
{{ states|selectattr('state','in',['unavailable','unknown','none'])|rejectattr('domain','eq','group')
|rejectattr('entity_id','in',state_attr('group.ignored_entities','entity_id'))|list|count }}
attribute_templates:
entities: >
{{ states|selectattr('state','in',['unavailable','unknown','none'])|rejectattr('domain','eq','group')
|rejectattr('entity_id','in',state_attr('group.ignored_entities','entity_id'))|map(attribute='entity_id')|join(',') }}
## REQUIRED add any entities you do not want to monitor in this group.
## This group MUST exist even if is empty for sensor template to render.
group:
ignored_entities:
entities:
- binary_sensor.updater
## OPTIONAL Example automation to demonstrate how you can utilize this sensor
automation:
- id: unavailable_entities_notification
alias: "Unavailable Entities Notification"
description: "Create persistent notification if there are unavailable entities, dismiss if none."
mode: restart
trigger:
- platform: state
entity_id: sensor.unavailable_entities
action:
- choose:
conditions:
- condition: numeric_state
entity_id: sensor.unavailable_entities
below: 1
sequence:
- service: persistent_notification.dismiss
data:
notification_id: unavailable_entities
default:
- service: persistent_notification.create
data:
title: Unavailable Entities
message: "- {{ state_attr('sensor.unavailable_entities','entities').split(',')|join('\n- ') }}"
notification_id: unavailable_entities
@DrBlokmeister

This comment has been minimized.

Copy link

@DrBlokmeister DrBlokmeister commented Aug 23, 2020

Hey! Great script! I am using it now, but have modified the notification automation using the new automation mode and a template condition. Maybe it's nice to modify the gist.

This renders the persistent notification creation after startup automation obsolete, as its trigger is added to the first automation. It does however rely on the availability of the uptime sensor. It simply waits until the uptime is larger than 5 minutes (with a 5 minute timeout just in case), rather than delaying the automation for 5 minutes. So if sensor.unavailable_entities changes after startup, it updates the notification instantly.

automation:
  - id: startup_unavailable_entity_notification
    alias: "Startup Unavailable Entity Notification"
    description: "Create persistent notification if there are unavailable entities on or after startup."
    mode: restart
    trigger:
      - platform: homeassistant
        event: start
      - platform: state
        entity_id: sensor.unavailable_entities
    condition:
      - condition: numeric_state
        entity_id: sensor.unavailable_entities
        above: 0
    action:
      # delay to allow sensors to come online, prevent false notifications
      - wait_template: "{{ states('sensor.uptime')|int > 5 }}"
        timeout: '00:05:00'
      - condition: numeric_state
        entity_id: sensor.unavailable_entities
        above: 0
      - service: persistent_notification.create
        data_template:
          title: "Unavailable Entities"
          message: "{{ state_attr('sensor.unavailable_entities','names').split(', ') | join('\n') }}"
          notification_id: 'unavailable_entities'
@jazzyisj

This comment has been minimized.

Copy link
Owner Author

@jazzyisj jazzyisj commented Aug 28, 2020

Glad you found it useful! I've been going through me entire config trying to catch up with the recent improvements in the latest releases. Just got around to this one. I was able to simplify it down to one automation to create and dismisses the automation. Decided to dispense with the delay all together and make it as basic as I could. The only disadvantage I can think of is the notification will keep coming back if you dismiss it and there are still unavailable entities. It's only a quick example to get people up and running so I can live with it :-)

It was a neat solution, though it does depend on the uptime sensor not only being configured, but configured for minutes which might cause problems for people with the sensor configured in hours or days (such as me!) for other uses.

@DrBlokmeister

This comment has been minimized.

Copy link

@DrBlokmeister DrBlokmeister commented Aug 29, 2020

I agree. Your new version is more elegant and less dependent on other things also being set up compared to mine. I'll update my config with yours. 👍

The only thing I do think of is that if the sensor changes a lot, this automation gets queued up a lot and then creates and dismisses a lot of notifications. I think that's not a problem usually, and I cannot really think of an elegant way to solve it. Maybe create a delay at the beginning of the actions of around 5 seconds and change the mode to restart. However, I wonder if that would make a difference, or if it's needed at all.

On another note. I've noticed for example that when my server is turned off, I see a lot of unavailable entities, because a lot of things run on my server. But I don't care about seeing that my Transmission jail or my hard disk temperature sensors are unavailable because I know that happens when my server is off. However, when my server is on, I do care about these things becoming unavailable because this means that something is wrong. Do you know a way of approaching this?

@jazzyisj

This comment has been minimized.

Copy link
Owner Author

@jazzyisj jazzyisj commented Aug 29, 2020

Restart would definitely be a better choice for automation mode, I've changed it.

I didn't really intend on this being a complete automation, it was just meant to be a starting point and a way to verify the sensor was working correctly. A cool down delay thrown in there somewhere certainly wouldn't be out of place.

In your case off the top of my head I'd probably create two groups, one for when your server is on and the other when it's off. If you don't already have a binary sensor to test for your server on, create on (ping is probably easiest). Then modify the sensor to switch which group it's using for ignored sensors depending on the state of your server connection binary sensor. There's probably a slicker way to do it but that will work.

  value_template: >
       {% if is_state('binary_sensor.server_on','on') %}
           {{ states|selectattr('state','in',['unavailable','unknown','none'])
             |rejectattr('entity_id','in',state_attr('group.ignored_entities', 'entity_id'))
             |rejectattr('domain','eq','group')|list|length }}
       {% else %}
           {{ states|selectattr('state','in',['unavailable','unknown','none'])
             |rejectattr('entity_id','in',state_attr('group.no_server_ignored_entities', 'entity_id'))
             |rejectattr('domain','eq','group')|list|length }}
        {% endif %}
@DrBlokmeister

This comment has been minimized.

Copy link

@DrBlokmeister DrBlokmeister commented Sep 10, 2020

Okay, I think I have found a really nice implementation of this. First I programmatically define a group with the entities I want to ignore depending on if the main switch in the group is available. This consists of three steps in my case, the first two steps I manually define the entities to ignore, and in the third step I programmatically do so:

  - alias: "Update additional unavailable entities group"
    description: "Add child entities to ignored entities group if parent becomes unavailable."
    mode: restart
    trigger:
      - platform: time_pattern
        minutes: 1
    action:
      # delay to allow sensors to come online, prevent false notifications
      - wait_template: "{{ states('sensor.uptime')|int > 5 }}"
        timeout: '00:05:00'
      - service: group.set
        data_template:
          object_id: additional_ignored_entities
          entities: >-
            {%- set entities = namespace() -%}
            {%- set entities.entities = '' -%}
            {%- if is_state('switch.transmission_switch', 'unavailable') or is_state('device_tracker.transmission','not_home') -%}
              {%- if entities.entities != '' %}{% set entities.entities = entities.entities + ',' %}{%- endif %}
              {%- set entities.entities = 'sensor.ping_transmission_avg,sensor.transmission_active_torrents,sensor.transmission_completed_torrents,sensor.transmission_down_speed,sensor.transmission_paused_torrents,sensor.transmission_started_torrents,sensor.transmission_up_speed,sensor.transmission_total_torrents,switch.transmission_switch,switch.transmission_turtle_mode' -%}
            {%- endif -%}
            {%- if is_state('binary_sensor.blokmeisternas','off') -%}
              {%- if entities.entities != '' %}{% set entities.entities = entities.entities + ',' %}{%- endif %}
              {%- set entities.entities = entities.entities + 'sensor.ping_blokmeisternas_avg,sensor.fn_newstorage_used,sensor.fn_storage2_used' -%}
            {%- endif -%}
            {%- for group in states.group if ("blitzwolf" in group.name) and states(expand(group) | selectattr('domain', 'eq', 'switch') | map(attribute='entity_id') | list | join(','))=='unavailable' -%}
              {%- if entities.entities != '' %}{% set entities.entities = entities.entities + ',' %}{%- endif %}
              {%- set entities.entities = entities.entities + (expand(group) | rejectattr('domain', 'eq', 'switch') | map(attribute='entity_id') | list | join(',')) %}
            {%- endfor %}
            {{- entities.entities }}

Then I exclude the entities in that group as well in your main automation:

sensor:
  - platform: template
    sensors:
      unavailable_entities:
        entity_id: sensor.time # updates sensor every minute
        friendly_name: Unavailable Entities
        unit_of_measurement: entities
        icon_template: "{{ 'mdi:check-circle' if states('sensor.unavailable_entities')|int == 0 else 'mdi:alert-circle' }}"
        value_template: >
          {{ states|selectattr('state','in',['unavailable','unknown','none'])
            |rejectattr('entity_id','in',state_attr('group.base_ignored_entities', 'entity_id'))
            |rejectattr('entity_id','in',state_attr('group.additional_ignored_entities', 'entity_id'))
            |rejectattr('domain','eq','group')|list|length }}
        attribute_templates:
          entities: >
            {{ states|selectattr('state','in',['unavailable','unknown','none'])
              |rejectattr('entity_id', 'in', state_attr('group.base_ignored_entities', 'entity_id'))
              |rejectattr('entity_id', 'in', state_attr('group.additional_ignored_entities', 'entity_id'))
              |rejectattr('domain','eq','group')|map(attribute='entity_id')|list|join(', ') }}
          names: >
            {{ states|selectattr('state','in',['unavailable','unknown','none'])
              |rejectattr('entity_id', 'in', state_attr('group.base_ignored_entities', 'entity_id'))
              |rejectattr('entity_id', 'in', state_attr('group.additional_ignored_entities', 'entity_id'))
              |rejectattr('domain','eq','group')|map(attribute='name')|list|join(', ') }}

There of course is the limitation that it only works for groups that don't have more than one switch.

@pmd5700

This comment has been minimized.

Copy link

@pmd5700 pmd5700 commented Sep 18, 2020

This is great! I was looking for something exactly like this. I have it configured to notify me on my mobile device. I have a question though. My Hue lights randomly go unavailable for a second or 2 (I should probably figure that problem out, too). What would the best way be to add some sort of delay - essentially only show devices that are unavailable for more than 5 seconds or so. Would I add a for: to my trigger? Or something else?

@DrBlokmeister

This comment has been minimized.

Copy link

@DrBlokmeister DrBlokmeister commented Sep 19, 2020

Maybe you could do something where you reject the items in the loop where "state_attr(huelamp, 'last_changed') - now() > 2"? Please share your code here if you have found a solution, it would be interesting to see! :)

@pmd5700

This comment has been minimized.

Copy link

@pmd5700 pmd5700 commented Sep 19, 2020

So, I've got a simple delay in before choose. That seems to be mostly working. Seems a little buggy still so I'll keep tinkering with it. Thanks!

@jazzyisj

This comment has been minimized.

Copy link
Owner Author

@jazzyisj jazzyisj commented Sep 19, 2020

@pmd5700 Personally I would just create a template binary sensor with a delay on it to trigger your alert automation or alert.

binary_sensor:
  - platform: template
    sensors
      unavailable_entities_alert:
        delay_on:
          minutes: 5 # delay before activating alert
        value_template: "{{ states('sensor.unavailable_entities')|int > 0 }}"

https://www.home-assistant.io/integrations/binary_sensor.template/

@pmd5700

This comment has been minimized.

Copy link

@pmd5700 pmd5700 commented Sep 19, 2020

@jazzyisj Thanks! I'm pretty new to all of this. Do I have this right? Would that binary sensor "see" the unavailable entities sensor go something >0, then it would wait 5 minutes, then I would use unavailable_entities_alert to trigger the automation? And then the automation would send a notification if unavailable entities was > 0?

@jazzyisj

This comment has been minimized.

Copy link
Owner Author

@jazzyisj jazzyisj commented Sep 19, 2020

Yep. The automation is actually triggering when the binary sensor turn on, which happens 5 minutes after the unavailable entities sensor state goes and stays above 0. If the state goes back to zero within 5 minutes the binary sensor never turns on and the automation won't trigger.

trigger:
  - platform: state
    entity_id: binary_sensor.unavailable_entities_alert
    state: 'on'

This situation is an ideal candidate for the alert integration btw.

https://www.home-assistant.io/integrations/alert/

@jazzyisj

This comment has been minimized.

Copy link
Owner Author

@jazzyisj jazzyisj commented Sep 19, 2020

@DrBlokmeister I didn't realize that group had a set service! It isn't mentioned in the group docs. That has got me thinking about something else in my config now. Thanks for sharing that!

@pmd5700

This comment has been minimized.

Copy link

@pmd5700 pmd5700 commented Sep 20, 2020

Yep. The automation is actually triggering when the binary sensor turn on, which happens 5 minutes after the unavailable entities sensor state goes and stays above 0. If the state goes back to zero within 5 minutes the binary sensor never turns on and the automation won't trigger.

trigger:
  - platform: state
    entity_id: binary_sensor.unavailable_entities_alert
    state: 'on'

This situation is an ideal candidate for the alert integration btw.

https://www.home-assistant.io/integrations/alert/

Thanks! So using the template binary sensor is better than the delay in the automation since it doesn't always make the automation run every time - only when a sensor stays unavailable for more than 5 minutes, correct? My delay seems to be working, but I like you're way better 👍

Also, I really like the Alert integration. I've never seen that before, but I actually have a lot of uses for something like that. Thanks!

@jazzyisj

This comment has been minimized.

Copy link
Owner Author

@jazzyisj jazzyisj commented Sep 21, 2020

only when a sensor stays unavailable for more than 5 minutes, correct?

Yessir.

Once I've got my config finished for v0.115 I'll update my git. I have probably close to 50 alerts set up in a couple of different ways. They are pretty flexible if you figure out how to use them effectively.

@pmd5700

This comment has been minimized.

Copy link

@pmd5700 pmd5700 commented Sep 21, 2020

I've got the binary sensor setup with a delay and it works great, thanks!

I've been messing around with Alerts, too. It seems like you have to put some time in for repeat. Have you found a "simple" way to avoid that? I'm sure there's a way with automations or something, but that kind of defeats the purpose in my situation. I really only wanted to get notified once for a few of my alerts.

@DrBlokmeister

This comment has been minimized.

Copy link

@DrBlokmeister DrBlokmeister commented Sep 22, 2020

Okay, we have a major problem with version 0.115 and the sensor template definition used in this gist. Since the template checks if a state is unavailable, unknown or none is ALL entities, the sensor updates whenever ANY entity changes state. This caused major slowdowns in my HA setup until I tracked down the issue and commented out this sensor. I think there is no way of limiting the update rate of this template sensor. So maybe we should create an issue on the HA github to bring it up?

What do you think?

@jazzyisj

This comment has been minimized.

Copy link
Owner Author

@jazzyisj jazzyisj commented Sep 26, 2020

Yes, there is a problem. Discussion was here..
Apparently on systems with lots of horsepower (in other words not an RPi) it seems to work fine, but it definitely kills my RPi 3.

My suggest would be to possibly add a throttle option to template sensors. Still playing around and discussing before I create an issue.

@DrBlokmeister

This comment has been minimized.

Copy link

@DrBlokmeister DrBlokmeister commented Oct 1, 2020

I'm running it on an i5 NUC, and it also stalls my system severly. CPU always at 100%, 90*C thermal throttling.

Paulus was looking for usecases to add entity_ids to template sensors on the Home Assistant podcast, but couldn't think of any. Maybe it's an idea to just send him a message on Discord?

@pmd5700

This comment has been minimized.

Copy link

@pmd5700 pmd5700 commented Oct 1, 2020

Weird - I'm running on an Intel Celeron NUC and haven't seen CPU go over ~40%. Usually it stays around 10% - 15%

@jazzyisj

This comment has been minimized.

Copy link
Owner Author

@jazzyisj jazzyisj commented Oct 2, 2020

A little disconcerting when you're trying to track down an issue with your system only to recognize your own code being the culprit!

It's actually all states| based templates causing the issues for myself and others. Looks like the devs are aware of the issue and may be working on a solution so sensors like this one will still be a viable solution again.

home-assistant/core#40292

@pmd5700

This comment has been minimized.

Copy link

@pmd5700 pmd5700 commented Oct 29, 2020

Curious if anyone has updated their template sensor? In 0.117.0, I'm getting the following error. Seems like it's an issue with the icon?

Source: components/template/template_entity.py:239
Integration: template (documentation, issues)
First occurred: 2:16:57 PM (1 occurrences)
Last logged: 2:16:57 PM

Template loop detected while processing event: <Event state_changed[L]: entity_id=sensor.unavailable_entities, old_state=<state sensor.unavailable_entities=58; entities=alarm_control_panel.ring_alarm..............................In-Wall Smart Dimmer, unit_of_measurement=Entities, friendly_name=Unavailable Entities, icon=mdi:alert-circle @ 2020-10-29T14:16:57.079248-04:00>>, skipping template render for Template[{{ 'mdi:check-circle' if states('sensor.unavailable_entities')|int == 0 else 'mdi:alert-circle' }}]
@DrBlokmeister

This comment has been minimized.

Copy link

@DrBlokmeister DrBlokmeister commented Oct 30, 2020

I haven't yet dared to try it again. Do you have an update @jazzyisj?

@jazzyisj

This comment has been minimized.

Copy link
Owner Author

@jazzyisj jazzyisj commented Oct 30, 2020

@DrBlokmeister @pmd5700

Sorry guys, with all the changes in the last couple releases it took me a while to get around to this.
I have updated the gist. I can confirm on an RPi3 that the updated gist is working without issue on v0.117.0

@jazzyisj

This comment has been minimized.

Copy link
Owner Author

@jazzyisj jazzyisj commented Oct 30, 2020

@pmd5700

I believe that is related to this, which was supposed to be fixed. It doesn't seem to affect the sensor at all though, I think it is still just throwing a warning in the log.

home-assistant/core#41013

@pmd5700

This comment has been minimized.

Copy link

@pmd5700 pmd5700 commented Oct 30, 2020

@jazzyisj

Your new update seems to be working, thank you! I did have to tweak my automation to get it to function properly. Here is what I have:

sensor:
  - platform: template
    sensors:
      unavailable_entities:
        friendly_name: Unavailable Entities
        unit_of_measurement: Entities
        icon_template: "{{ 'mdi:check-circle' if is_state('sensor.unavailable_entities','0') else 'mdi:alert-circle' }}"
        value_template: >
          {{ states|selectattr('state','in',['unavailable','unknown','none'])|rejectattr('domain','eq','group')
            |rejectattr('entity_id','in',state_attr('group.ignored_entities','entity_id'))|list|count }}
        attribute_templates:
          entities: >
            {{ states|selectattr('state','in',['unavailable','unknown','none'])|rejectattr('domain','eq','group')
              |rejectattr('entity_id','in',state_attr('group.ignored_entities','entity_id'))|map(attribute='entity_id')|join(',') }}
          names: >
            {{ states|selectattr('state','in',['unavailable','unknown','none'])|rejectattr('domain','eq','group')
              |rejectattr('entity_id','in',state_attr('group.ignored_entities','entity_id'))|map(attribute='name')|join(',') }}

binary_sensor:
  - platform: template
    sensors:
      unavailable_entities_alert:
        delay_on:
          seconds: 30 # delay before activating alert
        value_template: "{{ states('sensor.unavailable_entities')|int > 0 }}"

automation:
- id: ''
  alias: Unavailable Sensors
  description: ''
  trigger:
  - platform: state
    entity_id: binary_sensor.unavailable_entities_alert
  condition: []
  action:
  - choose:
    - conditions:
      - condition: and
        conditions:
        - condition: numeric_state
          entity_id: sensor.unavailable_entities
          above: '0'
        - condition: numeric_state
          entity_id: sensor.unavailable_entities
          below: '2'
      sequence:
      - service: notify.mobile_app_iphone
        data:
          title: There is {{ states('sensor.unavailable_entities')|int }} device offline!
          message: '{{ state_attr(''sensor.unavailable_entities'',''names'').split('','')
            | join(''

            '') }}'
    - conditions:
      - condition: numeric_state
        entity_id: sensor.unavailable_entities
        above: '1'
      sequence:
      - service: notify.mobile_app_iphone
        data:
          title: There are {{ states('sensor.unavailable_entities')|int }} devices
            offline!
          message: '{{ state_attr(''sensor.unavailable_entities'',''names'').split('','')
            | join(''

            '') }}'
    default:
    - service: notify.mobile_app_iphone
      data:
        title: Attention!
        message: All devices are back online.
  mode: restart
@jazzyisj

This comment has been minimized.

Copy link
Owner Author

@jazzyisj jazzyisj commented Oct 31, 2020

@pmd5700

I think this will accomplish the same thing for you.

    - choose:
      - conditions:
          - condition: numeric_state
            entity_id: sensor.unavailable_entities
            above: '0'
        sequence:
          - service: notify.mobile_app_iphone
            data:
              title: "There {{ 'is' if is_state('sensor.unavailable_entities','1') else 'are'}} {{ states('sensor.unavailable_entities')|int }} {{ 'device' if is_state('sensor.unavailable_entities','1') else 'devices'}} offline!"
              message: "{{ state_attr('sensor.unavailable_entities'',''names').split(',')|join('\n') }}"
      default:
        - service: notify.mobile_app_iphone
          data:
            title: Attention!
            message: All devices are back online.
@pmd5700

This comment has been minimized.

Copy link

@pmd5700 pmd5700 commented Oct 31, 2020

@jazzyisj Cool, thanks! I figured there was a better way - but that was working for the time being!

@Jurgenn22

This comment has been minimized.

Copy link

@Jurgenn22 Jurgenn22 commented Nov 1, 2020

@jazzyisj
Your new update is not working for me, I am getting this error in logs. What am I doing wrong?
With the previous Gist, and Home-Assistant 0.117.1, I get the Event loop warning.

Error:
2020-11-01 18:16:48 ERROR (MainThread) [homeassistant.components.template.template_entity] TemplateError('TypeError: argument of type 'NoneType' is not iterable') while processing template 'Template("{{ states|selectattr('state','in',['unavailable','unknown','none'])|rejectattr('domain','eq','group')

Template Sensor:
unavailable_entities:
friendly_name: Unavailable Entities
unit_of_measurement: entities
icon_template: "{{ 'mdi:check-circle' if is_state('sensor.unavailable_entities','0') else 'mdi:alert-circle' }}"
value_template: >
{{ states|selectattr('state','in',['unavailable','unknown','none'])|rejectattr('domain','eq','group')
|rejectattr('entity_id','in',state_attr('group.ignored_entities','entity_id'))|list|count }}
attribute_templates:
entities: >
{{ states|selectattr('state','in',['unavailable','unknown','none'])|rejectattr('domain','eq','group')
|rejectattr('entity_id','in',state_attr('group.ignored_entities','entity_id'))|map(attribute='entity_id')|join(',') }}

@jazzyisj

This comment has been minimized.

Copy link
Owner Author

@jazzyisj jazzyisj commented Nov 2, 2020

@Jurgenn22

Do you have the ignored_entities group declared somewhere? See the comments in the gist.

@Jurgenn22

This comment has been minimized.

Copy link

@Jurgenn22 Jurgenn22 commented Nov 2, 2020

@jazzyisj
Thx! Different sensor name.

@Jurgenn22

This comment has been minimized.

Copy link

@Jurgenn22 Jurgenn22 commented Nov 4, 2020

@jazzyisj
With the new update, I still get the message 'Template loop detected while processing event' in the logs.

@Jurgenn22

This comment has been minimized.

Copy link

@Jurgenn22 Jurgenn22 commented Nov 4, 2020

@jazzyisj
I think I have a solution, in the ignored_entities, group, I added the Unavailable Entities sensor. Since then no more Event Loop messages in the logs.

Unfortunately not working, after a while again Event Loop notifications in logs.

@jazzyisj

This comment has been minimized.

Copy link
Owner Author

@jazzyisj jazzyisj commented Nov 5, 2020

@Jurgenn22 i haven't figured out what triggers the warning yet. And it is just a warning, not an error. The sensor appears to always work as expected and no other detrimental effects have been noticed. (Please report if you notice anything though!)

I think they just haven't worked all the bugs out of the new template engine. Self referencing entities are permitted now if they only refer to themselves? I think? I'm ignoring it for now, I will look into it further if it persists after the next couple updates.

@Jurgenn22

This comment has been minimized.

Copy link

@Jurgenn22 Jurgenn22 commented Nov 8, 2020

@jazzyisj
Thank you for your answer, I'll wait and see.
regards

@nickh66

This comment has been minimized.

Copy link

@nickh66 nickh66 commented Nov 13, 2020

This is great @jazzyisj thanks. It works great.
I was wondering if you had any thoughts on how to perhaps present this list of resulting entities in the UI on card?
Cheers.

@jazzyisj

This comment has been minimized.

Copy link
Owner Author

@jazzyisj jazzyisj commented Nov 13, 2020

@nickh66

Quick and dirty? Just use a markdown card

- type: markdown
  content: |
    {%- if states.sensor.unavailable_entities.attributes.entities is defined -%}
      {%- if states('sensor.unavailable_entities')|int == 0 -%}
        No unavailable entities.
      {%- else -%}
        {%- for device in state_attr('sensor.unavailable_entities','entities').split(',') -%}
        - {{ device ~ '\n' }}
        {%- endfor %}
      {%- endif -%}
    {%- endif -%}  

If you have installed the fold entity row and hui element plugins you can do it like this and use it in an entities card with other entities.

- type: entities
  title: System Monitor
  show_header_toggle: false
  entities:
    - type: custom:fold-entity-row
      head: sensor.unavailable_entities
      padding: 5
      entities:
        - type: custom:hui-element
          card_type: markdown
          content: |
            {%- if states.sensor.unavailable_entities.attributes.entities is defined -%}
              {%- if states('sensor.unavailable_entities')|int == 0 -%}
                No unavailable entities.
              {%- else -%}
                {%- for device in state_attr('sensor.unavailable_entities','entities').split(',') -%}
                - {{ device ~ '\n' }}
                {%- endfor %}
              {%- endif -%}
            {%- endif -%}

image
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.