Speedtest.net integration alternative

Official Speedtest.net integration has been broken, from time to time, either from speedtest-cli or Home Assistant changes. There is an alternative in running a separate Docker of Speedtest Tracker (not affiliated) as it includes an API (available at /api/speedtest/latest) and importing the results in Home Assistant are fairly easy:

Example of API results: {“message”:“ok”,“data”:{“id”:123456789,“ping”:9.467,“download”:1880.9072,“upload”:817.7248,“server_id”:123456789,“server_host”:“speedtest.xxx.xx:8080”,“server_name”:“XXXXXXXXXXX”,“url”:“https://www.speedtest.net/result/c/123456789-123456789-123456789-123456789-123456789”,“scheduled”:true,“failed”:false,“created_at”:“2024-01-23T08:00:20.000000Z”,“updated_at”:“2024-01-23T08:00:20.000000Z”}}

As the Speedtest requires a fair amount of computing power, running it on a separate machine can be useful in cases where the Home Assistant instance runs on a low performance hardware (Raspberry Pi, low power NUCs, etc.) or when a multi-gigabit network card is a available to a server grade machine but not to Home Assistant.

- platform: rest
  resource: http://192.168.0.46:45043/api/speedtest/latest
  name: Download Speed
  value_template: "{{ value_json['data']['download'] }}"
  unit_of_measurement: Mbps
  unique_id: '0100000000001'
- platform: rest
  resource: http://192.168.0.46:45043/api/speedtest/latest
  name: Upload Speed
  value_template: "{{ value_json['data']['upload'] }}"
  unit_of_measurement: Mbps
  unique_id: '0100000000002'
- platform: rest
  resource: http://192.168.0.46:45043/api/speedtest/latest
  name: Ping
  value_template: "{{ value_json['data']['ping'] }}"
  unit_of_measurement: ms
  unique_id: '0100000000003'

If planning to share the results, or view them at a later time, an URL sensor can be imported.

- platform: rest
  resource: http://192.168.0.46:45043/api/speedtest/latest
  name: URL
  value_template: "{{ value_json['data']['url'] }}"
  unique_id: '0100000000004'

Also, remainder of API values (server_id, server_host, server_name, scheduled, failed, created_at, updated_at) can be useful for serving additional sensors.

Home Assistant card:

image

Speedtest Tracker card:

4 Likes

Hello i added the sensor configuration into my home assistant configuration yaml but after restart i cannot found the sensors… what is wrong ?
may uou share the card code too ?
Thanks

Logs? Where are they?

Below is the code for the card.

To be sure I understood your problem: you are not using the official speedtest integration in Home Assistant; instead, you are using the Speedtest Tracker on a separate machine with REST manual sensors, right?

Card
cards:
  - cards:
      - cards:
          - align: split
            card_style:
              border-radius: 5px
            columns: 1
            entities:
              - entity: sensor.ping
            entity_row: true
            max: 100
            padding: 4px
            show_icon: true
            title_position: inside
            type: custom:bar-card
        type: horizontal-stack
    type: horizontal-stack
  - cards:
      - color_thresholds:
          - color: red
            value: 0
          - color: yellow
            value: 1500
          - color: green
            value: 1800
        entities:
          - sensor.download_speed
        font_size: 70
        height: 70
        hours_to_show: 24
        icon: mdi:download
        line_width: 2
        name: Download
        points_per_hour: 1
        show:
          extrema: true
          fill: true
        type: custom:mini-graph-card
      - color_thresholds:
          - color: red
            value: 0
          - color: yellow
            value: 600
          - color: green
            value: 800
        entities:
          - sensor.upload_speed
        font_size: 70
        height: 70
        hours_to_show: 24
        icon: mdi:upload
        line_width: 2
        name: Upload
        points_per_hour: 1
        show:
          extrema: true
          fill: true
        type: custom:mini-graph-card
    type: horizontal-stack
type: vertical-stack
view_layout:
  width: 10
  max_cols: 10

Thank you so much… all ok now

Nice. I recently moved to the alexjustesen version of SpeedTest and wanted to remove the HA one as it was always inconsistent + was duplicated load on the internet.

Your code did the trick to import the API data into HA.
Added the code to sensors.yaml and I’m getting proper numbers now :slight_smile:

One thing to note for those that are looking to replace the HA integration SpeedTest Tracker is to put the new REST code in, but change the names to align with the HA integration names so that the sensor history remains available and any automations you may have will continue to trigger.

e.g.
change:

  name: Download Speed
  name: Upload Speed
  name: Ping

To:

  name: Speedtest Download
  name: Speedtest Upload
  name: Speedtest Ping

Then remove the HA integrationn version and reboot.
It’ll swap them like a slight-of-had card trick and continue as if nothing has changed :slight_smile:

Integrated speedtest was waaaaay off before. Should be 900+
image

I didn’t have any automations enabled previously because SpeedTest integration was doing that automatically. What did you use to trigger these sensors to update periodically? I like the idea that Speedtest Tracker has a webhook that can be triggered each time it runs. Was going to look into using that but if anyone has suggestions of a good way to do this, please let me konw.

The docker image for Speedtest Tracker defaults to updating once per hour but it can be changed to other schedules in Admin Panel → General and you can use a cron generator to set it to own needs.

In a future release it’s planned to have a method of triggering the speedtest to run triggered from an external prompt like an HA trigger.

Externally triggering a speedtest is planned for the API feature release.
[Feature] Allow a SpeedTest to be triggered by external call · Issue #1447 · alexjustesen/speedtest-tracker · GitHub

Worth noting that there’s been an update with some breaking changes.
Notably that the cron/schedule has been moved to an environment variable and that an API key needs to be created (also an environment variable)

Get your APP_KEY: https://speedtest-tracker.dev/

Example docker changes/addition in docker CLI:

-e SPEEDTEST_SCHEDULE="0 * * * *" \
-e APP_KEY=base64:Th1515an4P1K3yJqzTdoiwPfpqnKnbIWnNZsOa2Yq7I= \

Is it possible to create a button in home assistant to run the the sepeedtest?

It is supposed to have an option to trigger an update in the next docker update (see 3 posts above)

Hi, I encountered the same issue when I added the sensor configuration to my Home Assistant configuration.yaml. However, after restarting, the sensors didn’t appear. I checked the log files for any errors, but couldn’t find anything.

Additionally, I verified that the Speedtest-Tracker Docker container v0.21.2 is running and responding correctly. When I execute the command http://192.168.X.X:XXXX/api/speedtest/latest, I receive the expected response with all the speedtest information."

Your help will be highly appreciated

what sensor configuration have you used?

Thank you for reply, I used yaml code above and adjust it to my speedtest-tracker docker IP address

I used to use Speedtest.net integration and i have one service with 3 entities : speedtest ping, speedtest upload, and speedtest download.

Can you post the actual config (sanitized of any personal info)?

Also, have you used the official speedtest integration before trying this one?

#Speedtest-tracke    
  - platform: rest
    resource: http://192.168.1.142:8696/api/speedtest/latest
    name: Download Speed
    value_template: "{{ value_json['data']['download'] }}"
    unit_of_measurement: Mbps
    unique_id: '0100000000001'
  - platform: rest
    resource: http://192.168.1.142:8696/api/speedtest/latest
    name: Upload Speed
    value_template: "{{ value_json['data']['upload'] }}"
    unit_of_measurement: Mbps
    unique_id: '0100000000002'
  - platform: rest
    resource: http://192.168.1.142:8696/api/speedtest/latest
    name: Ping
    value_template: "{{ value_json['data']['ping'] }}"
    unit_of_measurement: ms
    unique_id: '0100000000003'

and yes currently the the official speedtest integration is running

Let’s clarify several things:

  1. my post refers to a split configuration (Splitting up the configuration - Home Assistant). Instead, you mentioned that you used configuration.yaml which would not work if copy/pasted as is (it could be correct, however you didn’t posted the complete section of sensors from configuration.yaml).
  1. if using before the official speedtest integration in HA (Speedtest.net - Home Assistant) then you would already have the sensors from the initial integration and the new ones will have suffixes in their names. Can you check that?

Instead of calling the rest url multiple times, you can simply make use of the newish notation in your config file like this:
(NOTE: I have renamed the sensors as I have a few download and upload or ping sensors, this will NOT be a drop in replacement for you - you’d have to stick to the standard names)

# Create UUID's via https://www.uuidgenerator.net
rest:
  resource: http://<your_IP_here>/api/speedtest/latest
  scan_interval: 60
  sensor:
  - name: Internet Download Speed
    value_template: "{{ value_json['data']['download'] }}"
    unit_of_measurement: Mbps
    unique_id: '4fcd3c93-1ae2-47a5-af7e-300f9fc73a0b'
  - name: Internet Upload Speed
    value_template: "{{ value_json['data']['upload'] }}"
    unit_of_measurement: Mbps
    unique_id: 'cdc1fe6c-1000-46aa-9340-05b99d49c292'
  - name: Internet Ping
    value_template: "{{ value_json['data']['ping'] }}"
    unit_of_measurement: ms
    unique_id: '5adc7f11-470b-4821-85f2-ca4fee43518e'
  - name: Internet Speed URL
    value_template: "{{ value_json['data']['url'] }}"
    unique_id: '06ef57d4-2ad2-4438-b09d-ac7788706d20'
  - name: Internet Speed Test Time
    value_template: "{{ value_json['data']['updated_at'] }}"
    unique_id: '9f2d86ae-290c-4ae2-9056-5c49b2e66f59'
  - name: Internet Speed Server URL
    value_template: "{{ value_json['data']['server_host'] }}"
    unique_id: 'ff663e03-cafa-4c35-adb4-1d0d88a5f158'