OpenWonderLabs / SwitchBotAPI-BLE

SwitchBot BLE open API
105 stars 10 forks source link

Lock BLE API #5

Open AdyRock opened 2 years ago

AdyRock commented 2 years ago

Current Situation

There is no BLE API documentation for the lock API except for the device id

Proposed Change

Add documentation for the Lock BLE API

Additional Context

It is desirable to integrate the lock into other home automation systems.

dsypniewski commented 1 year ago

@KiraPC while running the script it should create an app that handles those authentication URLs and removes it after the script exits. While the script is running you can check in the /Applications directory there should be switchbot URL handler.app.

KiraPC commented 1 year ago

Yes,

I did a little bit of reverse engineering and found.

Anyway it doesnโ€™t want works.

I also tried to pack an app with py2app that listen on url as yours.

It works if I call the app directly from the browser typing switchbot:// and works (I also started a listener for debugging) but not when is cognito to call the app.

Could you help me?

EDIT: after another test (whiteout changing anything) it worked. Anyway you need to fix the creation of the app because like as it now, it doesn't work

donavanbecker commented 1 year ago

@donavanbecker I pushed an update to the branch mentioned earlier that adds support for macOS and Windows could you check it out? This might require updating python3 to newer version because I had some problems with the default version provided by macOS.

Sorry @dsypniewski, been busy. sorry for not knowing much about python. Want to learn more about it, but how do I run the script? I have the zip downloaded and I tried to execute it using python3 switchbot_get_lock_key.py --web-auth XX:XX:XX:XX:XX:XX

but then I receive this:

Traceback (most recent call last):
  File "/Users/xxxxxx/xxxxxxxxxxx/pySwitchbot-lock-key-script-web-auth/scripts/switchbot_get_lock_key.py", line 6, in <module>
    import requests
ModuleNotFoundError: No module named 'requests'
dsypniewski commented 1 year ago

@KiraPC Do you have any ideas on how this could be improved? This is my first time working with an app for Mac.

@donavanbecker Sorry for the delay but I've also been busy recently - the script is not standalone and needs the pySwitchbot and other libraries installed to work so you need to install the package using pip:

pip install git+https://github.com/dsypniewski/pySwitchbot.git@lock-key-script-web-auth

If pip is not found or not working you might need to use pip3 instead. This will also install the script as executable, so there should be no need to use the downloaded one.

donavanbecker commented 1 year ago

No problems! and thanks @dsypniewski. I just get stuck here and receive this error when opening up the handler

Registering switchbot:// url handler
Opening auth page
Waiting for the auth response.
Screenshot 2023-01-27 at 11 41 43 PM
dsypniewski commented 1 year ago

@donavanbecker Hmm, this error message is not very helpful but there was one thing that I could think of and I pushed an update, could you check if that fixes your problem?

KiraPC commented 1 year ago

@donavanbecker Hmm, this error message is not very helpful but there was one thing that I could think of and I pushed an update, could you check if that fixes your problem?

This was the same error i had.

I pushed here the standalone application to be installed manually.

Try it and let me now.

@KiraPC Do you have any ideas on how this could be improved? This is my first time working with an app for Mac.

@dsypniewski Check my repository. The code is basically equals to yours, but it is standalone.

donavanbecker commented 1 year ago

@KiraPC when I run the commands, I get this:

The 'rumps' distribution was not found and is required by the application
KiraPC commented 1 year ago

@KiraPC when I run the commands, I get this:


The 'rumps' distribution was not found and is required by the application

Damn!

I stared from an old project, and I forget to remove a dependecy.

In setup.py file remove the "install_requires" line and check again if it compile.

I'm from my smartphone, tomorrow I'll fix on the repo.

donavanbecker commented 1 year ago

still getting:

ImportError: No module named 'rumps'

No rush, I can wait till tomorrow.

KiraPC commented 1 year ago

still getting:


ImportError: No module named 'rumps'

No rush, I can wait till tomorrow.

Mmm, I'll test it on a virtual environment tomorrow.

dsypniewski commented 1 year ago

@donavanbecker how about changes in my branch I mentioned earlier, does that work for you?

KiraPC commented 1 year ago

@donavanbecker fixed it. Should work now!

federicotravaini commented 1 year ago

Sorry to interrupt your conversation but maybe you can help with this related issue: https://github.com/home-assistant/home-assistant.io/issues/25859

KiraPC commented 1 year ago

Sorry to interrupt your conversation but maybe you can help with this related issue: home-assistant/home-assistant.io#25859

Hello @federicotravaini I'm using the switchbot Lock too. It's working fine.

I read the 3rd you posted and seems strange.

Could you report your system? Are you using a BLE adapter?

federicotravaini commented 1 year ago

Sorry to interrupt your conversation but maybe you can help with this related issue: home-assistant/home-assistant.io#25859

Hello @federicotravaini I'm using the switchbot Lock too. It's working fine.

I read the 3rd you posted and seems strange.

Could you report your system? Are you using a BLE adapter?

I am running HA in a VM on a Synology NAS DS920+. I have a BT usb adapter in the NAS that is in the basement (out of range) and an ESP32 bt proxy in the house, and a Shelly Plus with BT enabled (active mode). Everything works fine unless the BT lock that most of the times is not updated. Also, sometimes they became unavailable randomly and dont get back until I reload the switchbot integration.

I also had a switchbot HUB that I powered off and now back on cause didn't impact on the behaviour of the integration.

Will provide all the information you need.

KiraPC commented 1 year ago

Sorry to interrupt your conversation but maybe you can help with this related issue: home-assistant/home-assistant.io#25859

Hello @federicotravaini I'm using the switchbot Lock too. It's working fine. I read the 3rd you posted and seems strange. Could you report your system? Are you using a BLE adapter?

I am running HA in a VM on a Synology NAS DS920+. I have a BT usb adapter in the NAS that is in the basement (out of range) and an ESP32 bt proxy in the house, and a Shelly Plus with BT enabled (active mode). Everything works fine unless the BT lock that most of the times is not updated. Also, sometimes they became unavailable randomly and dont get back until I reload the switchbot integration.

I also had a switchbot HUB that I powered off and now back on cause didn't impact on the behaviour of the integration.

Will provide all the information you need.

Mmm. What firmware version is installed on the lock?

federicotravaini commented 1 year ago

Pretty sure it's the latest one, I checked a couple of days ago. Now I not at home and I can't check since it requires BT connection.

KiraPC commented 1 year ago

Pretty sure it's the latest one, I checked a couple of days ago. Now I not at home and I can't check since it requires BT connection.

It is not so sure.

The firmware is not delivered to all users togethers.

If you don't have the v6.5, ask to the support, they will send you it.

federicotravaini commented 1 year ago

Will check for sure tonight and let you know.

Now I am also using the web API to retrieve the door status (via the hub) and they work fine.

It's really weird, I hope it's not related to the ESP32...

KiraPC commented 1 year ago

Will check for sure tonight and let you know.

Now I am also using the web API to retrieve the door status (via the hub) and they work fine.

It's really weird, I hope it's not related to the ESP32...

I'm using a respberrypi 4pi with a usb doongle CSR and it works fine.

federicotravaini commented 1 year ago

Pretty sure it's the latest one, I checked a couple of days ago. Now I not at home and I can't check since it requires BT connection.

It is not so sure.

The firmware is not delivered to all users togethers.

If you don't have the v6.5, ask to the support, they will send you it.

I have version 6.4 holy moly No update available Will ask support...

KiraPC commented 1 year ago

Pretty sure it's the latest one, I checked a couple of days ago. Now I not at home and I can't check since it requires BT connection.

It is not so sure.

The firmware is not delivered to all users togethers.

If you don't have the v6.5, ask to the support, they will send you it.

I have version 6.4 holy moly No update available Will ask support...

Yes, ask for the V6.5. it should fix the sends update status.

Comunque, italiano anche io! ๐Ÿ˜‚

federicotravaini commented 1 year ago

Pretty sure it's the latest one, I checked a couple of days ago. Now I not at home and I can't check since it requires BT connection.

It is not so sure.

The firmware is not delivered to all users togethers.

If you don't have the v6.5, ask to the support, they will send you it.

I have version 6.4 holy moly No update available Will ask support...

Yes, ask for the V6.5. it should fix the sends update status.

Comunque, italiano anche io! ๐Ÿ˜‚

Ahah ottimo!

When I update I'll let you know if it fixed

donavanbecker commented 1 year ago

@KiraPC, yours worked.

@dsypniewski, yours worked when I used @KiraPC "switchbot.app" in the Applications Folder, but when I deleted that and tried again with the switchbot Url handler it didn't work and got the same error.

FYI: I did have to right click and Open the "switchbot.app" before @dsypniewski script would recognize that it is installed.

KiraPC commented 1 year ago

@KiraPC, yours worked.

Great!. You could think to link the repository and install the macos app externally.

federicotravaini commented 1 year ago

Pretty sure it's the latest one, I checked a couple of days ago. Now I not at home and I can't check since it requires BT connection.

It is not so sure. The firmware is not delivered to all users togethers. If you don't have the v6.5, ask to the support, they will send you it.

I have version 6.4 holy moly No update available Will ask support...

Yes, ask for the V6.5. it should fix the sends update status.

Comunque, italiano anche io! ๐Ÿ˜‚

After a couple of days with V6.5 I can confirm it works way better than before. Still happens sometimes that the device goes offline and I just need to reload the integration.

Grazie per la dritta!