Page 2 of 2

Re: Sending data between Domoticz servers

Posted: Saturday 18 April 2020 18:00
by sailmich
I'll do my best :)

Re: Sending data between Domoticz servers

Posted: Saturday 18 April 2020 18:07
by ILoveIOT
Its just C programming, so not to hard :D :D

If you understand this a bit, the world is in you're hands, you can find many funtions/info for this on the internet.

I was learning C for the mpc23017 chip, and figured out I was doing C already 20+ years with bash ;)

Re: Sending data between Domoticz servers

Posted: Saturday 18 April 2020 18:54
by sailmich
@ILoveIOT You know I'm more a mechanical guy not the electrician :D With your fantastic help I finally got a result and it's working :o
Spoiler: show

Code: Select all

#!/bin/bash
# 
INFO="Sync between (IDX) Domoticz servers (different versions) by ILoveIOT @ 2020"
#
#
# use /root/scripts/domoticz.sync.device.servers.sh >> /dev/null 2>&1 in a cron job, every 1-5 min
# use /root/scripts/domoticz.sync.device.servers.sh on console so you see some output
#
# It can sync switches
#
#
#
#

# Setting the names or ip adresses of the Domoticz servers
SOURCEDOMOTICZIP="192.xxx.xxx.xx"	# your source ip here
TARGETDOMOTICZIP="192.xxx.xxx.xx"	# your target ip here

# Setting the port of the Domoticz servers
SOURCEDOMOTICZPORT="xxxx"		# your source port here
TARGETDOMOTICZPORT="xxxx"		# your target port here

# Domoticz IDX(s) to check, use : for separate, use source IDX and target IDX like 1-2 or 200-300 for example 1-2:200-300:67-234
# source idx is 1 and target idx is 2, source idx is 200 and target idx is 300, source idx is 67 and target idx is 234
#IDXTOCHECK=`echo -e "1-2:200-300:67-234"`
IDXTOCHECK=`echo -e "8-249:9-250:4-195:2-196"`



# Begin Script
#####################################################################################################################################
#####################################################################################################################################

clear
echo "$INFO" 
echo ""
echo "SOURCEDOMOTICZIP     = $SOURCEDOMOTICZIP with port $SOURCEDOMOTICZPORT"
echo "TARGETDOMOTICZIP     = $TARGETDOMOTICZIP with port $TARGETDOMOTICZPORT"
echo ""

# Do the loop for "IDXTOCHECK"
c=1
temps=`echo "$IDXTOCHECK" | /usr/bin/cut -f $c -d ":"`
while [ -n "$temps" ]; do

	IDXSOURCE=`echo "$temps" | /usr/bin/cut -d '-' -f1`
	IDXTARGET=`echo "$temps" | /usr/bin/cut -d '-' -f2 | /usr/bin/cut -d ':' -f1`

	# Get the domoticz value from a device, en cut the result
	VALUEIDXSOURCEDEVICE1=`curl -s 'http://'$SOURCEDOMOTICZIP':'$SOURCEDOMOTICZPORT'/json.htm?type=devices&rid='$IDXSOURCE'' | /bin/grep Data | /usr/bin/awk '{ print $3 }' | /bin/sed 's/,/ /g' | /usr/bin/tr -d '"'`
	VALUEIDXTARGETDEVICE=`curl -s 'http://'$TARGETDOMOTICZIP':'$TARGETDOMOTICZPORT'/json.htm?type=devices&rid='$IDXTARGET'' | /bin/grep Data | /usr/bin/awk '{ print $3 }' | /bin/sed 's/,/ /g' | /usr/bin/tr -d '"'`

	# Check  if value different
	if [ "$VALUEIDXTARGETDEVICE" != "$VALUEIDXSOURCEDEVICE1" ] ;then

	# Send the value to the target domoticz server
	curl -i -s 'http://'$TARGETDOMOTICZIP':'$TARGETDOMOTICZPORT'/json.htm?type=command&param=switchlight&idx='$IDXTARGET'&switchcmd='$VALUEIDXSOURCEDEVICE1'' >> /dev/null 2>&1
	fi
	# Just for debugging, you can comment this out if it works, or add >> /dev/null 2>&1
	echo ""
	echo "VALUEIDXSOURCEDEVICE1 = $VALUEIDXSOURCEDEVICE1"
	echo "VALUEIDXTARGETDEVICE = $VALUEIDXTARGETDEVICE"
	echo "IDXSOURCE             = $IDXSOURCE"
	echo "IDXTARGET             = $IDXTARGET"
	echo "IDXTOCHECK            = $temps"
	echo ""

# End the loop IDXTOCHECK
let c=$c+1
temps=`echo "$IDXTOCHECK" | cut -f $c -d ":"`
done

exit

#EOF
Thank you very much!

Re: Sending data between Domoticz servers

Posted: Saturday 18 April 2020 19:09
by ILoveIOT
:D YW, thanks for the upload, maybe others will need it too ;)

btw I was a big truck (Scania) mechanic in my early days, but I got black hands every day (you cant wash it off), and went to IT :D