Tag Archives: speedtest

push speedtest results to domoticz

Preface

I needed to monitor my internet bandwith because it was flappy.

Decided to push speedtest information to domoticz (easy graphs, easy notifications).

1. install speedtest (apt-get install speedtest-cli)
2. create 3 virtual counters in domoticz (and remember the idx’s)
3. create a script, put in the variables and chmod +x it
4. crontab -e it (I cron it @hourly)

Code

#!/bin/bash
#setup
host=xxx.xxx.xxx.xxx
port=xxxx
username=xxx
password=xxx
pingidx=xxx
downloadidx=xxx
uploadidx=xxx
#
# no need to edit
speedtest-cli --simple > output.txt
ping=$(cat output.txt | sed -ne 's/^Ping: \([0-9]*\.[0-9]*\).*/\1/p')
download=$(cat output.txt | sed -ne 's/^Download: \([0-9]*\.[0-9]*\).*/\1/p')
upload=$(cat output.txt | sed -ne 's/^Upload: \([0-9]*\.[0-9]*\).*/\1/p')
#output if you run it manually
echo "ping = $ping ms"
echo "download = $download Mbps"
echo "upload = $upload Mbps"

# Push -> domoticz
curl -s -i -H "Accept: application/json" "http://$username:$password@$host:$port/json.htm?type=command&param=udevice&idx=$pingidx&svalue=$ping"
curl -s -i -H "Accept: application/json" "http://$username:$password@$host:$port/json.htm?type=command&param=udevice&idx=$downloadidx&svalue=$download"
curl -s -i -H "Accept: application/json" "http://$username:$password@$host:$port/json.htm?type=command&param=udevice&idx=$uploadidx&svalue=$upload"

Result

screen-shot-2016-10-22-at-19-57-29