Advice for integrating with legacy home automation system

Hi everyone.
I am looking for advice.
I want to integrate HA with a old legacy home automation system that is pre installed in my villa (no name brand). I have 100+ lights, ACs, curtains running on the system. After months of network sniffing and debugging, I think I have figured out how to communicate with the system. It supports TCP/IP, only udp protocol. Commands to turn devices on/off, set temp etc are done through udp calls passing various cryptic HEX values. I have figured that out and can implement it using command platform and making UDP calls from python scripts.

The bigger challenge is to get the state of the various devices (lights on/off, temperature etc). I can not query this through udp calls to pull data, but rather the legacy device broadcasts a udp message to the local network whenever a device status has changed. So I need to build some sort of UDP listener that listens to multicast and decodes the HEX messages and then feeds it into HA for the appropriate device. I have hacked together a simple python script that listens to udp broadcasts, decodes the messages and writes it to a file. And then I have a separate python script that reads from the file if queried. I run this on a separate machine as I could not figure out how to run a “always on” continuous loop udp listener server on my HA installation on my RPi.

Few thoughts

  1. How would you go about this?
  2. One idea I had is to build this as a small bridge that can covert from the legacy system to MQTT and then I could use the built in HA integrations from MQTT for climate, cover and lights?

Would love any thoughts on approach.

Thanks a million
Magnus

I think thats the way to go.
If you write the messages to a file, you can also publish them as mqtt messages.

Welcome to HA! :slightly_smiling_face:

Thanks for your response!

How would you build the “udp broadcast listener to MQTT translator”? Ideally I can run it on the same Rpi that I use for HA to avoid needing to have two separate devices.

Would I build this as a completely standalone app and run it independently from HA or can I build it as a custom integration or would it have to be an add on? I would love to get advice on how to best think about the overall structuring of this before jumping in and building it out.

Thanks

I suggest you consider using Node-Red (for easy installation, it’s available as an Add-on for Home Assistant). It has a UDP node (and MQTT).

1 Like

Thanks for the advice.
Two follow on questions.

  1. If I use node red to do the udp listening from the legacy system, can it access broadcast messages or are they blocked from inside the container that node red is running when installed as add in to HA on RPi?

  2. What is the preferred way to do an integration on the other side, ie between node red and HA itself. Is there an “internal” way to communicate given that node red would run as an add on to HA? Or would I still need to setup a proper “channel” between the two? If so, is Mqtt preferred or do you propose something else? I was thinking Mqtt as I found there are already integrations for light, cover, climate that handle mqtt, but maybe there are other even better options.

Just want to understand what might be best approach before I dig in.

Thanks

You shouldn’t have any problems if your legacy system communicates via a UDP port number greater than 1024.

Home Assistant provides its own set of nodes; you can execute Home Assistant service calls directly from Node-Red.