Device Availability Checker - Run Action(s) (notifications) if device(s) are low battery or unavailable

This is my first blueprint, highly inspired by existing blueprints[1][2][3] already published here on the Blueprints Exchange.

My primary goal was more control with the output, making the UI elements more to my liking, and of course to wet my toes in the blueprints pool.

A few things I think that I have achieved with this blueprint, that the other blueprints I found did not, are:

  • Better, less cluttered “Day(s)” selector.
  • Exclusion logic that will work with not only entities, but also devices and areas.
  • Combining “Low Battery” and “Unavailable” check into one blueprint (not sure this is better, though).

Import Device Availability Checker blueprint to your Home Assistant.

The blueprint will return an array of dictionaries, which can be referenced using {{items}}. This way you can gain greater control over how the output should be handled.

An example of the returned data:

[
  {
    "device_id": "bb0074342dc93760d18ae40bb454f9ec",
    "device_name": "LUMI lumi.sensor_magnet",
    "area_id": "entrance",
    "state": "unavailable"
  },
  {
    "device_id": "0a300fdf5cdcc8e7d2e2473d003f9585",
    "device_name": "LUMI lumi.weather",
    "area_id": "bedroom",
    "state": "unavailable"
  },
  {
    "device_id": "6586d15e7134da404836203e165b7b9c",
    "device_name": "LUMI lumi.weather",
    "area_id": "living_room",
    "state": "unavailable"
  },
  {
    "device_id": "5e20568a620d5b500811c86568c5cee8",
    "device_name": "RGB Bulb",
    "area_id": "closet",
    "state": "unavailable"
  },
  {
    "device_id": "2563429dfb3eb402007748d833f2dfd4",
    "device_name": "LUMI lumi.weather",
    "area_id": "kitchen",
    "state": "56"
  }
]

An action example which sends an HTML-formatted e-mail:

service: notify.smtp_gmail
data:
  title: Unavailable or low battery devices
  message: |
    The following devices are low on battery or unavailable:
  data:
    html: |
      <!DOCTYPE html> <html>
        <head>
          <meta charset="UTF-8">
          <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
          <meta name="viewport" content="width=device-width, initial-scale=1.0">
          <title>Unavailable or low battery devices</title>
        </head>
        <body>
          <p>The following devices are low on battery or unavailable:</p>
          <ul>
          {% for item in items %}
            <li><a href="http://homeassistant.local:8123/config/devices/device/{{item.device_id}}">{{item.device_name}}</a><br />
              <ul>
                <li>Area: <a href="http://homeassistant.local:8123/config/areas/area/{{item.area_id}}">{{area_name(item.area_id)}}</a></li>
                <li>State: {{item.state}}</li>
              </ul>
            </li>
          {% endfor %}
          </ul>
        </body>
      </html>

Please find the blueprint on Github. That way I do not have to keep the code updated two places (here and Github).

The fine print:
I am not a programmer and I have little to no experience with YAML or Jinja2, so I have probably made several basic mistakes. If you find any mistakes, feel free to point them out, preferably with explanations and corrections for me to learn from :slight_smile:

I have published the code on Github, where you are welcome to clone/copy/whatever-it-is-called (I am no Github guru either), make pull requests (hopefully I will figure out how that works then) etc.

5 Likes

2 Likes

Thank you for your sharing. That would be good solution. I will try and give you feedback soon.

The idea to create this code is perfect if you have water leak sensors (battery) and water valve (power socket). To be safe from house flooding I need to be sure both sensor and valve are working. Let me know if this code can be used for the situation above.
Thank you.

That is essentially the purpose of the blueprint :slight_smile:

1 Like

If I press the “Import blueprint” button I don’t get the latest version? Should I get it from the Github repository? It is unfortunate that this is the case now that HA has the ability to update blueprints.

What steps should I follow to install the code in the Github repository?