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

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,

Ok, I got the last part working. but still othing happens within domoticz.
I the domoticz logfile it doesn't seem check on the script for some reason.

is there anything else I need to setup within domoticz besides creating 3 virtual devices?

I installed it through the following.
wget -O speedtest-cli https://raw.githubusercontent.com/sivel ... est_cli.py

within the CLI it works fine but somehow domoticz is seeing the output
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 »

Hi Trigun,

What's the output of the script if you run it manually?

Looks like it looses the location to output.txt.

Specifying that output.txt should be at ~/ and later cat'ing it from there might do the trick :)

Also, your speedtest package seems to be in the admin folder. Did you schedule this in the crontab for admin as well? Or another user (that might not have permissions on that folder?)

Can you try this? I hope that with the '~' it will place the output.txt to the home-folder of the user you schedule it for, so it wouldn't matter which user you use. Next to that it's more specific to where the output.txt is, might work ...

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"
homebridge, rfxcom, zwave, nest, applamp, hue, debian, apple, mysensors, netatmo, fibaro, synology, foscam, otherz
User avatar
Siewert308SW
Posts: 288
Joined: Monday 29 December 2014 15:47
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: The Netherlands
Contact:

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

Post by Siewert308SW »

Just wanna say thx for your script.
Using it to monitor some issues with my connection -> isp regarding ping times.
Schermafdruk 2017-04-19 00.38.56.png
Schermafdruk 2017-04-19 00.38.56.png (295.58 KiB) Viewed 4896 times
Setup:
- RPi4 - Domo Stable / Aeotec Z-stick7 / PiHole Unbound Gemini
- RPi4 - PiHole / PiVPN Unbound Gemini
- Synology DS923+ / DS218j
- P1 Gas/Power, SmartGateway watermeter
- Fibaro switches, contacts, plugs, smoke/Co2 ect
- rootfs @ USB HDD
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 »

Siewert308SW wrote:Just wanna say thx for your script.
Nice to be appreciated :D
homebridge, rfxcom, zwave, nest, applamp, hue, debian, apple, mysensors, netatmo, fibaro, synology, foscam, otherz
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 »

safi78 wrote:Hi Trigun,

What's the output of the script if you run it manually?

Looks like it looses the location to output.txt.

Specifying that output.txt should be at ~/ and later cat'ing it from there might do the trick :)

Also, your speedtest package seems to be in the admin folder. Did you schedule this in the crontab for admin as well? Or another user (that might not have permissions on that folder?)

Can you try this? I hope that with the '~' it will place the output.txt to the home-folder of the user you schedule it for, so it wouldn't matter which user you use. Next to that it's more specific to where the output.txt is, might work ...

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"
Hi safi78,

thnx for you reply!
It perfectly generates an output.txt file in the folder, the data is correct when I compare it to the output in de CLI but for some reason Domoticz is not picking up the values. I have no idea why it isn't working.

Grtz.
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 »

Again,

What's the output of the script if you run it manually?

Are you sure your host, port and idx settings are correct? And that you can connect without a password?
homebridge, rfxcom, zwave, nest, applamp, hue, debian, apple, mysensors, netatmo, fibaro, synology, foscam, otherz
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 »

safi78 wrote:Again,

What's the output of the script if you run it manually?

Are you sure your host, port and idx settings are correct? And that you can connect without a password?
ok, this is what I do.
I connect to the CLI run the following command: /volume1/homes/admin/Speedtest/stdomo.sh (without a password)
I get the following result:
output1.JPG
output1.JPG (18.08 KiB) Viewed 4867 times
It takes long though for the script to finish, even though the results are already in the script.
+ even though there is no ping time, it does show a ping value in the output.txt file, I guess this is due to the fixed server I selected (5302)
I tried using the script you send in the previous reply, but so far no luck.

Grtz.
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 »

Can you try again without the '-s' after the 'curl' command?

As far as i can tell, you don't get a ping value (could be another version of speedtest-cli than I use).

And, curl returns it's result after trying to update domoticz, I don't see that here. (could be another version of curl).

Run it again, without the -s and send the results?
Last edited by safi78 on Wednesday 19 April 2017 21:38, edited 1 time in total.
homebridge, rfxcom, zwave, nest, applamp, hue, debian, apple, mysensors, netatmo, fibaro, synology, foscam, otherz
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 »

did it.

the result in the output.txt file is as follows:
Knipsel1.JPG
Knipsel1.JPG (41.23 KiB) Viewed 4862 times
the output from the cli is as follows:
Knipsel.JPG
Knipsel.JPG (20.51 KiB) Viewed 4862 times
it cold very well be I got the wrong version.
perhaps you can tell me which one I need for a synology NAS.
do I perhaps need to install a specific version of curl?

Cheers
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 »

change

Code: Select all

/volume1/homes/admin/Speedtest/speedtest-cli --server 5302 > ~/output.txt
to

Code: Select all

/volume1/homes/admin/Speedtest/speedtest-cli --simple --server 5302 > ~/output.txt
homebridge, rfxcom, zwave, nest, applamp, hue, debian, apple, mysensors, netatmo, fibaro, synology, foscam, otherz
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 »

I got a ping value now :)
see:
Knipsel2.JPG
Knipsel2.JPG (21.1 KiB) Viewed 4858 times
but stil no result in Domoticz.

Grtz
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 »

change

Code: Select all

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

Code: Select all

curl -i -H "Accept: application/json" "http://$host:$port/json.htm?type=command&param=udevice&idx=$pingidx&svalue=$ping"
curl -i -H "Accept: application/json" "http://$host:$port/json.htm?type=command&param=udevice&idx=$downloadidx&svalue=$download"
curl -i -H "Accept: application/json" "http://$host:$port/json.htm?type=command&param=udevice&idx=$uploadidx&svalue=$upload"
and show what happens.
homebridge, rfxcom, zwave, nest, applamp, hue, debian, apple, mysensors, netatmo, fibaro, synology, foscam, otherz
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 »

I don't know what happend, but i re-installed speedtest-cli and re-did the script using your update ~/ and it works!

thanks a lot safi78. much appreciated!!
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 »

Trigun wrote:I don't know what happend, but i re-installed speedtest-cli and re-did the script using your update ~/ and it works!

thanks a lot safi78. much appreciated!!
I doubt if that was your problem, after adding the '--simple' the part to 'get' the data out of the txt was fixed already.

The problem was in your host/user/pass/idx and curl part, you probably changed something there.

Anyway, always glad to help!
homebridge, rfxcom, zwave, nest, applamp, hue, debian, apple, mysensors, netatmo, fibaro, synology, foscam, otherz
ilpier
Posts: 31
Joined: Friday 24 February 2017 12:01
Target OS: Windows
Domoticz version:
Contact:

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

Post by ilpier »

Here's the problem!
On windows 10,with CMD!
Someone help me?
Prob.JPG
Prob.JPG (46.49 KiB) Viewed 4629 times
bertbigb
Posts: 147
Joined: Thursday 13 August 2015 13:36
Target OS: NAS (Synology & others)
Domoticz version: beta
Location: Netherlands
Contact:

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

Post by bertbigb »

ilpier wrote:Here's the problem!
On windows 10,with CMD!
Someone help me?
Prob.JPG
If you provide your script also we could hopefully see where the mistake (typo) is. Now we only know it is in line 14 :D
Best regards Bert

Synology DS1517+ - DSM 6.2
Raspberry PI2-B, Raspberry Nano - Raspberry PI3 - model B
Xiaomi Gateway - Philips HUE Lights - Zwave - RFXCom(E) with KaKu and other 433MHz devices - Yeelight Lights - Toon
ilpier
Posts: 31
Joined: Friday 24 February 2017 12:01
Target OS: Windows
Domoticz version:
Contact:

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

Post by ilpier »

yes Sorry!
here's the code!

Code: Select all

#!/bin/bash

#setup
port=8080
username=Admin
password=***
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"
ben53252642
Posts: 543
Joined: Saturday 02 July 2016 5:17
Target OS: Linux
Domoticz version: Beta
Contact:

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

Post by ben53252642 »

We need a combined sensor for Internet Upload and Download, like we have combined sensor for Temperature and Humidity, I have about 300 devices in my Domoticz, keeping them as organised as possible is essential!
1.PNG
1.PNG (56.03 KiB) Viewed 4600 times
2.PNG
2.PNG (220.93 KiB) Viewed 4600 times
Unless otherwise stated, all my code is released under GPL 3 license: https://www.gnu.org/licenses/gpl-3.0.en.html
bertbigb
Posts: 147
Joined: Thursday 13 August 2015 13:36
Target OS: NAS (Synology & others)
Domoticz version: beta
Location: Netherlands
Contact:

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

Post by bertbigb »

Hi ilpier,

I think your problem is related to the fact that your windows system doesn't know where to find the several files.
Your speedtest.sh is at C:\Users\andre\Desktop and you run the script from folder C:\Users\andre
But where will the system find speedtest-cli and where should it write output.txt?

That is why in Linux you use something like:
/volume1/homes/admin/Speedtest/speedtest-cli --simple --server 5302 > ~/output.txt

Here it is obvious. The speedtest-cli is at location: /volume1/homes/admin/Speedtest/
The output.txt file is written in ~/ which means in Linux the user directory of the user who is running this script.

I suggest that you put the script speedtest.sh in the same folder as where you put the speedtest-cli and run the script from that location.
Lets see what happens but most likely you will have results.
Good luck.
Best regards Bert

Synology DS1517+ - DSM 6.2
Raspberry PI2-B, Raspberry Nano - Raspberry PI3 - model B
Xiaomi Gateway - Philips HUE Lights - Zwave - RFXCom(E) with KaKu and other 433MHz devices - Yeelight Lights - Toon
ilpier
Posts: 31
Joined: Friday 24 February 2017 12:01
Target OS: Windows
Domoticz version:
Contact:

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

Post by ilpier »

Thx @bertbidb,yes,i put .sh in the same folder of speedtest-cli and now,in the same folder i have output.txt with Ping,Download and Upload!
but in Domoticz nothing happen!
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests