How to monitor your internet connection with virtual custom sensors

Client tools or tools that can connect with Domoticz. Tools for Windows, iOS, Android, Linux etc.

Moderator: leecollings

Post Reply
safi78
Posts: 204
Joined: Thursday 05 September 2013 15:39
Target OS: Linux
Domoticz version: LastBeta
Contact:

Re: How to monitor your internet connection with virtual custom sensors

Post by safi78 »

I created a fairly similar script for a differtent purpose, maybe you guys like it as well: viewtopic.php?f=21&t=14591
homebridge, rfxcom, zwave, nest, applamp, hue, debian, apple, mysensors, netatmo, fibaro, synology, foscam, otherz
johan99
Posts: 8
Joined: Wednesday 24 August 2016 15:25
Target OS: -
Domoticz version:
Contact:

Re: How to monitor your internet connection with virtual custom sensors

Post by johan99 »

Hi,
I try to get this working on my Dometicz installed at a Windows 2012-server.
I get Speedtest working and I got python installed and working.

But when running this scrip, I get this error message:
File "speedtest2.sh", line 15
ping=$(cat output.txt | sed -ne 's/^Ping: \([0-9]*\.[0-9]*\).*/\1/p')
^
SyntaxError: invalid syntax

Any idea on what I do wrong?
mikeoo
Posts: 110
Joined: Sunday 22 March 2015 7:35
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Holland
Contact:

Re: How to monitor your internet connection with virtual custom sensors

Post by mikeoo »

johan99 wrote:Hi,
I try to get this working on my Dometicz installed at a Windows 2012-server.
I get Speedtest working and I got python installed and working.

But when running this scrip, I get this error message:
File "speedtest2.sh", line 15
ping=$(cat output.txt | sed -ne 's/^Ping: \([0-9]*\.[0-9]*\).*/\1/p')
^
SyntaxError: invalid syntax

Any idea on what I do wrong?
Place your script and the command you use also here so we can check.
User avatar
gjaa
Posts: 38
Joined: Thursday 12 February 2015 6:59
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: The Netherlands
Contact:

Re: How to monitor your internet connection with virtual custom sensors

Post by gjaa »

I've made some icons (I don't like the default Icon ;) )
One for up and download (speed)
and one for ping (ping)
Attachments
ping.zip
ping
(19.61 KiB) Downloaded 208 times
Speed.zip
Up- and download
(14.4 KiB) Downloaded 189 times
johan99
Posts: 8
Joined: Wednesday 24 August 2016 15:25
Target OS: -
Domoticz version:
Contact:

Re: How to monitor your internet connection with virtual custom sensors

Post by johan99 »

mikeoo wrote:
johan99 wrote:Hi,
I try to get this working on my Dometicz installed at a Windows 2012-server.
I get Speedtest working and I got python installed and working.

But when running this scrip, I get this error message:
File "speedtest2.sh", line 15
ping=$(cat output.txt | sed -ne 's/^Ping: \([0-9]*\.[0-9]*\).*/\1/p')
^
SyntaxError: invalid syntax

Any idea on what I do wrong?
Place your script and the command you use also here so we can check.
Ok, here is first the code and after that is the command line.

Code: Select all

#!/bin/bash

#setup
port=8080
username=xxxx
password=xxxx
host=localhost
pingidx=239
downloadidx=241
uploadidx=240


# 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"

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"
command in windows (cmd runned in admin mode): python speedtest.sh
mikeoo
Posts: 110
Joined: Sunday 22 March 2015 7:35
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Holland
Contact:

Re: How to monitor your internet connection with virtual custom sensors

Post by mikeoo »

johan99 wrote:
mikeoo wrote:
johan99 wrote:Hi,
I try to get this working on my Dometicz installed at a Windows 2012-server.
I get Speedtest working and I got python installed and working.

But when running this scrip, I get this error message:
File "speedtest2.sh", line 15
ping=$(cat output.txt | sed -ne 's/^Ping: \([0-9]*\.[0-9]*\).*/\1/p')
^
SyntaxError: invalid syntax

Any idea on what I do wrong?
Place your script and the command you use also here so we can check.
Ok, here is first the code and after that is the command line.

Code: Select all

#!/bin/bash

#setup
port=8080
username=xxxx
password=xxxx
host=localhost
pingidx=239
downloadidx=241
uploadidx=240


# 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"

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"
command in windows (cmd runned in admin mode): python speedtest.sh
Try to change host=localhost to host=ip-adres of domoticz and test if that change something.
mikeoo
Posts: 110
Joined: Sunday 22 March 2015 7:35
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Holland
Contact:

Re: How to monitor your internet connection with virtual custom sensors

Post by mikeoo »

gjaa wrote:I've made some icons (I don't like the default Icon ;) )
One for up and download (speed)
and one for ping (ping)
Nice one's :mrgreen:

Tip
I did not see them when i try to change them for the Custum Sensor afther uploading the icons in Domoticz.
I reboot did not solve the problem.

You need the do a browser refresh and then you can see them.
johan99
Posts: 8
Joined: Wednesday 24 August 2016 15:25
Target OS: -
Domoticz version:
Contact:

Re: How to monitor your internet connection with virtual custom sensors

Post by johan99 »

mikeoo wrote:
johan99 wrote:
mikeoo wrote: Try to change host=localhost to host=ip-adres of domoticz and test if that change something.
When i use the IP I get this error:

File "speedtest2.sh", line 7
host=192.168.0.188
^
SyntaxError: invalid syntax

I says the zero in the adress is the problem, dont know why, the adress is correct. When I edit the file i use a Windows PC and notepad++ and choose unix EOL.
mikeoo
Posts: 110
Joined: Sunday 22 March 2015 7:35
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Holland
Contact:

Re: How to monitor your internet connection with virtual custom sensors

Post by mikeoo »

johan99 wrote:
mikeoo wrote:
johan99 wrote:
When i use the IP I get this error:

File "speedtest2.sh", line 7
host=192.168.0.188
^
SyntaxError: invalid syntax

I says the zero in the adress is the problem, dont know why, the adress is correct. When I edit the file i use a Windows PC and notepad++ and choose unix EOL.
You can try the use a different editor. Lot of Windows editors give problems with linux files and to be sure try an other one. Because it say that er is a problem it looks like notepad++ does something with the file. Try Sublime Text https://sublimetext.com/3 that one is working fine with linux files

Create a new file again, don't copy and past the old one because then you can copy the strange characters in to the new file.

If it still not working maybe a pyhton version problem, try to run it without python command and just speedtest
viewtopic.php?f=21&t=13814&p=100190&hil ... ws#p100190
johan99
Posts: 8
Joined: Wednesday 24 August 2016 15:25
Target OS: -
Domoticz version:
Contact:

Re: How to monitor your internet connection with virtual custom sensors

Post by johan99 »

I tried sublimetext now aswell and get the same issues.
I think I set a Raspberry Pi up (have one not used for anything) and use that for this instead. Using it as a 2:nd Domoticz server. When reading this forum I realize that most of you use RP and most guides are written for RP.

Thanks for the help though. And I'll keep on using the Windows server as my main server for Domoticz and are intrested to hear from you who got everything working fine with Win and Domoticz.
dtech
Posts: 20
Joined: Thursday 26 November 2015 8:31
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: RE: Re: How to monitor your internet connection with virtual custom sensors

Post by dtech »

gjaa wrote:I've made some icons (I don't like the default Icon ;) )
One for up and download (speed)
and one for ping (ping)
How this icons can be added ?
User avatar
sincze
Posts: 1300
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Location: Netherlands / Breda Area
Contact:

Re: RE: Re: How to monitor your internet connection with virtual custom sensors

Post by sincze »

dtech wrote:
gjaa wrote:I've made some icons (I don't like the default Icon ;) )
One for up and download (speed)
and one for ping (ping)
How this icons can be added ?
I found the solution in the wiki
http://www.domoticz.com/wiki/Custom_ico ... binterface
Pass2php
LAN: RFLink, P1, OTGW, MySensors
USB: RFXCom, ZWave, Sonoff 3
MQTT: ZIgbee2MQTT,
ZWAVE: Zwave-JS-UI
WIFI: Mi-light, Tasmota, Xiaomi Shelly
Solar: Omnik, PVOutput
Video: Kodi, Harmony HUB, Chromecast
Sensors: You name it I got 1.
Trigun
Posts: 390
Joined: Wednesday 30 November 2016 11:58
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Contact:

Re: How to monitor your internet connection with virtual custom sensors

Post by Trigun »

Hi all, first of all, great feature!! i carried out all the steps bit for some reason the custom sensors don't show the values. When I run the script I do get the correct info, but the sensors are not showing anything. Does anyone have an idea where I went wrong?


Sent from my iPhone using Tapatalk
User avatar
EdwinK
Posts: 1820
Joined: Sunday 22 January 2017 21:46
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Rhoon
Contact:

Re: How to monitor your internet connection with virtual custom sensors

Post by EdwinK »

I like this script a lot. One small thing though.

After the data, I get a '0' instead of the right value (ms, Mbp/s). Can this be fixed?

Image
Forget about the first tile, that is from another script.
Running latest BETA on a Pi-3 | Toon® Thermostat (rooted) | Hue | Tuya | IKEA tradfri | Dashticz V3 on Lenovo Huawei Tablet | Conbee
koowee
Posts: 62
Joined: Thursday 29 December 2016 18:17
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Finland
Contact:

Re: How to monitor your internet connection with virtual custom sensors

Post by koowee »

EdKo66 wrote:I like this script a lot. One small thing though.

After the data, I get a '0' instead of the right value (ms, Mbp/s). Can this be fixed?

Image
Forget about the first tile, that is from another script.
I think that you need to modify those, Device (Ping, Download and Upload) > Edit > Axis label (add ms or Mbp/s depending device)
User avatar
EdwinK
Posts: 1820
Joined: Sunday 22 January 2017 21:46
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Rhoon
Contact:

Re: How to monitor your internet connection with virtual custom sensors

Post by EdwinK »

Ah.. Of course. Thanks :)
Running latest BETA on a Pi-3 | Toon® Thermostat (rooted) | Hue | Tuya | IKEA tradfri | Dashticz V3 on Lenovo Huawei Tablet | Conbee
Trigun
Posts: 390
Joined: Wednesday 30 November 2016 11:58
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Contact:

Re: How to monitor your internet connection with virtual custom sensors

Post by Trigun »

Hey guys,

Really like the script! its working well when manually run. but for some reason I can't seem to get the output in domoticz.
does anyone have an idea?
I am running it on a Synology NAS.

Thnx in advance!
User avatar
EdwinK
Posts: 1820
Joined: Sunday 22 January 2017 21:46
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Rhoon
Contact:

Re: How to monitor your internet connection with virtual custom sensors

Post by EdwinK »

Running this on a Synology NAS too, and had it working in matter of minutes.

Synology doesn't have apt-get, so you need to find another way to get the files. I used easy_install, but can't quite remember how I did install that.
Search for easy_install and Synology on the Google.
Last edited by EdwinK on Tuesday 18 April 2017 20:00, edited 1 time in total.
Running latest BETA on a Pi-3 | Toon® Thermostat (rooted) | Hue | Tuya | IKEA tradfri | Dashticz V3 on Lenovo Huawei Tablet | Conbee
User avatar
EdwinK
Posts: 1820
Joined: Sunday 22 January 2017 21:46
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Rhoon
Contact:

Re: How to monitor your internet connection with virtual custom sensors

Post by EdwinK »

gjaa wrote:I've made some icons (I don't like the default Icon ;) )
One for up and download (speed)
and one for ping (ping)

Thanks for those icons ;)
Running latest BETA on a Pi-3 | Toon® Thermostat (rooted) | Hue | Tuya | IKEA tradfri | Dashticz V3 on Lenovo Huawei Tablet | Conbee
Trigun
Posts: 390
Joined: Wednesday 30 November 2016 11:58
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Contact:

Re: How to monitor your internet connection with virtual custom sensors

Post by Trigun »

Hi Edko66,

is there a chance you can help me out here?
since I have no username and password for domoticz, this is my script.

Code: Select all

#!/bin/bash

#setup
host=192.168.10.21
port=8084
pingidx=8
downloadidx=6
uploadidx=7

# no need to edit
/volume1/homes/admin/Speedtest/speedtest-cli --server 5302 > 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"

curl -s -i -H "Accept: application/json" "http://$host:$port/json.htm?type=command&param=udevice&idx=$pingidx&svalue=$ping"
curl -s -i -H "Accept: application/json" "http://$host:$port/json.htm?type=command&param=udevice&idx=$downloadidx&svalue=$download"
curl -s -i -H "Accept: application/json" "http://$host:$port/json.htm?type=command&param=udevice&idx=$uploadidx&svalue=$upload"
I can see the output.txt file it not in the same directory where thie stdomo.sh and speedtest-cli are in. shoudl this be?
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest