HomeHome AutomationSlow Internet Warning

Slow Internet Warning

Where is my Internet???

From time to time your ISP fails and the promised Internet speed drops below what’s acceptable. If the slow internet speed isn’t caused by local network traffic, chances are it’s your ISP that is not delivering on the contractual agreements due to technical reasons (or else). Inspired by Fingbox feature and a profile I made earlier to use Google Home to measure the Internet speed, I created the Slow Internet Warning system that works with your smart home.

Bad ISP? Get a warning and Tweet at them!

I know that tweeting at ISP has been done before, but I wanted to bring something special to the table. This project will not only monitor your Internet speed 24/7 but also notifies you and your smart home in more than one way!

Features

  • Alexa notifications
  • Google Home alerts
  • Android Notifications
  • Windows 10 Notifications
  • 24h Charts
  • Custom number of tests
  • Tweeter alerts

The Slow Internet Warning system will periodically check your Internet speed. I could finally take advantage of the 1Gbit Ethernet on my Raspberry Pi 4 to monitor my network (I get speeds in excess of 100Mbits).

I would strongly recommend getting a 1Gbit compatible board (Raspberry Pi 4) unless your ISP contractual speed is way below 100Mbits, otherwise, your results may not be accurate. Note that even with 10/100 Ethernet it’s possible to monitor low speeds.

If the Internet speed drops below a predefined value, the Slow Internet Warning system will start measuring it X times over a shorter period of time to make sure this was not a traffic spike. If the Internet speed is still low, warnings are sent to the devices of your choice with an option to automatically tweet at your ISP to start the conversation about the possible discounts this month!

NodeRED and Slow Internet Warning

There are a couple of nodes that you need to instal to make this work. I used the following nodes in my script:

 node-red-contrib-cast (for google home)
 node-red-contrib-join-joaoapps (for android)
 node-red-dashboard (for charts)
 node-red-contrib-alexa-notifyme
 node-red-contrib-speedtest 

To send the notifications for Windows 10 and Android I will use Join app. It works great for simple notifications. Anything more complicated would require Perfect Notifications 2.0.

Settings

I’m taking advantage of NodeRED 1.0 release and the custom subflow variables to set the settings for the project. You will need to provide the following info:

  • lowspeed set the low limit threshold
  • handle provide the Twitter handle of your ISP to annoy them
  • defaultspeed promised Internet speed by ISP
  • tests – number of confirmation tests

SpeedTest.net

Thanks to speedtest node, the entire process is very simple, trigger the speedtest node every X min, and monitor the result. It gets somehow complicated when it comes to calculating what constitutes the low Internet speed.

If the Internet speed fails to go over the set threshold, the Internet is then a subject to further evaluation. There is a smaller loop in place which will make consecutive tests.

If the average of these tests still falls below the threshold, the notifications are triggered. To break the loop, the threshold level tests have to be done X times (tests) or the value of the subsequent test has to go over the threshold indicating that the network issue was only temporary.

Function Node: Investigate
var count = context.get("count");
var total = flow.get("lowAverageSpeed");
var download = msg.payload.speeds.download;
var targetspeed = flow.get("lowSpeed");
var tests = flow.get("tests");
var defaultspeed = flow.get("defaultspeed");
var handle = flow.get("handle");


//check if array exists
if(!total || !total.length || total === undefined){
        total = [];
    }

var z = isNaN(count);

if(z === true){
    count = 0;
    context.set("count", count);
}

if(download <= targetspeed){

    if(z === false){
        if(count <= tests){
            count = count + 1;
            context.set("count", count);
            //push element
            total.unshift(download);
            //remove X elementh
            if(total[tests] === undefined) {
                
                flow.set("lowAverageSpeed", total);
            }
            else {
                total.splice(tests, 1);
                flow.set("lowAverageSpeed", total);
            }
        }
    //if speed is still below the target    
        if(count > tests){
            context.set("count", 0);
            //calculate average
            var sum = total;
            var average = Math.round(sum.reduce(add)/tests);
            total.splice(0,total.length);
            if(average <= targetspeed){
                msg.info = {
                    "isp": msg.payload.client.isp,
                    "average": average,
                    "lastDL": msg.payload.speeds.download,
                    "lastUL": msg.payload.speeds.upload
                }
                
                return[null, msg];
            }
        }
    }
    }
if(download > targetspeed){
    context.set("count", 0);
    total.splice(0,total.length);
    return [null, null];
}

function add(accumulator, a) {
            return accumulator + a;
        }

msg.payload = average;

return [msg, null];

A couple of words about Notifications

Alexa

I’m using Alexa NotifyMe skill, to create a pending notification on my Alexa devices. For the most part, everything stays the same, but I wanted to add a timestamp to the message so I would know when the outage occurred.

Function Node: Alexa Notification
var handle       = flow.get("handle");
var defaultspeed = flow.get("defaultspeed");
var average      = msg.info.average;
var isp          = msg.info.isp;

//get HH:MM
var time = new Date();
var timestamp = time.getHours() +":"+ time.getMinutes();

msg.payload = "The Internet speed at "+ timestamp + "was "+average+"Mbps out of "+defaultspeed+"Mbps. Looks like "+isp+ " sucks again";
return msg;
Google Home

To get Google Home talking, I used the Cast node. Since I cannot create a pending notification, your voice note will be played only at the time of the outage. That’s ok, we have android notifications too if you missed the announcement.

Function Node: Google Notification
var handle       = flow.get("handle");
var defaultspeed = flow.get("defaultspeed");
var average      = msg.info.average;
var isp          = msg.info.isp;

msg.payload = "The Internet speed is "+average+"Mbps out of "+defaultspeed+"Mbps. Looks like "+isp+ " sucks again";
return msg;
Android and Windows 10

Both, Android and Windows will use simple Join messages to receive updates about the conditions of your network. The notification is simple, but you probably want to read the trick about the icons below!

You could hardcode the API keys, but I used my credential system to serve it from global variables.

Function Node: Compose Push
var handle       = flow.get("handle");
var defaultspeed = flow.get("defaultspeed");
var average      = msg.info.average;
var isp          = "msg.info.isp;

var id1 = global.get('JOINmi9');
var id2 = global.get('JOINdesktop');

msg.push = {
    "deviceIds": id2,
    "title":"The Internet speed warning",
    "text":"The Internet speed is " +average+"Mbps out of "+defaultspeed+"Mbps. Looks like "+isp+ " sucks again",
    "icon":"https://doc-0k-9k-docs.googleusercontent.com/docs/securesc/ha0ro937gcuc7l7deffksulhg5h7mbp1/d35rtaa7bl3d8elcjd6koa8pk5646dnu/1570968000000/04123719101998194317/*/11CUYP4yD7iJBVc_bMmVLoZz7rRRaHAmZ?e=view"
};

return msg;
Tweet at ISP

You will have to apply for the Twitter API. It was granted quickly for my account, so I don’t expect you to wait long. Once you provide all the tokens to authorise the tweets, you will be able to tweet at your ISP about the outages.

Do not provide them with any information about your account in that tweet. Also, be very careful about scammers. My last interaction with Virgin Media on Twitter ended up with a spoof account DM me minutes after the official account responded back to me asking for card details.

Function Node: Compose Tweet
var handle       = flow.get("handle");
var defaultspeed = flow.get("defaultspeed");
var average      = msg.info.average;

//tweet
msg.payload = "Hey " + msg.payload.client.isp + 
               " ("+handle+") what's going on with my Internet, the speed dropped to " + 
               average + "Mbps from " + defaultspeed + "Mbps.";
               
return msg;

Conclusion

Even if you don’t have a spare Raspberry Pi 4, you can use this to monitor your internet speed. You won’t get accurate results if your Internet is faster than 10/100 interface, but you will be able to tell if your ISP dropped the speed significantly!

Let me know what do you think about this project, and feel free to share your internet charts in this Reddit thread.

Project Download

Download project files here. Bear in mind that Patreon supporters have early access to project files and videos.

PayPal

Nothing says "Thank you" better than keeping my coffee jar topped up!

Patreon

Support me on Patreon and get an early access to tutorial files and videos.

image/svg+xml

Bitcoin (BTC)

Use this QR to keep me caffeinated with BTC: 1FwFqqh71mUTENcRe9q4s9AWFgoc8BA9ZU

Smart Ideas with

Automate your space in with these ecosystems and integrate it with other automation services

client-image
client-image
client-image
client-image
client-image
client-image
client-image
client-image
client-image

Learn NodeRED

NodeRED for beginners: 1. Why do you need a NodeRED server?

0
To server or not to server? That's a very silly question!

Best Automation Projects

Tuya SDK for beginners: Intro to Tuya Cloud API

0
Working with Tuya Cloud API. A guide to Cloud automation for beginners, get started with REST!

NEST your old thermostat under $5

0
Nest-ing up your older thermostat under $5

Nora – Google Assistant in NodeRED

0
Integrate Google Assistant with NodeRED thanks to Nora - NodeRED home automation

Sonoff Zigbee Bridge – review

0
Sonoff line up will soon include Sonoff Zigbee Bridge and more Zigbee sensors - here is the first look

DIY Smart Washing Machine – for about 15 bucks!

0
Learn how to add washing machine notifications to your Google Home on the cheap

Smart Home

We’ve seen this before: SwitchBot K10+ PRO

0
This is an odd one. Building on the success of SwitchBot K10+ they released SwitchBot K10+ PRO - but is the experience actually better?

Is this the smart panel we have waited for?

0
ITEAD has released a new smart panel: Sonoff NSPanel Pro 120 - have they learned the lesson from the terrible launch of the original Pro? Let's see what's new.

Aqara FP1E detects motionless humans

0
This isn't exactly a new device, it's an interaction of the original Aqara presence sensor. Aqara FP1E brings Matter, ZigBee and new triggers to your smart home

SwitchBot S10: cleaning re-imagined!

0
SwitchBot S10 promises unattended vacuuming and mopping so you can focus on things you love and care for. Does it deliver?

Sonoff for households and gardens

0
ITEAD released two ZigBee devices to manage water in your household and gardens. Now you can monitor the flow and dispense water with Sonoff SWV and prevent water damage using the Sonoff Water Leak sensor with a twist.