Unavailable / Unknown Entity Monitoring - Template Sensor

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?

Nah you still have all those escapes and newlines in there (and you didn’t format the code).

Is this how you pasted?

image

Yeah the “\” and “\n” characters. Where are you copying the automation code from?


I follow you now. I recopied it from github. I have no clue how that happened. Let me retest and see if the push notify still doesn’t work.

I apologize, I’m a literal wombat sometimes.

Yeah, I think you have some issues there with wayward escape characters. Did you copy the RAW code from github?

image

Ok, see if it is reposted properly above. Yaml is going to be the death of me.

Much better. In your original post you had notify.mobile_app_weston as the service call. In the automation you posted you have notify.notify as the service call.
Updated the choose to if. (If is a new thing and is prefereable here. Need to update the git!)

Also I shortened the entity id list template. If you want to use the name like you asked about before you have to go back to the old way and expand the list.

Try this. Copy and paste the whole thing.

automation:
  - 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: ~
    condition:
      - condition: template
        value_template: |
          {{ is_number(trigger.from_state.state)
              and is_number(trigger.to_state.state) }}
        action:
          - if:
              - condition: numeric_state
                entity_id: sensor.unavailable_entities
                below: 1
            then:
              - service: persistent_notification.dismiss
                data:
                  notification_id: unavailable_entities
            else:
              - service: persistent_notification.create
                data:
                  title: Unavailable Entities
                  message: "- {{ state_attr('sensor.unavailable_entities','entity_id')|join('\n- ') }}"
                  notification_id: unavailable_entities

              - service: notify.notify
                data:
                  title: Unavailable Devices
                  message: "- {{ state_attr('sensor.unavailable_entities','entity_id')|join('\n- ') }}"

Just so you realize how that trigger works - this will only trigger once, when the sensor goes above 0 for the first time. It won’t trigger if more entities become unavailable unless the sensor goes back to 0 first.

If you want notifications every time any sensor goes on or offline, you’ll have to adjust the trigger.

Yeah, I would prefer the weston one like you ended up doing. Ahhh, I follow you. I would have never gotten that, just don’t understand alot of the programming yet. I’m in a technical career field but I’m a monkey with programming, 3 lines take me 3 hours. haha. Thank you and I’m testing it now. And I follow you on the id list template. I think.