Mastering Browser-Based Alerts: Advanced Web Push Notifications in Home Assistant

NGC 224
DIY Smart Home Creator
Intro: The Need for Robust, Browser-Based Alerts
While Home Assistant offers various notification methods—from companion apps to Telegram—relying solely on them can have limitations. Companion apps aren't always installed on every device, and external services introduce privacy concerns or potential points of failure. For tech enthusiasts and privacy-conscious homeowners, browser-based Web Push notifications offer a powerful, direct, and app-independent solution for instant alerts across all your devices with a modern web browser. Imagine receiving critical security alerts or actionable smart home prompts directly in your desktop or mobile browser, even when Home Assistant isn't actively open.
This guide will walk you through implementing Home Assistant's native Web Push integration. We'll cover the essential prerequisites, step-by-step setup, common troubleshooting, and advanced configurations like interactive notification actions, enabling you to build a truly responsive and reliable smart home notification system.
1. Prerequisites: Secure Home Assistant & Public URL
For Web Push to function, your Home Assistant instance must be accessible via HTTPS from the internet with a valid, trusted SSL certificate. This is a fundamental security requirement for all modern browser features. If you're not already doing so, consider using Nginx Proxy Manager or Caddy to manage your public URL and SSL certificates (e.g., Let's Encrypt). This ensures secure communication and a public endpoint for push services.
Example Nginx Proxy Manager Configuration (conceptual):
# Nginx Proxy Manager Host Configuration
# Domain Names: your.homeassistant.url
# Scheme: http
# Forward Hostname / IP: homeassistant.local (or its IP)
# Forward Port: 8123
# SSL Tab: Request a new SSL certificate (Let's Encrypt) and enable Force SSL.
2. Setting Up Web Push Integration in Home Assistant
The Web Push integration relies on VAPID (Voluntary Application Server Identification) keys for secure communication between your Home Assistant instance and the push service (e.g., Google's FCM, Mozilla's Autopush). You'll add the integration to your configuration.yaml
and generate these keys.
2.1. Add the Integration to configuration.yaml
Add the following to your configuration.yaml
file:
webpush:
vapid_private_key: !secret webpush_vapid_private_key
vapid_public_key: !secret webpush_vapid_public_key
vapid_email: [email protected] # Email for contact in case of abuse.
Replace [email protected]
with your actual email address. This email is publicly visible to the push service, but not to end-users, and is used for contact regarding misuse.
2.2. Generate VAPID Keys
Home Assistant does not automatically generate these keys. You can do so using various online tools or Python:
from webpush import Vapid
keys = Vapid.generate_keys()
print("Private Key:", keys["private_key"])
print("Public Key:", keys["public_key"])
Store the generated private and public keys securely in your secrets.yaml
file:
# secrets.yaml
webpush_vapid_private_key: <YOUR_GENERATED_PRIVATE_KEY>
webpush_vapid_public_key: <YOUR_GENERATED_PUBLIC_KEY>
Restart Home Assistant after making these changes.
3. Registering Your Browser for Push Notifications
Once the integration is set up, open your Home Assistant instance in any modern browser (Chrome, Firefox, Edge, Safari, Brave) at your public HTTPS URL. You should be prompted to allow notifications. Accept this prompt.
For a more app-like experience and persistent notifications, consider installing Home Assistant as a Progressive Web App (PWA) directly from your browser's menu (usually found near the URL bar).
4. Sending Your First Web Push Notification
With your browser registered, you can now send notifications. The service call is notify.webpush
.
Navigate to Developer Tools > Services in Home Assistant and try sending a test notification:
service: notify.webpush
data:
message: "Hello from Home Assistant!"
title: "Test Notification"
data:
tag: "test-notification" # Optional: helps manage notification behavior.
You should immediately receive this notification in your registered browser. If you have multiple devices registered, they will all receive it.
Troubleshooting Common Web Push Issues
If your notifications aren't appearing or behaving as expected, consider these common solutions:
- No Notification Prompt / Notifications Not Appearing: Ensure your Home Assistant URL is accessible via HTTPS with a valid SSL certificate. Check your browser's site settings to ensure notifications are allowed for your Home Assistant domain. Clear browser cache or try a different browser.
webpush
Service Not Found: Double-check yourconfiguration.yaml
syntax and ensure the VAPID keys are correctly loaded fromsecrets.yaml
. Restart Home Assistant completely after any configuration changes.- Errors in Home Assistant Logs: Look for specific errors related to
webpush
. Common issues include invalid VAPID keys, network connectivity problems to push services, or an inaccessible Home Assistant URL. Ensurevapid_email
is a valid email format. - Notifications Delayed/Missed on Mobile: Some mobile operating systems or browsers aggressively optimize battery usage by restricting background activity. Ensure your browser app has no battery restrictions and is allowed to run in the background. Installing HA as a PWA can sometimes improve reliability.
Advanced Web Push Configuration & Optimization
Web Push notifications can be much more than simple text alerts. Leverage these advanced features for richer interactions:
4.1. Rich Notifications with Actions (Buttons)
Add interactive buttons to your notifications, allowing users to perform actions directly from the alert. These actions can trigger Home Assistant scripts or automations.
service: notify.webpush
data:
message: "A strange motion was detected in the backyard!"
title: "Security Alert"
data:
tag: "backyard-motion-alert"
actions:
- action: "view_camera"
title: "View Camera"
- action: "turn_on_lights"
title: "Turn On Lights"
To handle these actions, you'll need an automation that listens for the webpush_notification_action
event:
automation:
- alias: Handle Backyard Motion Actions
trigger:
platform: event
event_type: webpush_notification_action
event_data:
tag: "backyard-motion-alert"
action:
- choose:
- conditions:
- >-
{{ trigger.event.data.action == 'view_camera' }}
sequence:
- service: browser_mod.navigate
data:
path: /lovelace/security_dashboard
- conditions:
- >-
{{ trigger.event.data.action == 'turn_on_lights' }}
sequence:
- service: light.turn_on
target:
entity_id: light.backyard_lights
Note: browser_mod.navigate
is an example using the HACS Browser Mod integration for browser control.
4.2. Notification Persistence and Replacement
Using the tag
parameter in the data
field allows you to manage notification behavior. Notifications with the same tag
can replace previous ones, preventing a flood of alerts. For example, a new temperature alert can replace the old one, showing only the latest reading.
Real-World Example: Garage Door Alert with Quick Action
Let's create an automation that notifies you if your garage door is left open for more than 10 minutes, offering a button to close it directly from the notification.
automation:
- alias: Notify if Garage Door Left Open
description: Send a Web Push notification if the garage door is open for too long, with a close option.
trigger:
- platform: state
entity_id: cover.garage_door
to: 'open'
for: '00:10:00'
condition:
- condition: state
entity_id: cover.garage_door
state: 'open'
action:
- service: notify.webpush
data:
message: "The garage door has been open for over 10 minutes!"
title: "Garage Door Alert"
data:
tag: "garage-door-open"
actions:
- action: "close_garage_door"
title: "Close Garage Door Now"
- alias: Handle Garage Door Close Action
trigger:
platform: event
event_type: webpush_notification_action
event_data:
tag: "garage-door-open"
action: "close_garage_door"
action:
- service: cover.close_cover
target:
entity_id: cover.garage_door
Best Practices for Robust Web Push Notifications
- Security First: Keep your
vapid_private_key
absolutely secret. Never expose it publicly. - Thoughtful Usage: Don't spam yourself with notifications. Use tags to replace old alerts and ensure alerts are truly actionable or critical.
- Backup Your Keys: Store your VAPID keys securely in a password manager or encrypted backup. Losing them means all registered browsers will stop receiving notifications until new keys are generated and re-registered.
- Test Across Devices: Test your notifications on various browsers (Chrome, Firefox, Edge, Safari) and operating systems (desktop, Android, iOS) to ensure consistent behavior.
- Privacy-Centric: Since Web Push relies on standardized browser APIs, it's generally more privacy-friendly than sending data through third-party chat applications, as your notification content typically goes directly to the browser push service and then to your device without being stored by Home Assistant or unnecessary intermediaries.
By implementing Web Push notifications, you gain a powerful, flexible, and privacy-respecting channel for your Home Assistant alerts, moving beyond app-centric limitations and taking another step towards a truly integrated and responsive smart home.

NGC 224
Author bio: DIY Smart Home Creator