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
ESPHome as an ble gateway #34
Comments
Hi @manymuch Here is my solution for ESPHome
|
Looking forward to test this once implemented. My experience with bluetooth stick wasn't good but since I set up an ESPHome bluetooth proxy device I already had good experience with the HA SwitchBot integration. If the bluetooth proxy device could be used for turning my projector on as well this would be really cool. Thanks both! |
Maybe the SwitchBot integration can also serve as a reference regarding how to send bluetooth commands through ESP32 / ESPHome Bluetooth Proxy device: https://github.com/home-assistant/core/tree/dev/homeassistant/components/switchbot All references with "bluetooth": https://github.com/search?q=repo%3Ahome-assistant%2Fcore+path%3A%2F%5Ehomeassistant%5C%2Fcomponents%5C%2Fswitchbot%5C%2F%2F+bluetooth&type=code |
manufacturer_data_vector ??? |
@plesetsk Thanks for the solution. I slightly changed the snippet so that it does not block ESPHome due to delay in the lambda function, which causes the system to completely freeze. I also added a few iterations of how the original remote does it. Now the code works fine, even at a very large distance from the projector. esp32:
framework:
type: esp-idf
esp32_ble:
id: ble
esp32_ble_server:
button:
- platform: template
name: XGIMI Projector Wakeup
icon: "mdi:projector"
on_press:
- repeat:
count: 3
then:
- lambda: |-
std::vector<uint8_t> data = {0x46, 0x00, 0xe7, 0x12, 0x97, 0x30, 0x35, 0xf2, 0x78, 0xff, 0xff, 0xff, 0x30, 0x43, 0x52, 0x4b, 0x54, 0x4d};
id(ble).advertising_set_manufacturer_data(data);
- delay: 1s
- lambda: |-
std::vector<uint8_t> data = {0x46, 0x00};
id(ble).advertising_set_manufacturer_data(data);
- delay: 1s |
@Drafteed I have just tested your code in my environment and it works perfect. Thanks! |
Thank you! Do I understand it right that this code requires a dedicated ESP32 device which only serves for this command? The SwitchBot integration uses any ESP32 Bluetooth Proxy device set up in ESPHome and works for various BLE commands, so it acts like a bluetooth stick which is not limited to one command. I was just wondering if the advertising command could also be sent through the ESP32 Bluetooth Proxy device? Then the manufacturer code set in the XGIMI remote configuration could be used and no additional ESP32 device would be required. |
I don't know if it's possible to send advertising command through esp32:
framework:
type: esp-idf
# Enable BLE
esp32_ble:
id: ble
# Enable BLE Server
esp32_ble_server:
# Enable Bluetooth Proxy
bluetooth_proxy:
button:
- platform: template
name: XGIMI Projector Wakeup
icon: "mdi:projector"
on_press:
- repeat:
count: 3
then:
- lambda: |-
std::vector<uint8_t> data = {0x46, 0x00, 0xe7, 0x12, 0x97, 0x30, 0x35, 0xf2, 0x78, 0xff, 0xff, 0xff, 0x30, 0x43, 0x52, 0x4b, 0x54, 0x4d};
id(ble).advertising_set_manufacturer_data(data);
- delay: 1s
- lambda: |-
std::vector<uint8_t> data = {0x46, 0x00};
id(ble).advertising_set_manufacturer_data(data);
- delay: 1s |
@Drafteed Thank you for the great hint! It works indeed, I have now a working BT Proxy and the working wakeup command running on the same ESP device. Thank you again! |
It seems that instead of hard coding the advertising data it could also be provided e.g. by the XGIMI Remote integration, e.g.: https://community.home-assistant.io/t/how-to-pass-a-variable-from-home-assistant-front-end-to-esphome/183845/23 and https://schinckel.net/2021/01/24/esphome-variables-from-home-assistant/ I will certainly further look into this myself later, just wanted to also share this. |
Hi,
thanks for you code.
Since my HA installed on Hyper-v I have no access to bluetooth on the host.
I am trying to use ESPHome as a gateway for command but it seems that I have to configure it in the way to send ble advertise message.
I do not know how to do it.
May be some one can help me on this.
Thanks.
The text was updated successfully, but these errors were encountered: