Bash - Download/Upload/Ping monitoring

From Domoticz
Jump to: navigation, search


This script uses the Python module speedtest-cli for testing internet bandwidth (Download/Upload/Ping) via

It is not my script and I do not claim ownership of it (Source: Sander Filius:

This script will create 4 Virtual Sensors to monitor internet bandwidth and uptime:

  • Download (Graph)
  • Upload (Graph)
  • Ping (Graph)
  • Broadband (Switch to manually trigger Bash script)

Dependencies - hardware / software / operating system


Note: You need to be using Domoticz beta to add "Custom" Type Virtual Sensors.

  • Within Domoticz open the Setup > Hardware screen
  • Create 3 Virtual Sensors with the "Custom" Type named:
    • Download
    • Upload
    • Ping
  • Create 1 Virtual Sensors with the "Switch" Type named:
    • Broadband
  • Within Domoticz open the Setup > Devices screen and note the IDX of each new Virtual Sensor added, you'll need this in the Bash script
  • Create a new file within /domoticz/scripts/ called
  • Change the permissions on to allow it to run from crontab
  • Edit the file
  • Copy and paste the contents of the Bash script section below
  • Change the following fields:
    • host (to match your IP address or localhost)
    • idxdl (the IDX of the Download device)
    • idxul (the IDX of the Upload device)
    • idxpng (the IDX of the Ping device)
    • idxbb (the IDX of the Broadband device)
  • Save changes and run the Bash script, if successful after a moment it will display your Download, Upload and Ping
  • Within Domoticz open the Setup > Log to confirm that Domoticz was informed of this data
  • Within Domoticz open the Utility tab and check that data is being recorded
  • Within Domoticz open the Switches tab
  • Click Edit within the Broadband device
  • Set the On action to "script:///home/pi/domoticz/scripts/" (replace pi with your user and/or correct absolute path)
  • For automatic reporting you could add a crontab task to run the Bash script at given intervals (e.g. every 24 hours, etc.)

Bash script

#idx for download, upload and ping
# speedtest server number
# serverst=xxxx
# no need to edit
# speedtest-cli --simple --server $serverst > outst.txt
speedtest-cli --simple > speedtest.txt
download=$(cat speedtest.txt | sed -ne 's/^Download: \([0-9]*\.[0-9]*\).*/\1/p')
upload=$(cat speedtest.txt | sed -ne 's/^Upload: \([0-9]*\.[0-9]*\).*/\1/p')
png=$(cat speedtest.txt | sed -ne 's/^Ping: \([0-9]*\.[0-9]*\).*/\1/p')
# output if you run it manually
echo "Download = $download Mbps"
echo "Upload =  $upload Mbps"
echo "Ping =  $png ms"
# Updating download, upload and ping ..
wget -q --delete-after "http://$host/json.htm?type=command&param=udevice&idx=$idxdl&svalue=$download" >/dev/null 2>&1
wget -q --delete-after "http://$host/json.htm?type=command&param=udevice&idx=$idxul&svalue=$upload" >/dev/null 2>&1
wget -q --delete-after "http://$host/json.htm?type=command&param=udevice&idx=$idxpng&svalue=$png" >/dev/null 2>&1
# Reset Broadband switch
wget -q --delete-after "http://$host/json.htm?type=command&param=udevice&idx=$idxbb&svalue=0" >/dev/null 2>&1
# Domoticz logging
wget -q --delete-after "http://$host/json.htm?type=addlogmessage&" >/dev/null 2>&1