Hi All,
First of all, i have to excuse for the lack of programming knowledge and experience in this field. I have a background as a industrial / robotic programmer so a lot of probably basic concepts i do not grasp (yet), but bear with me!
I have spent the past week reading the developers documentation to set up an environment on a linux VM and been grabbing parts from other projects to try and puzzle mine together and get an understanding of how everything goes together. I keep running into a lack of understanding how to implement things though.
To explain my intention:
I have Brel wireless window blind/cover motors which connect to wifi using a wifi-to-someWirelessProtocol hub. I wrote software to support them for Homey, and later OpenHAB. Now that im switching to Home Assistant im trying to code support for this too.
First of all some keypoints about the hub.
-
Autodiscover
The blind hub is auto discoverable by using a json “GetDeviceList” post to UPD multicast [238.0.0.18:32100]. A UDP unicast response “GetDeviceListAck” will be send back to the originating ip on the same port [HomeAssistantIp:32100] by each hub. I think i will need to implement a custom discovery solution for this? For now i just have a fixed manual entry in my config_flow.py which saves the hub IP and a AUTHkey. (works for now and the integration is created correctly) -
Getting attached blinds/covers
The “GetDeviceList” can allso be requested with a UDP UniCast [hubIp:32100]. A UDP unicast response “GetDeviceListAck” contains a JSON response with the hubs mac and the to the hub connected blinds/covers and their wireless MAC adresses. These MAC addresses are used as a unique identifier for further commands. -
Motion commands to a blind/cover
Motion commands can be send to a blind by sending a JSON “WriteDevice” post Post to UDP UniCast [hubIp:32100] or UDP MultiCast [238.0.0.18:32100] .This JSON contains the target position and mac address of the blind/cover we want to control. A UDP unicast response “WriteDeviceAck” is sent back immediately as a conformation. -
Status update after motion
After a motion is finished, the blind will send a JSON “Report” post to UDP MultiCast [238.0.0.18:32100] with its new position. -
Hub HeartBeat
The hub will occasionaly send a JSON “HeartBeat” post to UDP MultiCast [238.0.0.18:32100] with its mac and nr of devices (blinds).
My Idea
The init.py async_setup_entry is called for each created instance of my hub integration. The “hass.data[DOMAIN][entry.entry_id] = SomeClass(hass, entry)” allows me to bind a Class for each instance of a hub. This class will need to run a UDP listener subscribed to the multicast somehow to listen for broadcasts from hubs. A second UDP listener takes in responses directed at the HomeAssistant IP directly.
If the received message is a “HeartBeat” or “GetDeviceList” and the mac is this hub instance its mac, update the connected “cover” devices. If its a “WriteDeviceAck” or “Report” and the mac matches a blind under the hubs instance we update that “cover” device.
How to ?
Where do i implement a listening UDP socket per hub instance?
How does the creation of “cover” devices per hub instance exactly work?
I would really appreciate if anyone can point me in the correct direction with some pseudocode, a minimized exaple project or some poitners to a similar project i can look at to get a feel.
Kind regards!
Jordy