Get PagerDuty notifications to flash your bedside lamp
This article explains how I used AWS SES, AWS SNS, ngrok, nginx, Home Assistant and a TP-Link Kasa Smart TP-Link (KP400) to flash a beside lamp when I get paged on PagerDuty, before it falls back to a sound notification on my phone.
Note: there are probably simpler methods. I didn’t have access to the PagerDuty API and had to rely on emails for notifications.
Overview
Here’s the high-level configuration:
- Configure Home Assistant to flash a lamp when it receives a webhook (for example on:
/api/webhook/something
). - Add an nginx container alongside Home Assistant to only expose this webhook endpoint. I didn’t want to expose my entire Home Assistant setup on the Internet.
- Use ngrok to expose the nginx container’s port publicly on the Internet. You could very well forward a port from your home router/NAT device and rely on your current public IP instead.
- Configure AWS SES to receive email (for example on:
x@y.xyz
) and forward them to an SNS topic. - Add a webhook subscriber
https://$HOSTNAME/api/webhook/something
to the SNS topic. - Configure PagerDuty to send email notifications to that email address (for example:
x@y.xyz
).
Prerequisites
The instructions below assume that:
- You already have Home Assistant setup on a host
- You’ve paired a smart plug device with it
- You own a domain name
- You have basic knowledge of Docker, nginx, AWS SES, AWS SNS and PagerDuty configuration
Home Assistant Configuration
-
Configuration > Automations > Add Automation > Start with an empty automation
-
Click on the top right three dots and press “Edit as YAML”.
-
You can use this sample configuration. It might be suboptimal (didn’t get to loops), it’s the first one I create. Replace
something
by your webhook path. This should be enough to expose a webhook that will trigger a lamp to flash with 1 second delay between turn on and turn off.1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
alias: PagerDuty Notification description: '' trigger: - platform: webhook webhook_id: something condition: [] action: - type: turn_on device_id: 1234 entity_id: switch.kasa_smart_plug_4d21_0 domain: switch - delay: 1 - type: turn_off device_id: 1234 entity_id: switch.kasa_smart_plug_4d21_0 domain: switch - delay: 1 - type: turn_on device_id: 1234 entity_id: switch.kasa_smart_plug_4d21_0 domain: switch - delay: 1 - type: turn_off device_id: 1234 entity_id: switch.kasa_smart_plug_4d21_0 domain: switch - delay: 1 mode: single
At this point, you should be able to send a request to http://homeassistant:8123/api/webhook/something to trigger the lamp to flash.
Nginx container on the Home Assistant Raspberry Pi
I wrote this configuration file to /mnt/data/docker/nginx/nginx.conf
:
|
|
And then started a container with:
- image
nginx:latest
- configuration mounted on
/mnt/data/docker/nginx/nginx.conf:/etc/nginx/nginx.conf:ro
- expose port 80
At this point, you should be able to send a request to http://homeassistant:80/api/webhook/something to trigger the lamp to flash.
ngrok
I downloaded ngrok on /mnt/data
, prepared a sample configuration, and started it:
|
|
At this point, you should be able to send a request to https://YOUR_SUBDOMAIN.ngrok.io/api/webhook/something to trigger the lamp to flash.
AWS SES and SNS configuration
- Create a new SNS topic.
- Follow this documentation to setup SES to receive emails. At step 3, configure the action to publish to your SNS topic instead of S3.
- Subscribe your webhook URL
https://YOUR_SUBDOMAIN.ngrok.io/api/webhook/something
to the SNS topic.
At this point, you should be able to send an email to x@y.xyz
to trigger the lamp to flash.
PagerDuty
Add the extra email address (example taken from above: x@y.xyz
) in your PagerDuty user profile. Configure notifications to trigger on this email address first if you want the lamp to flash before anything else like I did.