One-liner Internet speedtest, Linux CLI, Node-Red, Home Assistant

+ Linux
We’ve been using Mobile Broadband for several years and have always been keen to measure the speed from our Internet Service Provider (ISP).

I’ve posted several variants, mostly Node-RED(NR) flows and programs that often use Python. I’m now slowly converting to Home Assistant(HA), and was glad there was an integration,  Speedtest, to do the job. But I couldn’t get it to work since HA didn’t like that the test took more than 10 seconds, 

Then I tried a Speedtest NR node, but it didn’t install because it needed Python dependencies...... (NR was installed as a HA "Add-on")

Intro 
HA OS
Just a comment on HA OS. It is not a regular Linux distribution and therefore some standard Linux "things" don't work. In this case I'm using the Linux commands "wget" and "curl" which are available.

Node-RED
If not yet installed, in HA, here is a how to.

The inspire link
So after some Googling i found this nice post.

Some ISPs, like Tele2, offer simple utilities to test your internet connection. The mentioned post shows a script

t=$(date +”%s”); wget http://speedtest.tele2.net/100MB.zip -O ->/dev/null ; echo -n ”MBit/s: ”; expr 8 \* 100 / $(($(date +”%s”)-$t))

which will give you your download speed.

The command works for any file, but the math is for a 100MB file. If you want other sites with test files, search for ”download 100mb.zip” on Google.

Code
CLI commands
With command 

t=$(date +"%s"); wget -q http://speedtest.tele2.net/100MB.zip -O ->/config/files/100MB.zip ; echo -n ; expr 8 \* 100 / $(($(date +"%s")-$t))

i got the download speed. There are some changes to the original code
  • "wget" is using quiet mode
  • the downloaded file is stored in "/config/files/"
Tele2 also have a service checking the upload speed so the stored file is uploaded with command 

t=$(date +"%s"); curl -s -T /config/files/100MB.zip http://speedtest.tele2.net/upload.php -O /dev/null ; echo -n; expr 8 \* 100 / $(($(date +"%s")-$t))

Node-RED
The flow uses "exec" nodes to run the commands, a "function" node makes the value numeric and "sensor" nodes creates the entities for HA. The file used for the speedtest are then deleted and a ping test is executed.

Comments

Popular posts, last 30 days

iCloud drive sync, or mount, with a Linux, Ubuntu, device

Raspberry Pi OS Lite with GUI, RDP, VNC, Chromium

Home Assistant with VirtualBox or Proxmox or Linux KVM ???

NetworkManager UI and access point, hotspot

Installing Ubuntu 24.04 or 24.10/25.04 on an old MacBook Air(2011)

Raspberry Pi 2, 3, 4, 5 USB SSD or USB drive boot

Waveshare CAN hat with Signal K & OpenPlotter

Clone the Raspberry boot disk

IVT, Bosch heat pump easy integration, Home Assistant

Signal K charts, offline & online