As mentioned above, this thread seems to pop up when you are looking in to why your SpeedTest results are lower than expected.
For those of us running HA unsupervised (container or core), add-ons aren’t available, and so I’d like to give those of us in this position an alternative to the SpeedTest plugin as well.
What I did that seems to work so far is to download the speedtest CLI client from Ookla, and put it somewhere within my /config directory so I could get HA to run it. I then defined a shell_command
for it, and set up a script to run that. I defined two numbers that the script updates with the parsed results, and then defined two template sensors that read in those numbers and convert them to Mbit/s (plus allows for statistics since they’re sensors). Finally, I created an automation to run the script every hour to update the numbers.
Here’s everything you should need to reproduce what I have…
In your configuration.yaml:
shell_command:
speedtest: /config/deps/ookla/speedtest -p no -f json
The script:
alias: SpeedTest
icon: mdi:speedometer
sequence:
- alias: Run Ookla SpeedTest via CLI
service: shell_command.speedtest
response_variable: result
data: {}
- alias: Parse JSON output
variables:
speedtest: "{{ result.stdout | from_json }}"
- alias: Record download speed
service: input_number.set_value
target:
entity_id: input_number.speedtest_download
data:
value: "{{ speedtest.download.bandwidth }}"
- alias: Record upload speed
service: input_number.set_value
target:
entity_id: input_number.speedtest_upload
data:
value: "{{ speedtest.upload.bandwidth }}"
The input numbers that the script records to (this is the raw JSON; you’ll have to define your own via GUI, but all the settings should be here for you)
{
"version": 1,
"minor_version": 1,
"key": "input_number",
"data": {
"items": [
{
"id": "speedtest_download",
"min": 0.0,
"max": 2684354560.0,
"name": "SpeedTest download",
"icon": "mdi:cloud-download",
"mode": "box",
"unit_of_measurement": "bytes",
"step": 1.0
},
{
"id": "speedtest_upload",
"min": 0.0,
"max": 2684354560.0,
"name": "SpeedTest upload",
"icon": "mdi:cloud-upload",
"mode": "box",
"unit_of_measurement": "bytes",
"step": 1.0
}
]
}
}
FYI - the max is defined to be 2.5gb. If you’re baller and have more than that, adjust as needed.
The template sensors to handle unit conversion and statistical tracking need to be done in the GUI, but it’s simple enough. Within Helpers, create a new Template sensor (not binary). Set the state to:
{{ (states.input_number.speedtest_download.state | float / 125000) | round(2) }}
with a unit of Mbit/s, Device class of Data rate, State class of Measurement (use states.input_number.speedtest_upload.state
in the yaml code for the upload sensor).
Finally, you can test it by running the SpeedTest script manually - give it a few seconds for the CLI to finish and you can check the trace to ensure it worked. You can then check the sensors for the reported download/upload speeds and if everything seems good, you can make an automation to run the script every so often (careful if you’re on a metered connection… goes without saying this consumes a decent chunk of data).
You can then also create lovelace dashboard cards using the sensors to show speed meters and stats graphs.
Enjoy!