Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Unavailable Sensor Detection and Notification
#######################################################################################################################
# The Unavailable Entities Sensor Package has been moved to it's own repository!
# https://github.com/jazzyisj/unavailable-entities-sensor
#######################################################################################################################
@pmd5700
Copy link

pmd5700 commented Dec 20, 2021

@jazzyisj Here is the full warning. I just want to make sure it doesn't break in 2022.1. Yes, I actually just updated to the most recent version. I don't recall if I was getting this warning prior to that.

Template warning: 'int' got invalid input 'unknown' when rendering template '{{ states('sensor.unavailable_entities')|int > 0 }}' but no default was specified. Currently 'int' will return '0', however this template will fail to render in Home Assistant core 2022.1

Template warning: 'int' got invalid input '' when rendering template '{{ states('sensor.unavailable_entities')|int > 0 }}' but no default was specified. Currently 'int' will return '0', however this template will fail to render in Home Assistant core 2022.1

@jazzyisj
Copy link
Author

jazzyisj commented Dec 20, 2021

@pmd5700 - The code you are referring to does not exist in the most current version. Where are you copying the code from?

@pmd5700
Copy link

pmd5700 commented Dec 20, 2021

@jazzyisj I'm using this to trigger my automation:

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

@jazzyisj
Copy link
Author

jazzyisj commented Dec 21, 2021

@pmd5700

That is not part of the package in this gist. That does look suspiciously like some template sensors I have in my personal config though..lol.
Anyway yes, you can just add a default value for int there. That should only happen on startup or when you're reloading templates.

value_template: "{{ states('sensor.unavailable_entities')|int(0) > 0 }}"

I use alerts for my notifications instead of an automation which is why I had to create the binary sensors in addition to the unavailable entities sensor. You could just use a numeric_state trigger if you're using an automation, you don't need the binary sensor template.

trigger:
 - platform: numeric_state
   entity_id: sensor.unavailable_entities
   above: 0

As for the template loop warnings - I'm not seeing them anymore again.
What is happening when you see that warning in your logs? Startup? Reloading templates?

@pmd5700
Copy link

pmd5700 commented Dec 21, 2021

@jazzyisj Thanks! I think I misread Bytelink5616's comment above. I was only getting the errors I posted above about the Int. I added the (0) and they seem to have gone away.

It should look familiar, I think you help me set it up ~a year ago lol. I tried the numeric state trigger, but I wanted to put a delay in the binary sensor so it didn't trigger all the time.

@jazzyisj
Copy link
Author

jazzyisj commented Dec 21, 2021

@pmd5700 Too funny..lol

This will give you your delay. Also if you're using the most current version you can increase the ignore_sec value to accomplish pretty much the same thing.

trigger:
 - platform: numeric_state
   entity_id: sensor.unavailable_entities
   above: 0
   for: 60

@jazzyisj
Copy link
Author

jazzyisj commented Dec 26, 2021

The Unavailable Entities Sensor has been moved to it's own package.

Please ask any further questions or report issues here.
https://github.com/jazzyisj/unavailable-entities-sensor

@jazzyisj
Copy link
Author

jazzyisj commented Dec 28, 2021

@massive

I have a similar issue as some others: I have a few devices that expose multiple sensors. I thought I could extend the sensor in a way that it would allow excluding sensors using regular expression. However, it seems that there is no elegant way to do that with HA and Jinja:

This feature is now available via the search test. The README in the new repository explains how to utilize it. I remembered your comment because it was the basis for my first failed attempt at accomplishing it with custom attributes so I thought I'd point it out to you.

@amitkeret

| rejectattr('entity_id','match',...)

YES! Home Assistant finally supports this! I finally got around to implementing it on this sensor (well, more like documenting it).

@Snuffy2

Is there anyway to modify it to only show if an entity has been unavailable for XX seconds/minutes?

I've updated the sensor and this is now accomplished with a much more elegant method. I recommend updating to the new method.

@Bytelink5616
Copy link

Bytelink5616 commented Jan 9, 2022

@jazzyisj
Copy link
Author

jazzyisj commented Jan 9, 2022

@Bytelink5616 My pleasure! I'm just paying forward all the help I've received along the way :-)

Can you visit the new repository for the sensor and check out the READ.ME? I've added quite a bit of documentation there.
If you still have a question then feel free to open an issue there so others can benefit.

https://github.com/jazzyisj/unavailable-entities-sensor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment