Bredbandskollen, internet speedtest, integrating with Home Assistant via MQTT Discovery
In my earlier posts about Lightweight DIY Linux Server Monitoring I used a small Bash script and MQTT Auto-Discovery to get server metrics into Home Assistant (HA) without any manual sensor setup. The same idea works very well for something else I wanted to keep an eye on: the speed of my internet connection.
This time the data source is the command line client for Bredbandskollen. It measures download, upload and latency against a nearby test server, and prints the result as a single line of text, perfect for a script. The script runs on my Proxmox host, publishes the result to the Mosquitto broker, and HA creates a device with all the sensors by itself.
Intro
Home Assistant MQTT Auto-Discovery
The script publishes the configuration for every sensor (with the "
retain" flag), so a device called "Internet Speedtest" shows up under "Settings > Devices & Services > MQTT" without any YAML.Discovery on every run
In the server monitoring post I throttled the heavy configuration payloads to once a day. Here the script only runs every 30 minutes, and the discovery messages are just a few hundred bytes each, so I simply send them every time. HA ignores identical configs, and if the broker or HA is rebuilt the sensors come back automatically on the next run.
Availability
If the measurement fails, the script publishes "
offline" and the sensors turns "unavailable" in HA instead of showing an old value.Install
You need a working MQTT integration in HA and a user on the broker, see the first post for the details.
In my case the script is executed on my Proxmox host with a user "proxmox". It's important that the script is running on a machine with some muscles and it is Ethernet connected to get right measurements
So on the Linux machine that will run the test proceed with
sudo apt update
sudo apt install mosquitto-clients
sudo apt install -y build-essential gcc g++ makewget https://github.com/dotse/bbk/archive/refs/heads/master.zip
(sudo apt install unzip)
unzip master.zip
cd bbk-master/src/cli
make clean
make
Will create a command "cli". Execute with "./cli"
Rename and put the command in the right place
cp cli /usr/local/bin/bbk-cli
Normal output, for my 5G Internet, looks like this:
Start: 2026-10-14 23:09:09
Network operator: Tele2
Support ID: mmo10d9d1970
Latency: 18.186 ms
Download: 420.532 Mbit/s
Upload: 21.279 Mbit/s
Measurement ID: 537086434
The script uses the "--quiet" flag which gives one line with seven fields:426.757 22.8661 15.3436 anycast-global-ipv4.mserver.bredbandskollen.se Tele2 mmo10dc51c71 537086445
That is: download, upload, latency, server, operator, support ID and measurement ID. The order matters, so run "bbk-cli --quiet" on your own machine and check that it looks the same before continuing.
The script
Please update the following in the script:
- BROKER="192.nn.nn.nn"
- MQTT_AUTH=(-u "user" -P "passwd")
Save it in the home directory of the executing user and run it once with
bash -x speedtest.sh
The test takes a little while since it actually measures the line. Check the printed JSON and any errors.
Watch the Magic
Open "Settings > Devices & Services > MQTT" in HA. A new device, "Internet Speedtest", has appeared with seven sensors: Download, Upload, Latency, Support ID, Operator, Server and Last measurement. Because the numeric sensors have "
state_class: measurement" HA keeps long-term statistics, and you can put them straight into a history graph or a statistics card.Run it every 30 minutes
Add a cronjob with "crontab -e":
*/30 * * * * bash /home/proxmox/speedtest.sh
Each test uses real bandwidth, so I think every 30 minutes is a good balance. On a slow or metered connection you might want to run it less often.
Good to know
- Display unit: The sensors report Mbit/s. In HA you can change the display unit per entity (for example to Gbit/s or MB/s) under the entity’s settings, and HA converts the value for you.
- Changed a sensor? Edit the script and it is updated on the next run. If you remove a sensor from the script it stays in HA until you clear its retained config topic:
mosquitto_pub -h 192.nn.nn.nn -u XXX -P XXX -r -n -t homeassistant/sensor/inet_speedtest/operator/config
- Topic gotcha: I originally had
BASE_TOPIC="inetSpeed/"with a trailing slash, which gave a double slash (inetSpeed//metrics) when the topic was built. Leave the slash out.
Created together with Claude !!

Comments
Post a Comment
Feel free to leave a comment ! ... but due to a lot of spam comments I have to moderate them. Will reply ASAP !