I’m trying to make a sensor for monitoring internet speed using the official speedtest.net CLI application which can return JSON output.
Here’s an example of the output:
{"type":"result","timestamp":"2020-04-12T02:44:43Z","ping":{"jitter":0.58499999999999996,"latency":13.332000000000001},"download":{"bandwidth":115760816,"bytes":1209207888,"elapsed":10613},"upload":{"bandwidth":6509554,"bytes":23564752,"elapsed":3615},"packetLoss":0,"isp":"Atlantic Broadband","interface":{"internalIp":"192.168.1.221","name":"enp0s10","macAddr":"xxxxxxxxxx","isVpn":false,"externalIp":"x.x.x.x"},"server":{"id":14335,"name":"PBW Communications, LLC","location":"Herndon, VA","country":"United States","host":"speedtest.leadmon.net","port":8080,"ip":"38.103.8.130"},"result":{"id":"xxxxxxxxxxxxx","url":"https://www.speedtest.net/result/c/xxxxxxxxxxxxxxxxxxxx"}}
I’ve made a sensor which partially works, but doesn’t give me the key bits I really want:
sensor:
- platform: command_line
name: "Speedtest.net"
#command: "/config/speedtest-net/speedtest --accept-license --format=json > /config/debug.txt 2>&1"
command: "/config/speedtest-net/speedtest --accept-license --format=json"
scan_interval: 3600
command_timeout: 60
json_attributes:
- ping.jitter
- ping.latency
- download.bandwidth
- upload.bandwidth
- packetLoss
- isp
- name
- location
- country
- url
value_template: "{{ value_json['download.bandwidth'] }} / {{ value_json['upload.bandwidth'] }}"
When I look at it, I don’t see the download/upload speeds (which are the important bits).
First, how do I get it populating the rest of the values?
Second, how do I do the conversion from bytes/sec to Mbit/sec (I need to take the reported bandwidth X*8/1000000)