Tutorial: How to use the Brennenstuhl GYW433 Gateway with Domoticz

Moderator: leecollings

Post Reply
thomasbaetge
Posts: 153
Joined: Wednesday 02 October 2019 11:47
Target OS: Linux
Domoticz version: 2023.1
Location: DE / BY / LT
Contact:

Tutorial: How to use the Brennenstuhl GYW433 Gateway with Domoticz

Post by thomasbaetge »

Hi All,

this forum has always been very helpful to me, so I thought I'd give something back and share my way of integrating the Brennenstuhl Gateway into Domoticz to control all those cheap 433Mhz switches that you can usually buy from Intertechno, Brennenstuhl and others for a rather small amount of money on Amazon or any DIY shop.


You need:
  • A Brennenstuhl or Connair 433MHz Gateway (OBVIOUSLY :D )
    A domoticz instance (this works for Raspberry PI as well as Synology, as long as Python runs on that machine)
    The 'Powerswitch' app (I'm using the Android Version, but I assume IOS will work too) https://play.google.com/store/apps/deta ... wer_switch
    A bit of time, depending on the amount of devices you got (I have more than 20)
Steps

Setup the Gateway and the application according to the instructions given (I will not cover that here, but it is very self explanatory in the app /manuals). Just make sure, you set a static IP adress for the gateway itself.

Add all your devices to the Powerswitch app and test if they are operating as expected

What the app actually does when you press a button to switch a device is something very simple: it transmits a UDP broadcast on (default) Port 49880 to the gateway, that contains a string, specific to the device and the desired operation. this string looks smth. like this:

TXP:0,0,10,5600,350,25,1,3,1,3,1,3,1,3,1,3,3,1,1,3,3,1,1,3,3,1,1,3,3,1,1,3,3,1,1,3,1,3,1,3,3,1,1,3,3,1,1,3,1,3,1,3,3,1,1,14;

Now what we need, are all these strings for all of your devices. There may be a few different ways to do so, this is just how I did it:
  • Get a computer where Netcat is installed (I used a PI, where it was already installed, but there's a windows version too)
    find this computers IP adress and note it
    go into the Powerswitch app, go to settings and change the gateway IP to the IP of your computer
    open a terminal on the computer and start a Netcat listener:

Code: Select all

nc -l -u -v 49880
now when you press a button to switch a device on the powerswitch app, the string (as above) will show up in the terminal window. Copy and paste into a text file and repeat this process for every device, once for ON, once for OFF operation.
If all goes well you end up with a long list of codes for your devices.

Probably you can do the very same with wireshark or any other sniffing tool. the main trick here is to redirect the app to a listening computer instead of the real gateway in order to capture the string.

Next you will need a script in Domoticz, that will use these codes.:

Code: Select all

#!/usr/bin/python

import socket
import sys

UDP_IP = "192.168.2.139"
UDP_PORT = 49880

MESSAGE = sys.argv[1]
 
b = bytes(MESSAGE)
 
sock = socket.socket(socket.AF_INET, # Internet
             socket.SOCK_DGRAM) # UDP

I = 1
while I <= 3:			 
	sock.sendto(b, (UDP_IP, UDP_PORT))
	I = I + 1
	
 
# close the socket
sock.close()
Please adjust the IP to the one of your Gateway.
You may notice, that every code is sent 3 times. this is due to the fact, that I find this protocoll sometimes a bit unreliable, as in it doesn't react on the first or second switch attempt. Depending on your environment, feel free to adjust this to your liking.

Put this script into your scripts folder (/home/pi/domoticz/scripts, if it is a PI) and make it executable.

Now we go to Domoticz:

simply create a virtual switch of each of your devices.

in the switches tab, edit these switches like in the picture
Image

So, all you need to do is to put into the on/off action fields:

Code: Select all

script:// <yourscriptname> <stringfortheaction>
I hope this helps ;)
Attachments
2020-04-08 152830.jpg
2020-04-08 152830.jpg (142.32 KiB) Viewed 1130 times
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest