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

Jumper3126
Posts: 105
Joined: Thursday 31 December 2015 15:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: monitor internet connection with virtual sensors

Post by Jumper3126 »

Derik wrote: Sunday 23 October 2016 20:05
safi78 wrote:backup, backup backup ;)

Anyway, you can always create a 'ram-drive' to redirect this stuff to? Saves you disk-trashing :)
Backup is not the problem....

Code: Select all

0 1 * * * sudo ~/domoticz/scripts/domoticz_backup.sh
5 1 * * 6 sudo ~/domoticz/scripts/scripts_backup.sh
10 1 * * 6 sudo ~/domoticz/scripts/domoticz_map_backup.sh
1 1 1 * * sudo ~/domoticz/scripts/raspberry_backup.sh
Only everytime the work/time...
And Domoticz is going so fast that i do not every time how anything is working..
1 person says to me... when you can hold your card clean why don;t you do that
Hi Derik
I'm curious what those 4 different scripts backup exactly. Feel to share them?
Derik
Posts: 1601
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

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

Post by Derik »

Code: Select all

#!/bin/bash

## LOCAL/FTP/SCP/MAIL PARAMETERS
    SERVER="192.168.5.10"         # IP of Network disk, used for: ftp mail scp
    USERNAME="root"         # FTP username of Network disk used for: ftp mail scp
    PASSWORD="root"               # FTP password of Network disk used for: ftp mail scp
    DESTDIR="/opt/backup"      # used for: local
    DOMO_IP="192.168.5.10"      # Domoticz IP used for all
    DOMO_PORT="8080"         # Domoticz port used for all
## END OF USER CONFIGURABLE PARAMETERS

    TIMESTAMP=`/bin/date +%Y%m%d%H`
    BACKUPFILEDIR="Xu4_Domoticz-map_$TIMESTAMP.tar.gz" # verander  domoticz_xx_  en je backup krijgt deze naam.
 
    ### Create backup and ZIP it
    tar -zcvf /tmp/$BACKUPFILEDIR /home/domoticz/
    
    ### Send to Network disk through FTP
    curl -s --disable-epsv -v -T"/tmp/$BACKUPFILEDIR" -u"$USERNAME:$PASSWORD" "ftp://$SERVER/media/hdd/Domoticz_backup/"
                                                    
    ### Remove temp backup file
    /bin/rm /tmp/$BACKUPFILEDIR

    ### Done!

Try this one with a cron like you see in your post :-)
Change the stuff you want..

When you have this the other are coming:-)
Xu4: Beta Extreme antenna RFXcomE,WU Fi Ping ip P1 Gen5 PVOutput Harmony HUE SolarmanPv OTG Winddelen Alive ESP Buienradar MySensors WOL Winddelen counting RPi: Beta SMAspot RFlinkTest Domoticz ...Different backups
matzeb74
Posts: 49
Joined: Sunday 07 January 2018 19:23
Target OS: Raspberry Pi / ODroid
Domoticz version: newest
Location: Stuttgart
Contact:

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

Post by matzeb74 »

For me it won´t work. Nothing to see in Domoticz. All shows 0.

In shell:

Code: Select all

domoticz@domoticz:~/scripts $ sudo ./speedtest.sh
ping = 33.913 ms
download = 23.22 Mbps
upload =  19.28 Mbps
My script in Folder /home/domoticz/scripts/

Code: Select all

#!/bin/bash

#setup
host=192.168.178.74
port=1883
username=******
password=*****
pingidx=34
downloadidx=35
uploadidx=36

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

So i see the script works. The output.txt is there, but all three Virtual Devices show 0.0 or 0
freijn
Posts: 536
Joined: Friday 23 December 2016 16:40
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: Netherlands Purmerend
Contact:

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

Post by freijn »

I guess in your script the username and passwords are not ******* ( just checking! )

Also, is the port correct?

try

Code: Select all

http://blabla:[email protected]:1883/json.htm?type=command&param=udevice&idx=34&svalue=100"
What happens?
matzeb74
Posts: 49
Joined: Sunday 07 January 2018 19:23
Target OS: Raspberry Pi / ODroid
Domoticz version: newest
Location: Stuttgart
Contact:

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

Post by matzeb74 »

Ah. Thank You. 1883 is the Port for mqtt. Now changed to the domoticz Port and it works. Many thanks!!!
rlschulz
Posts: 20
Joined: Sunday 25 October 2015 16:33
Target OS: Windows
Domoticz version: 3.5877
Contact:

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

Post by rlschulz »

I tried modify the script slightly to display my public IP. However domoticz seems to be seeing it as a decimal number and only displaying the first to octets. Is there a way to tell Domoticz to see the IP as text?

ip=$(curl -s https://api.ipify.org)

#output if you run it manually
echo "My public IP address is: $ip"
***.***.***.***
curl -s -i -H "Accept: application/json" "http://$username:$password@$host:$port/json.htm?type=command&param=udevice&idx=$ipidx&svalue=$ip"

The sensor displays ***.*** when you look in the current states is shows ***.**** which I am assuming means it saw this as a decimal number and rounded it to 4 digits.
User avatar
sincze
Posts: 1299
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Location: Netherlands / Breda Area
Contact:

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

Post by sincze »

Today I figured out why my speedtest-cli results were so low. Only around 90 MBIT.
Figures ofcourse If you only have a 100mbit raspberry. :D
I moved all to my Synology (1000 mbit port).

To achieve it.. Download:

Code: Select all

wget -O speedtest-cli https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py
chmod +x speedtest-cli
In addition I downloaded speedtest-csv (just lazy) from
https://github.com/HenrikBengtsson/spee ... master/bin
Also this script needs:

Code: Select all

chmod +x speedtest-csv
Speedtest-csv uses speedtest-cli.

After that just create a speedtest.sh file with the contents as shown below.
Also chmod +x speedtest.sh as well.

Code: Select all

#!/bin/sh

DOMO_IP="***.***.***.***"  # Domoticz IP Address
DOMO_PORT="8080"        # Domoticz Port
UPLOAD_IDX="***"        # Upload IDX
DOWNLOAD_IDX="***"      # Download IDX
PING_IDX="***"          # Ping IDX

# DO NOT MODIFIY PAST HERE !

input=$(/var/services/homes/yourhome/speedtest-csv --sep ',')

ping=$(echo $input | cut -f7 -d ',')
download=$(echo $input | cut -f8 -d ',')
upload=$(echo $input | cut -f9 -d ',')

if [ -z "$ping" ]; then
   echo "Empty Variable $ping"
else
   curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=udevice&idx=$PING_IDX&nvalue=0&svalue=$ping"
fi

if [ -z "$upload" ]; then
   echo "Empty Variable $upload"
else
   curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=udevice&idx=$UPLOAD_IDX&nvalue=0&svalue=$upload"
fi

if [ -z "$download" ]; then
   echo "Empty Variable $download"
else
  curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=udevice&idx=$DOWNLOAD_IDX&nvalue=0&svalue=$download"
fi
From the synology task scheduler you can execute the domoticz.sh every x time or so. Now my results look more for what I pay for. :lol:
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.
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 »

sincze wrote: Tuesday 30 January 2018 21:57 Today I figured out why my speedtest-cli results were so low. Only around 90 MBIT.
Figures ofcourse If you only have a 100mbit raspberry. :D
I moved all to my Synology (1000 mbit port).
Tnx working much better with the NAS indeed.

Made a adjustment because your script was missing the location of the script on the NAS so made that a bit more clear.

Code: Select all

#!/bin/sh
DOMO_IP="***.***.***.***""  # Domoticz IP Address
DOMO_PORT="xxxx"          # Domoticz Port
UPLOAD_IDX="xxxx"          # Upload IDX
DOWNLOAD_IDX="xxxx"     # Download IDX
PING_IDX="xxx"                 # Ping IDX

input=$(/var/services/homes/domoticz/speedtest/speedtest-csv --sep ',') #adjust this line to the right location were your put the script.

# DO NOT MODIFIY PAST HERE !

ping=$(echo $input | cut -f7 -d ',')
download=$(echo $input | cut -f8 -d ',')
upload=$(echo $input | cut -f9 -d ',')

if [ -z "$ping" ]; then
   echo "Empty Variable $ping"
else
   curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=udevice&idx=$PING_IDX&nvalue=0&svalue=$ping"
fi

if [ -z "$upload" ]; then
   echo "Empty Variable $upload"
else
   curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=udevice&idx=$UPLOAD_IDX&nvalue=0&svalue=$upload"
fi

if [ -z "$download" ]; then
   echo "Empty Variable $download"
else
  curl -s -i -H "Accept: application/json" "http://$DOMO_IP:$DOMO_PORT/json.htm?type=command&param=udevice&idx=$DOWNLOAD_IDX&nvalue=0&svalue=$download"
fi
Erwin92
Posts: 16
Joined: Saturday 26 November 2016 19:30
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post by Erwin92 »

Hi Guys,

I'm using this script for a long time at my Raspberry Pi, and It works really great!
At this moment I'm trying to setup Domoticz at my Synology NAS by Docker, I'm using a virtual linux machine to run the speedtest and script.

But there is something really strange, when I'm running the script only the ping value could send to Domoticz (running in Docker) the download and upload value couldn't? I double checked the IDX values, and also made a new virtual sensor with a new IDX but I still doesn't work.
When I change the script and send the values to my Domoticz running on a Raspberry every value will be updated, so the script and the speedtest are okay.

Could anyone help me with this problem?
mphilipp
Posts: 6
Joined: Thursday 29 December 2016 15:58
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Rotterdam, Netherlands
Contact:

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

Post by mphilipp »

Aparently, I'm the only one that runs Domoticz using SSL... :)
When it didn't work, I looked at the command to start the Domoticz daemon and noticed 'SSLWWW 443', so I tried the curl line on it's own on the command line, with the -v (verbose) switch and saw the 'connection refused' message in the output. When I tried https and port 443, I got a certificate error because it is self-signed. That can be fixed with the '--insecure' switch. So, I ended up with this line in the script:

Code: Select all

curl --insecure -s -i -H "Accept: application/json" "https://$username:$password@$host:$port/json.htm?type=command&param=udevice&idx=$pingidx&svalue=$ping"
I think about splitting the script up in two parts: one for the ping test and one for the bandwith test. The ping test is one that I 'd like to run more often and the bandwidth test can be run every 30 minutes or once an hour.

[edit]
Bugger...speedtest always runs all tests, so splitting up is useless. Ok, sofar for the splitting idea... :lol:

A bit later (when I have more time), I might try to run the speedtest on my router. I've got a Asus router with Merlin firmware which enables me to run custom scripts. Maybe even speedtest is available so I can run it on the router, which gives me the best indication of the true speed. I can write the output.txt on a shared location so Domoticz can pick it up. But that's for later...
roblom
Posts: 402
Joined: Wednesday 26 February 2014 15:28
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: the Netherlands
Contact:

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

Post by roblom »

I use this script on my Synology NAS and it works perfect. There is only one problem, when there is no internet connection the value in domoticz isn't updated to 0 but stays at the last value. Has somebody a solution for this?
User avatar
sincze
Posts: 1299
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Location: Netherlands / Breda Area
Contact:

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

Post by sincze »

Have a virtual switch or variable that contains the result of ping to 8.8.8.8. if you have a ping you have internet... If no ping.... Update sensors to 0 :)
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.
roblom
Posts: 402
Joined: Wednesday 26 February 2014 15:28
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: the Netherlands
Contact:

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

Post by roblom »

I've added a ping to the script.

Code: Select all

....
#Server to ping
test_ip="8.8.8.8"
test_count=1

if ping -c ${test_count} ${test_ip} > /dev/null; then
	echo "Online"
	speedtest-cli --simple --server $serverst > 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')
else
	echo "Offline"
	download=0
	upload=0
	png=0
fi
....
And in order to make the ping command work for non root users I ran in the command line of my synology:

Code: Select all

sudo chmod u+s `which ping`
Now when there is no reaction from the 8.8.8.8 the values are set to 0 and updated in domoticz.
User avatar
sincze
Posts: 1299
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Location: Netherlands / Breda Area
Contact:

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

Post by sincze »

Hahaha Nice you fixed it.
Nice job.
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.
alacran
Posts: 12
Joined: Tuesday 04 June 2019 11:32
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Contact:

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

Post by alacran »

Hello all,
just perform a refresh install for my domoticz.
Try to launch my test_internet.sh but I met some trouble.

output.txt is well created but I have got this error message and my devices are not update...
pi@raspberrypi:~/domoticz/scripts/Perso $ ./test_internet.sh
ping = 65.448 ms
download = 9.34 Mbps
upload = 1.39 Mbps
HTTP/1.1 401 Unauthorized
Content-Length: 91
Content-Type: text/html
Set-Cookie: DMZSID=none; HttpOnly; Expires=Thu, 01 Jan 1970 00:00:00 GMT

<html><head><title>Unauthorized</title></head><body><h1>401 Unauthorized</h1></body></html>HTTP/1.1 401 Unauthorized
Content-Length: 91
Content-Type: text/html
Set-Cookie: DMZSID=none; HttpOnly; Expires=Thu, 01 Jan 1970 00:00:00 GMT

<html><head><title>Unauthorized</title></head><body><h1>401 Unauthorized</h1></body></html>HTTP/1.1 401 Unauthorized
Content-Length: 91
Content-Type: text/html
Set-Cookie: DMZSID=none; HttpOnly; Expires=Thu, 01 Jan 1970 00:00:00 GMT

<html><head><title>Unauthorized</title></head><body><h1>401 Unauthorized</h1></body></html>pi@raspberrypi:
Have you got any ideas?
Thank you
User avatar
sincze
Posts: 1299
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Location: Netherlands / Breda Area
Contact:

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

Post by sincze »

Did you add 127.0.0.1 to your domoticz settings so local access is possible without username and password??
It seems updating your devices is the problem.

alacran wrote: Tuesday 04 June 2019 11:40 Hello all,
just perform a refresh install for my domoticz.
Try to launch my test_internet.sh but I met some trouble.

output.txt is well created but I have got this error message and my devices are not update...
pi@raspberrypi:~/domoticz/scripts/Perso $ ./test_internet.sh
ping = 65.448 ms
download = 9.34 Mbps
upload = 1.39 Mbps
HTTP/1.1 401 Unauthorized
Content-Length: 91
Content-Type: text/html
Set-Cookie: DMZSID=none; HttpOnly; Expires=Thu, 01 Jan 1970 00:00:00 GMT

<html><head><title>Unauthorized</title></head><body><h1>401 Unauthorized</h1></body></html>HTTP/1.1 401 Unauthorized
Content-Length: 91
Content-Type: text/html
Set-Cookie: DMZSID=none; HttpOnly; Expires=Thu, 01 Jan 1970 00:00:00 GMT

<html><head><title>Unauthorized</title></head><body><h1>401 Unauthorized</h1></body></html>HTTP/1.1 401 Unauthorized
Content-Length: 91
Content-Type: text/html
Set-Cookie: DMZSID=none; HttpOnly; Expires=Thu, 01 Jan 1970 00:00:00 GMT

<html><head><title>Unauthorized</title></head><body><h1>401 Unauthorized</h1></body></html>pi@raspberrypi:
Have you got any ideas?
Thank you
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.
alacran
Posts: 12
Joined: Tuesday 04 June 2019 11:32
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Contact:

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

Post by alacran »

Hello,
Thank you for your answer.

Yes, I already add 127.0.0.1 and 192.168.0.* with no autentication required.
With the "401 Unauthorized" error message, I thought about it.
But I add user and password information too in the .sh script, to test it.
Whitout success...
User avatar
sincze
Posts: 1299
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Location: Netherlands / Breda Area
Contact:

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

Post by sincze »

If you try to update your sensors via a browser (copy the filled url to the browser) same result ?? or does that work??
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.
alacran
Posts: 12
Joined: Tuesday 04 June 2019 11:32
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Contact:

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

Post by alacran »

OK...
Does not work with a browser.
Just a wrong password associate to a bad configuration...
I tried to restore an old backup.db file and all seemed to go wrong...

Issue solved.
Thank you
alacran
Posts: 12
Joined: Tuesday 04 June 2019 11:32
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Contact:

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

Post by alacran »

Hello

for an other script, I needed to update Python from 2.7 (if I remember well) to 3.4.4.
Since that, my speed_test.sh did not work.
When I trie to execute it, I've got this error message:
pi@Domoticz:~/domoticz/scripts/Perso $ ./test_internet.sh
Traceback (most recent call last):
File "/usr/bin/speedtest-cli", line 6, in <module>
from pkg_resources import load_entry_point
ImportError: No module named 'pkg_resources'
Is there a difference between Python version?
How can I solved it?

Thank you
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests