RS485 Serial bus Light platform integration

Hello,

I’m writing an integration for Biomatx, its a light control system. It’s made of hardware modules, a module holds 10 switches. Each switch toggle a light using a relay. The system is controlled by an RS485 serial connection where when a switch is pressed or released a 2 bytes packet is sent containing the module address (0 to 7), the switch address (0 to 9) and the switch state (released or pressed). I’m trying to design the API to control it to be used later in an integration and I was wondering how best to model this. The active part, toggling the switches is easy, I just need to write a packet to the serial so each switch writes to the bus. The passive part, where I need to read from the serial port to know when a switch has been pressed and update the state is where I’m stuck.

I have 3 modules, so in my integrations, I’ll have 30 entities. How am I supposed to update their state? Lets say I have an instance of this class:

class Bus:
    """This class is part of the API, not the integration"""

    async def toggle_switch(self, module_address, switch_address):
        packet = self.make_packet(module_address, switch_address) 
        await self.serial_port.async_write(packet)

    async def read_event(self):
        # The protocol is 2 bytes per packet
        packet = await self.serial_port.async_read(2)
        module_address, switch_address = self.parse_packet(packet)
        return module_address, switch_address

Each entity can have a reference to that Bus instance and call toggle_switch in their turn_on methods. So far so good. Now where do I call the read_event method and how do I dispatch the state updates to my entities ?

Hope this is clear enough, any help welcome!

The Serial sensor might be a good example on how to read serial data in a loop : serial/sensor.py

1 Like

Hello Damien, did you ever succeed in this endeavour ? I own 5 Biomatx controllers, inherited with the house I purchased several years ago, and would like to be able to integrate the relays with Home Assistant without having to redo the entire electricity panel with new equipment. With an IT background but no coding skills, I can’t see myself finding a solution on my own. Thanks ahead for any hint you might have.

Yes I actually did! I never published it but you’re the third person I see today with a biomatx and the need to fiddle with it :slight_smile:

I published the integration and started a thread:

Many thanks, Damien. I’ll look into this shortly. Exciting news !