Sending data between Domoticz servers

Moderator: leecollings

sailmich
Posts: 245
Joined: Wednesday 17 February 2016 22:55
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Germany
Contact:

Re: Sending data between Domoticz servers

Post by sailmich »

I'll do my best :)
User avatar
ILoveIOT
Posts: 59
Joined: Sunday 25 March 2018 17:47
Target OS: Linux
Domoticz version: 2020.2
Location: NL
Contact:

Re: Sending data between Domoticz servers

Post 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 ;)
1x OPI PC 5.8.16 Debian 10, MiniDNLA,SMD230,EpEver,MPD,800GB,Wiegand,7 temps,DHT,32/64 I/O,2022.1
2x OPI PC 4.19.25 Debian 9, MPD,7 temps,16/32 I/O,BMP,4.10717
1x IntelNUC 5.10 Debian 10, 2TB,DalyBMS,2023.1
3x ESPEasy NodeMCU V3, 16/16 I/O
sailmich
Posts: 245
Joined: Wednesday 17 February 2016 22:55
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Germany
Contact:

Re: Sending data between Domoticz servers

Post 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!
Last edited by sailmich on Monday 20 April 2020 16:08, edited 1 time in total.
User avatar
ILoveIOT
Posts: 59
Joined: Sunday 25 March 2018 17:47
Target OS: Linux
Domoticz version: 2020.2
Location: NL
Contact:

Re: Sending data between Domoticz servers

Post 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
1x OPI PC 5.8.16 Debian 10, MiniDNLA,SMD230,EpEver,MPD,800GB,Wiegand,7 temps,DHT,32/64 I/O,2022.1
2x OPI PC 4.19.25 Debian 9, MPD,7 temps,16/32 I/O,BMP,4.10717
1x IntelNUC 5.10 Debian 10, 2TB,DalyBMS,2023.1
3x ESPEasy NodeMCU V3, 16/16 I/O
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest