renssies / homebridge-am43-blinds

A homebridge plugin to control the AM43 based blind motors in HomeKit
MIT License
18 stars 6 forks source link

Idea: Replace Blinds Engine Using Homebridge custom UI #26

Open neil-morrison44 opened 3 years ago

neil-morrison44 commented 3 years ago

Blind Engine's currently required for first time setup & fixing certain issues. Obviously this isn't great since you need to unpair the Pi / other homebridge device then launch Blind Engine & go through its pairing process again.

I was thinking instead the plug-in could expose a custom homebridge ui ( using https://github.com/homebridge/plugin-ui-utils ), which can sit alongside the current auto-generated schema UI.

This component would duplicate the Blind Engine features (first time setup, adjusting limits, setting reverse, passcode, etc) in combination with a server process which would use the existing BLE pairing on the device & send the BLE commands upon receiving requests from the UI.

As far as I can tell from those docs the UI could coexist with the auto-generated form since I don't think it really replaces any of that (except maybe adding a new device which we could support).

Hopefully moving more of the setup / maintenance inside this plugin would improve reliability (or at least understandability).

My skillset's more on the UI side than the reverse engineering BLE side so if anyone else was keen on writing the server that'd be good (I could document the API's I'd expect the UI to need etc).

This is assuming that the noble pairing in the main plugin process wouldn't lock out the server process from pairing, would need to find that out first.

renssies commented 3 years ago

It would be great to have some custom UI for this because the Blind Engine app sucks, to be honest.

However I'm not that good at reverse-engineering the BLE protocol used by the app, so If someone could help with that, that would be great. You could also check if someone else has already reverse engineered it for something like Domoticz, Node-red, or Home Assitant.

neil-morrison44 commented 3 years ago
Screenshot 2021-03-14 at 01 21 41

I've started to have a look at this, it's very early days at the moment - it doesn't do anything other than list them & the final thing probably shouldn't be called "Blind Engine".

I found this PDF which seems to be the most complete reverse engineering (at least that I've seen), but it's still missing things like changing the advertised name & factory resetting so I've ordered a BLE sniffer & we'll see how that goes..

From that PDF I should be able to get enable changing the direction & setting new minimum / maximum points at least

neil-morrison44 commented 3 years ago

Made some more progress on this, managed to get the BLE sniffer up and running & caught some requests (it misses most packets) for when the app was doing the renaming.

I couldn't get the requests sent from noble to change the name though, even though it was sending the exact same data. Luckily I managed to catch a packet going from the app to the motor & noticed it was a control code I've not seen anywhere yet, 0x17 & ~with a slightly different checksum method (haven't worked out what yet)~ & with my passcode as the data!

So it turns out the app does auth with the motor on connection and that's what locks off features like changing the name & probably changing the lower / upper limits, might even make other things (light sensor etc) work better if everything auths using it.

I'll need to change my UI a bit to ask for the passcode - we might want to include it in the schema if it improves non-config features but I don't know if it does yet