Unavailable / Unknown Entity Monitoring - Template Sensor

Next to one positive user response unfortunately not much. Now also listed @ Improvement: expand or split project to an "Unavailable / Unknown *DEVICE* Monitoring - Template Sensor" · Issue #11 · jazzyisj/unavailable-entities-sensor · GitHub.

I replied with an example on my git. Sorry took me a while to get to it, life gets in the way :slight_smile:

@jazzyisj Hello Jason. Could you or someone here help me figure out how to get this working. Essentially, I copied everything from the github link at the top of this post and I don’t trust that it is working properly. The screenshot below shows what has populated on my “overview” dashboard. I don’t really know why that populated there. (I guess because it has to since that dashboard is automatic and shows every sensor that I have within home assistant)-- Is this supposed to happen? Also, after restarting my HA instance, I didn’t get a persistent notification, that either means everything is fine in my setup or it isn’t working properly. Can you give me some guidance?

One last thing I can add is from the github you posted, when I copy pasted to the yaml file within the packages directory I deleted “- binary_sensor.updater # always unknown after restart” which was under the area below because I had read somewhere else that that sensor is deprecated now.

So I guess the 2 questions I have is, why did the group populate on my overview dashboard, is this normal (screenshot below)-- I also tried to hide it on the entities page but it is read only-- I don’t know if this would’ve hidden from the automated overview dashboard but I was going to try it at least–, and secondly, is this thing working. I figured for sure something would show up as unavailable but maybe my setup is cleaner than I thought. (I am wanting to use this for leak sensors and door sensors essentially). Thank you @jazzyisj or any one that is willing to chime in and help me understand how this stuff functions!

group:
  ignored_unavailable_entities:
    entities:
      - sensor.unavailable_entities # prevent template loop warnings?
      - binary_sensor.updater # always unknown after restart


It shows up on your dashboard because as part of the package that new group is created. Groups are shown in the auto generated dashboard. What you see on your UI there is the ignored entities group, not the sensor.

Did you set it up as a package or manually in your config? Did you try setting it up a couple of times? I see in your devtools that the sensor was named sensor.unavailable_entities_2. Click on that entity and change the entity_id to sensor.unavailable_entities (drop the “_2”).

If it is set up correctly it should be working now but just for giggles restart. What happens?

Thank you for responding Jason and thank you for helping in general.

Ahh, I follow you on the group situation. I didn’t know that groups were essentially a mandatory situation on the overview dashboard. So there’s no way on the automated dashboard to have that not show?

I set it up as a package. I did have it set up previously and it would post a notification but was only showing a single “.” in it for some reason so I ended up deleting everything and tried it all again. That’s when I decided to post here because I wasn’t trusting myself/ it. haha. Thank you for catching the naming of the entity within my entities list. I am restarting now and will report back shortly. Thank you Jason!!

Ok, so I have the entity renamed and have done a restart. I do not have a notification. Will that be what happens if I have no unavailable entities?

I also went back to the file editor to look at a few things. I have a folder called “packages” that is within the config directory. And a file within that directory called “package_unavailable_entities.yaml”. Also, I verified there has been a automation created called “unavailable entities notification” which was disabled for some reason and I enabled it before restarting.

Ok, it just popped up!! It just took a few minutes. Maybe I wasn’t being patient enough! Definitely took 2-3 minutes I believe.

I suspected. That is why the sensor got named incorrectly.

Ok so in Developer Tools → States. Type sensor.unavailable_entities in the states filter. What do you see. Can you screenshot it? Like this.

Will this only run on a HA restart? A perfect use case for me would be a push notification if a door or leak sensor goes to unavailable.

It will trigger any time the state of sensor.unavailable_entities (which is the number of unavailable/unknown entities) changes. This is the automation trigger.

      - platform: state
        entity_id: sensor.unavailable_entities
        to: ~

The ~ indicates “any state”.

That automation is really just a simple generic example to demonstrate one way you could use the sensor. I don’t think very many people use it as is. In most configs there will often always be entities with an unknown value. I think it would be annoying as heck for that persistent notification to constantly keep popping up!

In my own system there will always be anywhere from 70 - 90 sensors with unknown values. So I have a heavily customized version of the sensor and added many entities to the ignored entities group so that I am only notified for entities that should never have an unknown or unavailable state.

Ahh I follow you now on the triggering. This is great. Thank you for providing this to others. I see how useful this is at this point. And I understand on what you are saying with regards to the generic automation, it is just a good way to see that it is working.

I agree and see what you are saying, I started off with pretty much the same amount of unavailable entities as you were saying your setup had, it looks like the majority of them are philips hue scenes. It did however catch a zwave outlet that must have dropped off of network so that is nice because I wouldn’t have known otherwise.

I follow what you are saying also on adjusting the ignored entities group to rid myself of these so that I only get the important ones.

Jason, thank you for helping me get this thing going. One last odd question would be, is there anyway to get the notification to report the “Friendly Name” if the entity has one or not really just because of how it all functions? Thank you again Jason!!

Try this in the automation.

Replace
|map(attribute='entity_id')

With
|map(attribute='name')

With your scenes, if they are like HA scenes activate each scene at least once and the state goes from unknown to the date last activated so they won’t show up with this sensor any longer. Assuming they work like HA scenes.

That’s awesome. It worked great. Ahhh, I would say that is what it is, I will give that a try and see if they start dropping off the list. Also, I was on GitHub looking at your configs. Is it ok if I send you some questions sometime by PM. I was seeing somethings I would like to do but I can tell you rely heavily on templating/ packaging and I’m not sure I completely understand those concepts just yet. It looks like to me, it is a method to reduce duplication but again, I’m really new with all of this, I moved from SmartThings over the last few weeks.

Sure thing! It is usually preferred if post your questions either here in the forum or if it’s specifically about something in my config in the discussion section on my git so other people can benefit from the answers too. You’ll also benefit from alternative or better solutions and ideas other may have.

Be aware that some people might get a little uptight about being tagged for help or PM’s (generally it’s against the forum etiquette rules) so usually I would avoid it, but in my case I really don’t mind. If I can help I will, if not I’ll let you know.

Don’t be offended if I don’t get back to you right away - every now and then I disappear for a while because of work and life obligations,

And congrats on the upgrade in your home automation system! :wink:

Ok. I’ll do the suggested whenever I get to that point. I am still kind of messing around with just the basics for now and trying to get everything to my version of a “baseline” and then I’ll start looking into some of the more detailed concepts that may require me to reach out for in a forum style approach as you suggested.

Ahh, I didn’t realize that, yeah I’ll be careful with that approach then. Yeah, I wouldn’t either which I guess is why that angle never really crossed my mind. But I’ll definitely take your advice on being careful about how I approach certain situations/ asking for help etc.

No, I won’t get offended, our physical lives have to come first of course and we’ll all throw in the shiny toys/ widgets in our spare time. Thank you again for being so helpful with getting this portion running properly.

Right, hopefully one day things will get even more gui driven that what they have gotten to for monkeys like myself, I feel like I’m in a constant fight with yaml and indenting/ spacing.

Thank you again Jason!! Very helpful!!

Hello all,

Could I have someone help me out on determining why an “action” wouldn’t be working properly using this package as the “base”. Essentially the persistent notification is working as is written in the package but I added the following in hopes that I would be able to get a push notification sent ot my ios device and it doesn’t seem to be working:

Thank you all for the guidance ahead of time. And I imagine with such a simple question, you all already know I am extremely new to HA and yaml. But trying to swim in the deep end as quickly as possible. Thank you all again for your help!!

service: notify.mobile_app_weston
data:
  title: Unavailable Device
  message: |
    - {{ expand(state_attr('sensor.unavailable_entities','entity_id'))
          |map(attribute='entity_id')|join('\n- ') }}

Can you copy and paste the full yaml for the automation here?

I can. I imagine this is going to be a case of me knowing nothing yet when it comes to yaml. Thank you also.

alias: Unavailable Entities Notification
description: >-
  Create persistent notification if there are unavailable entities, dismiss if
  none.
trigger:
  - platform: state
    entity_id: sensor.unavailable_entities
    to: null
condition:
  - condition: template
    value_template: |
      {{ is_number(trigger.from_state.state)
          and is_number(trigger.to_state.state) }}
    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: >
                - {{
                expand(state_attr('sensor.unavailable_entities','entities'))
                      |map(attribute='entity_id')|join('\n- ') }}
              notification_id: unavailable_entities
          - service: notify.notify
            data:
              title: Unavailable Devices
              message: >
                - {{
                expand(state_attr('sensor.unavailable_entities','entities'))
                      |map(attribute='entity_id')|join('\n- ') }}

Can you go back to your code editor, select all the automation code again, copy it, then go back to the last message here and edit it. Select all the automation code but right-click it and select “Paste as plain text”.

You’ve got a bunch of escapes and newlines in there for some reason. What code editor are you using?

Ok, is that what you mean? And what do you mean by escapes and new lines, non printing characters?Or are those backslashes not supposed to be in there?