Create openhab.sh

Intergration in OpenHAB, a smart home software
This commit is contained in:
Motte001 2016-07-10 18:17:06 +02:00 committed by GitHub
parent 7b09d8759f
commit 1e11e6c587
1 changed files with 32 additions and 0 deletions

32
openhab.sh Normal file
View File

@ -0,0 +1,32 @@
#!/bin/bash
#
# Intergration in OpenHAB
#########
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd $DIR
# Check if connection is up
ping -c 1 duckduckgo.com > /dev/null
if [ $? -ne 0 ]
then
PING=0
DOWN=0
UP=0
else
# Check if a specific device is on, where you don't want high ping or slow connection (e. g. gaming or streaming)
ping -c 1 111.222.333.444 > /dev/null
if [ $? -eq 0 ]
then
exit
fi
data=$(./speedtest-cli --simple)
PING=$(echo $data | grep Ping | cut -d " " -f 2)
DOWN=$(echo $data | grep Download | cut -d " " -f 5)
UP=$(echo $data | grep Upload | cut -d " " -f 8)
fi
/usr/bin/curl -s --header "Content-Type: text/plain" --request POST --data $PING http://IP_OPENHAB:PORT/rest/items/INTERNET_PING
/usr/bin/curl -s --header "Content-Type: text/plain" --request POST --data $DOWN http://IP_OPENHAB:PORT/rest/items/INTERNET_DOWN
/usr/bin/curl -s --header "Content-Type: text/plain" --request POST --data $UP http://IP_OPENHAB:PORT/rest/items/INTERNET_UP