Any suggestion/good template for a bluetooth accessory? (for rewriting Switchmate component)

I’m planning on a proper rewrite of the Switchmate integration. The original implementation is buggy: It only turns the light on/off 50% successfully of the time, it does not reliably read out the current status of the switch if manually switched, and it sometimes makes my entire home assistant instance stuck.

I wonder if there is an example of a good Bluetooth component in Bluetooth?

In particular, I wonder how to handle the following stuff:

  1. I need to scan for Bluetooth beacon to update the current status of the switch. How can I do it so that it’s not in conflict with other components that also want to do Bluetooth scan?
  2. I need to connect to the device when I want to flip the switch. Should I connect every time and disconnect afterward? Or I should keep the connection open just in case a second command comes? Also, how to make this work with asyncio?
  3. For connect, similar to all BLE devices, the connect command may fail. It could be because a poor wireless environment or other devices is current connected to the switch. How can I keep trying to establish the connection without stuck the entire home assistant process?

For the reference, Switchmate is a smart switch roughly work like this:

  1. It always broadcast a beacon with one bit indicating whether it’s current status (on/off).
  2. If the user wants to control this switch, the system needs to first connect to the switch, write a value to a Bluetooth attribute, then the switch will toggle.

Thanks!

1 Like

I would be willing to help you with this. I was looking into the GitHub repos last night, getting my sea legs and trying to find an example of a BTLE devices.

@jackieyang9

I made a custom component which integrates with the Switchmate Power outlets as well. It was working on my existing system (HA standalone, not Hassio). I am currently upgrading my system to HA on a docker image and plan to get these implemented again. I’d be glad to help out as well.

-Rey

Did anything ever happen with this thread?