Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lock BLE API #5

Open
AdyRock opened this issue Jun 11, 2022 · 77 comments
Open

Lock BLE API #5

AdyRock opened this issue Jun 11, 2022 · 77 comments
Labels
enhancement New feature or request pinned

Comments

@AdyRock
Copy link

AdyRock commented Jun 11, 2022

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.

@AdyRock AdyRock added the enhancement New feature or request label Jun 11, 2022
@github-actions github-actions bot added the stale label Jun 21, 2022
@Jacksonbm1
Copy link

I also think this would be a nice feature and probably shouldn't be closed as the BLE fix isn't available yet. I understand that it's not possible yet, but the issue shouldn't be closed IMO.

@kaxio
Copy link

kaxio commented Jul 12, 2022

Hey team, any updates on this?

@Jacksonbm1
Copy link

I saw a post in a live chat with a cofounder of switchbot that said the ble lock api is coming:

Here's the op:

"Hey. It's Richard here. I am one of the cofounders of
this little robot SwitchBot. I am more on sales and
marketing, but i also know how to code and play
around with JavaScript and Python myself. I have
around 160+ connected device, 20-30 scenes/
routines/automations or whatever you call it at my
place and most of them are in use, which means I
kinda know what smart home is. Also I use Alexa
most of the time at home and Siri when I am on my
phone. Just wanna say hi and if you guys have
anything you wanna tell me, just let me know. Would
like to interact with you guys more from now on. In
case i missed you comments, pin me again. I am
also on Twitter in case you wanna talk there too.
https://twitter.com/richardmou63/"

Here's the reply that says the lock api is coming:

"1. Lock API is definitely on its way. We gotta
test the security level before releasing and
there is no ETA yet."

Post: https://www.reddit.com/r/TrySwitchBot/comments/vzr3y6/first_post_hello_world/?utm_source=share&utm_medium=ios_app&utm_name=iossmf

@brandon-dacrib
Copy link

I don't understand. Why was this issue closed even though there is still no documentation on using the switchbot lock via BLE?

@Jacksonbm1
Copy link

It's listed as open for me? But I believe comments may re open it. Pretty sure GitHub auto closes issues that don't get updates and go stale

@martindinicolino
Copy link

with V1.1 of the API dropping about a week ago and bringing back the lock and unlock capability to the webAPI (which is awesome, thank you very much for that), is there any timetable in regards to this functionality being added to the bleAPI?

@Jacksonbm1
Copy link

Best way I can find is to message Richard Mou on twitter. He responds quickly

@r-glebov
Copy link

Looking forward for the BLE API support!

@martindinicolino
Copy link

Best way I can find is to message Richard Mou on twitter. He responds quickly

i‘m not on twitter, could somebody do that please?

@Minsheng
Copy link
Contributor

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.

This is Davidson from the dev team. We are working on the BLE API and we will update the BLE API doc hopefully in the next month. I myself will oversee the progress and keep you posted. Thanks a lot for being patient and supportive! You guys are the best!

@Jacksonbm1
Copy link

This is Davidson from the dev team. We are working on the BLE API and we will update the BLE API doc hopefully in the next month. I myself will oversee the progress and keep you posted. Thanks a lot for being patient and supportive! You guys are the best!

This is fantastic news! Out of curiosity, what features will the api include?

  • ability to lock/unlock
  • ability to read state of lock
  • ability to read state of door
  • ability to read state of battery

Best

@Minsheng
Copy link
Contributor

This is Davidson from the dev team. We are working on the BLE API and we will update the BLE API doc hopefully in the next month. I myself will oversee the progress and keep you posted. Thanks a lot for being patient and supportive! You guys are the best!

This is fantastic news! Out of curiosity, what features will the api include?

  • ability to lock/unlock
  • ability to read state of lock
  • ability to read state of door
  • ability to read state of battery

Best

We plan to support these triggers first,

  • ability to read state of lock
  • ability to read state of door
  • ability to read state of battery

The actions will have to come after.

Davidson

@marcomow
Copy link

awesome! @Minsheng do you have an estimated timeline for both reading and actions? Asking as our company is deciding which product to choose, so it may be worth to wait, but we need to understand how long. Thank you!

@sonny-chen
Copy link

This is fantastic news! Out of curiosity, what features will the api include?

  • ability to lock/unlock
  • ability to read state of lock
  • ability to read state of door
  • ability to read state of battery

Please also add the ability to set PIN. This will create a huge use case for vacation homes.

@Minsheng
Copy link
Contributor

awesome! @Minsheng do you have an estimated timeline for both reading and actions? Asking as our company is deciding which product to choose, so it may be worth to wait, but we need to understand how long. Thank you!

We have released the broadcast definition for Lock. The pull request is being reviewed atm.
We don't have a timeline for the implementation of Lock actions yet. Please stay tuned.

@martindinicolino
Copy link

martindinicolino commented Dec 10, 2022

great job, thank you for your work!
patiently waiting for the ability to lock and unlock to be added to the BLE API though 🤞

@federicotravaini
Copy link

Just goona buy in advance the lock waiting for this integration to be live asap 😃

@advorsky73
Copy link

Happy New Year ;) Any updates?

@donavanbecker
Copy link
Collaborator

@advorsky73 check this repo out: https://github.com/Danielhiversen/pySwitchbot

@advorsky73
Copy link

@donavanbecker thats for cloud api, how does this help for BLE ??? 🤔

@donavanbecker
Copy link
Collaborator

donavanbecker commented Jan 2, 2023

@advorsky73 pretty sure this is all BLE: https://github.com/dsypniewski/pySwitchbot/blob/ed46ac93e2c8985037e21f31e4bb7b933e17714f/switchbot/devices/lock.py

From this PR: sblibs/pySwitchbot#164

@slight316
Copy link

@dsypniewski I find myself with a little bit of spare time. Is there anyway that I can help with reverse engineering the keypad functionality? I don't have much experience in this department but if you can send me towards some articles or something I'm eager to learn.

@dsypniewski
Copy link

@slight316 As to sniffing bluetooth traffic I can recommend series of videos mentioned here https://hackaday.com/2021/03/23/a-crash-course-on-sniffing-bluetooth-low-energy/
This requires a dongle that allows sniffing Bluetooth - you can usually buy one pretty cheap on sites like AliExpress but I didn't want to wait so I made mine from nRF52840 dongle flashed with this https://www.nordicsemi.com/Products/Development-tools/nRF-Sniffer-for-Bluetooth-LE
What also helped a lot was looking through decompiled java code and string resources of the Android SwitchBot app, this article https://medium.com/helpshift-engineering/reverse-engineer-your-favorite-android-app-863a797042a6 seems to be using similar set of tools that I was using except the last step where I use fernflower.

@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.

@KiraPC
Copy link

KiraPC commented Jan 20, 2023

@slight316 As to sniffing bluetooth traffic I can recommend series of videos mentioned here https://hackaday.com/2021/03/23/a-crash-course-on-sniffing-bluetooth-low-energy/ This requires a dongle that allows sniffing Bluetooth - you can usually buy one pretty cheap on sites like AliExpress but I didn't want to wait so I made mine from nRF52840 dongle flashed with this https://www.nordicsemi.com/Products/Development-tools/nRF-Sniffer-for-Bluetooth-LE What also helped a lot was looking through decompiled java code and string resources of the Android SwitchBot app, this article https://medium.com/helpshift-engineering/reverse-engineer-your-favorite-android-app-863a797042a6 seems to be using similar set of tools that I was using except the last step where I use fernflower.

@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.

Hello @dsypniewski I'm trying to test the script on my mac, do I have to install the URL handler? because chrome can't found it.

@dsypniewski
Copy link

@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
Copy link

KiraPC commented Jan 20, 2023 via email

@donavanbecker
Copy link
Collaborator

donavanbecker commented Jan 20, 2023

@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
Copy link

@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
Copy link
Collaborator

donavanbecker commented Jan 28, 2023

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
Copy link

@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
Copy link

KiraPC commented Jan 29, 2023

@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
Copy link
Collaborator

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

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

@KiraPC
Copy link

KiraPC commented Jan 30, 2023

@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
Copy link
Collaborator

still getting:

ImportError: No module named 'rumps'

No rush, I can wait till tomorrow.

@KiraPC
Copy link

KiraPC commented Jan 30, 2023

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
Copy link

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

@KiraPC
Copy link

KiraPC commented Jan 31, 2023

@donavanbecker fixed it. Should work now!

@federicotravaini
Copy link

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

@KiraPC
Copy link

KiraPC commented Jan 31, 2023

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
Copy link

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
Copy link

KiraPC commented Jan 31, 2023

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
Copy link

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
Copy link

KiraPC commented Jan 31, 2023

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
Copy link

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
Copy link

KiraPC commented Jan 31, 2023

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
Copy link

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
Copy link

KiraPC commented Jan 31, 2023

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
Copy link

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
Copy link
Collaborator

donavanbecker commented Feb 1, 2023

@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
Copy link

KiraPC commented Feb 1, 2023

@KiraPC, yours worked.

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

@federicotravaini
Copy link

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request pinned
Projects
None yet
Development

No branches or pull requests