Motivated by a recent heat pump failure, I started looking for entity monitoring solutions and was baffled to find that Home Assistant has no such capabilities. Nor do many third-party solutions seem to exist. This is all the more astonishing because the desire to be informed when things break should be a strong one among smart-home owners.
Confronted with this lack of functionality, I decided to build my own. Unlike my cover automation, I didn't want to create an integration. Instead, I felt that a basic capability like monitoring should rely only on what the platform natively offers, without external dependencies, so I focused on long-term stability as well as flexibility, low maintenance, and easy extensibility. Combining these seemingly contradictory requirements proved to be an interesting journey during which I learned many cool new tricks. The result exceeded my expectations. I'm sharing it in the hope that others may benefit from it:
Features
- Uses only native Home Assistant functionality plus a Python code generation script (required only when making changes)
- Clear separation of (private) configuration and (public) code
- Monitoring modes:
- Entity availability
- Entity error states
- Monitors almost any type of entity through user-created template sensors that define what counts as error or unavailable and specify user-friendly names for the UI
- Notifications via:
- Home Assistant persistent notifications that show up in the UI until dismissed
- Mobile and 3rd-party notifications via HA notification groups
- Multi-language support for end-user-facing messages
This is what a UI notification looks like:
Architecture Notes
Code Generation Script
The above features cannot be implemented generically with what's available in the Home Assistant platform, so I settled for the next-best thing: code generation. The actual Home Assistant automation configuration with its triggers and actions is created by a Python script from two sources: your list of monitored entities combined with the project's monitoring code.
Entity Abstraction Layer
(Nearly) any kind of entity can be monitored. This is made possible by adding an entity abstraction layer, where the user specifies what is to be monitored and how entity states should be interpreted. Since we already have this abstraction, we're using it to define user-friendly names for the notifications that are sent to mobile devices and show up in the Home Assistant UI, too.
Automations
The actual monitoring logic is deceptively simple: Home Assistant automations watch the user-defined monitoring entities that represent and abstract the actual entities whose status you want to know about. When one of these monitoring entities changes to an error state, the automation triggers notifications. When the state changes back to an OK state, the notifications are dismissed.
Scripts
Notifications are sent through Home Assistant scripts that perform two actions: create a persistent notification that shows up in the Notifications area of the Home Assistant UI, as well as send notifications via the built-in notifications integration. The latter natively supports mobile notifications via the Home Assistant companion app, but also many other targets via third-party integrations.
Notifications and Alerts
I didn't use Home Assistant alerts because they're built around the concept of repeatedly sending the same notification, which I find not to be helpful at all. These repeated notifications stack up in the Home Assistant UI and on your phone, reducing visibility and creating alert fatigue.
Happy monitoring!
