Updated, easier method. As before, grab the Ookla CLI, but then instead of literally all the rest, all you need is this in your configuration.yaml:
command_line:
sensor:
name: SpeedTest
icon: mdi:speedometer
command: /config/deps/ookla/speedtest --accept-license --accept-gdpr -p no -f json
command_timeout: 30
scan_interval: 3600
json_attributes:
- ping
- download
- upload
- packetLoss
- server
state_class: measurement
device_class: data_rate
unit_of_measurement: 'bytes'
Then you can just access this with states.sensor.speedtest.attributes.download.bandwidth
as an example. I still kept two helper sensors for download/upload speed since I use that to alter the value to Mbit/s and round it.
Much simpler, updates based on the interval set (1hr) and you get access to way more data than the other way.