Add 'Domoticz/SmartPinger.sh'
Added Smartpinger and implemented fix for Domoticz 2023.2 API calls. Before: type=devices After : type=command¶m=getdevices
This commit is contained in:
parent
208582dab1
commit
9a0099c662
87
Domoticz/SmartPinger.sh
Normal file
87
Domoticz/SmartPinger.sh
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
###############################
|
||||||
|
# @author: Bram Prieshof #
|
||||||
|
# @author: Branco van de Waal #
|
||||||
|
###############################
|
||||||
|
|
||||||
|
#echo $$ > /var/log/pid/Smartping-<DevName>.pid
|
||||||
|
|
||||||
|
# Set Parameters
|
||||||
|
Name='<DevName>'
|
||||||
|
domoticzserverip='127.0.0.1:8080'
|
||||||
|
IDX='<DomoIDX>'
|
||||||
|
IP='<DevStaticIP>'
|
||||||
|
bluetoothmac='<DevBTMac:>'
|
||||||
|
|
||||||
|
while [ 1 ]
|
||||||
|
do
|
||||||
|
# First network ping attempt
|
||||||
|
fping -c5 -b 32 -t1000 $IP > /dev/null 2>&1
|
||||||
|
if [ "$?" = 0 ] ; then
|
||||||
|
device="On"
|
||||||
|
technology="Online, Wifi 1"
|
||||||
|
success="yes"
|
||||||
|
else
|
||||||
|
success="no"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# First bluetooth ping attempt
|
||||||
|
if [[ $success != 'yes' ]]; then
|
||||||
|
bt1=$(l2ping -c5 -s32 -t1000 "$bluetoothmac" > /dev/null 2>&1 && echo "On" || echo "Off")
|
||||||
|
if [[ $bt1 == 'On' ]]; then
|
||||||
|
device="On"
|
||||||
|
technology="Online, Bluetooth 1"
|
||||||
|
success="yes"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Second network ping attempt
|
||||||
|
if [[ $success != 'yes' ]]; then
|
||||||
|
fping -c5 -b 32 -t1000 $IP > /dev/null 2>&1
|
||||||
|
if [ "$?" = 0 ] ; then
|
||||||
|
device="On"
|
||||||
|
technology="Online, Wifi 2"
|
||||||
|
success="yes"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Second bluetooth ping attempt
|
||||||
|
if [[ $success != 'yes' ]]; then
|
||||||
|
bt2=$(l2ping -c5 -s32 -t1000 "$bluetoothmac" > /dev/null 2>&1 && echo "On" || echo "Off")
|
||||||
|
if [[ $bt2 == 'On' ]]; then
|
||||||
|
device="On"
|
||||||
|
technology="Online, Bluetooth 2"
|
||||||
|
success="yes"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# If the device is still offline, declare it for processing
|
||||||
|
if [[ $success != 'yes' ]]; then
|
||||||
|
technology="Offline"
|
||||||
|
device="Off"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check Online / Offline state of Domoticz device
|
||||||
|
domoticzstatus=$(curl -s "http://"$domoticzserverip"/json.htm?type=command¶m=getdevices&rid="$IDX"" | grep '"Data" :' | awk '{ print $3 }' | sed 's/[!@#\$%",^&*()]//g')
|
||||||
|
CurTime=$(date '+%d/%m/%Y %H:%M');
|
||||||
|
# Compare ping result to Domoticz device status
|
||||||
|
if [ "$device" = "$domoticzstatus" ] ; then
|
||||||
|
echo "$CurTime | Device: $Name | Domo: Synced | Status: $technology"
|
||||||
|
else
|
||||||
|
#Domo status sync
|
||||||
|
if [ "$device" = On ] ; then
|
||||||
|
echo "$CurTime | Device: $Name | Domo: Desynced | Status: $technology"
|
||||||
|
curl -s "http://"$domoticzserverip"/json.htm?type=command¶m=switchlight&idx="$IDX"&switchcmd=On" 2>/dev/null 1>/dev/null
|
||||||
|
else
|
||||||
|
echo "$CurTime | Device: $Name | Domo: Desynced | Status: $technology"
|
||||||
|
curl -s "http://"$domoticzserverip"/json.htm?type=command¶m=switchlight&idx="$IDX"&switchcmd=Off" 2>/dev/null 1>/dev/null
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
#Waiting if Device is online
|
||||||
|
if [ "$device" = On ] ; then
|
||||||
|
echo "$CurTime | Device: $Name | Status: Online, Waiting"
|
||||||
|
sleep 60
|
||||||
|
fi
|
||||||
|
|
||||||
|
done
|
||||||
Loading…
x
Reference in New Issue
Block a user