Help with understanding code layout

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

Hey,

Did you end up anywhere with this? I think we’re using a similar kind of blind controller, mine is a Dooya OEM dd7002b (labeled Smart Home) and I managed to integrate the blinds into Home Assistant, but it’s a bit ugly, and could be improved in many ways. Found this thread by googling on some keywords from the “Connector WLAN Integration Protocol.pdf” which can be found on github by the way.

Anyway, I did not have patience to try to implement anything using this wifi method, but there is an rs485 port on the controller (an RJ9 connector), and using an RS485 to ethernet converter I was able to make contact with the brain of this controller finally. It didn’t take too long to find the command_line climate integration in HA and to find out some one liners which send the up/down/stop commands with netcat. I’m also not a programmer, but I created a script which - though fits my environment only - periodically pulls the blind positions from the controller. I have the so-called “Bi-Di” type of roller blind motors which send their position back to the controller/remote or even set the position or angle in 1% steps.

Since I don’t have experience in this, I only have ideas on how to do this, but can’t implement it myself. Since the controller is a bit lame, some kind of a daemon needs to be implemented that connects to the RS485 bridge on one socket, and opens another, to receive commands that it would queue. It should also update the position and store it somewhere. I think it would need a custom integration also to make use of the percentage-level position adjustment, as the command_line cover integration does not support that.

Let me know if this makes sense, not sure how many people could benefit from this, I can make some photos and write a few words on the RS485 to Ethernet bridge.

Daniel

LOL, I just found out that the Motion Blinds integration seamlessly works in HA.