Get notified when your home is disconnected from the Internet

Tony Stark
4 min readJun 13, 2019
It’s all about the Heart Beat.

The easiest way to detect your internet or power loss at home to use Pingdom or similar services. However it requires publicly exposed devices or services (or vpn tunneling). I won’t expose my devices publicly, so I made a trick.

Requirements for this hacking:

  • RPI connected to AC power and internet (or similar device at your home)
  • Server (outside from your home) to accept the heart beat requests
  • Mobile phone to accept notifications

Overview

The client send heart beat requests to the server. LogDNA monitors the beats. If the client fails (due lack of Internet connection or AC power failure) the heart beat stops. LogDNA triggers an alert, call IFTTT on a webhook then IFTTT send push notification to your phone. Profit.

+----------+              +----------+          +----------+
| | Heart Beat | | logs | |
| Client +------------->+ Server +--------->+ LogDNA |
| | | | | |
+----------+ +----------+ +----+-----+
|
| On Alert
| Webhook
v
+---------+ Push +----+-----+
| | Notification | |
| Phone +<-----------------+ IFTTT |
| | | |
+---------+ +----------+

First, setting up the server.

Checkout the git repository.

git clone git@github.com:kisPocok/home-api.git
cd home-api

then create a Heroku app.

heroku apps:create --region eu

New app creations also adds Heroku as a git remote repository.

$ git remote -v
heroku https://git.heroku.com/your-awesome-app.git (fetch)
heroku https://git.heroku.com/your-awesome-app.git (push)

Next step is to deploy the code to Heroku server.

git push heroku master

Wait for the deployment. Easy peasy.

In order to get notified, you have to set-up a push notification service. Luckily, IFTTT offers it freely, so you don’t have to buy Apple Dev Cert. Also, having IFTTT application on your phone is mandatory. Also, allow notifications for this application.

Create a new Applet on IFTTT site / app. Search for Webhook and use “Receive a web request” trigger and set Event Name.

Add Event Name

You are half way. Find and select “Notification” as action service. Select “Send a rich notification from the IFTTT app” then fill the inputs. The finished Applet looks like this:

You can customize the message

Now, you have to find your private Webhook url. Go to the Webhook page, select “Documentation” link. Create a trigger by adding missing_heart_beat event name. So, your final url looks like this:

https://maker.ifttt.com/trigger/missing_heart_beat/with/key/YOUR_KEY

The service is ready to use. If you click on your link there will be a notification on your phone. Keep this URL safe.

LogDNA is real time log aggregator. It collects and monitors “heart beat” logs, so you can make alert based on the statistics.

Enable LogDNA on Heroku marketplace, free tier is enough. Create a new alert, use Webhook notification. Add the previously created URL.

You can set up email and slack alerts too.

In the Views page, set application to “app[web]”, set log level to “info” and search for “heartbeat”. Save the view, then attach the previously created alert.

LogDNA saved view

Server part is done. Let’s move to the Client.

I assume you have an RPI (or similar device) connected to the network. This client will report periodically to the server. This is the heart beat signal. All you need is to send a request to the server. The script is easy, don’t forget to update the host.

touch heartbeat.sh
chmod +x heartbeat.sh
echo "#\!/usr/bin/env bash" >> heartbeat.sh
echo "curl -XPOST -v https://your-awesome-app.herokuapp.com/home/v1/heartbeat" >> heartbeat.sh

Put it into crontab and execute it every minutes.

crontab -e then add * * * * * /path/to/heartbeat.sh

That’s it. Try to disable your network for 15 minutes, magic will happen. Enjoy!

--

--