myhomeiot / esphome-components

A collection of my ESPHome components
Other
257 stars 25 forks source link

BLE Gateway Add config option to discover new devices #7

Closed ilarrain closed 2 years ago

ilarrain commented 2 years ago

Hello, any problems with the submitted code?

I've been using it without problems, and it works great, as my home assistant installation does not have inner Bluetooth working.

myhomeiot commented 2 years ago

@ilarrain Hello, thanks for PR and sorry for delay with a answer. As I understand your PR is trying to solve auto discovery problem of BLE Monitor and BLE Gateway when user don't know the device MAC address? You want to have ability to temporary allow to send all BLE packets from gateway to BLE Monitor? How you use this option, you configure BLE Monitor to discovery: true?

ilarrain commented 2 years ago

Yes, it just forwards all ble messages to home assistant's ble_monitor integration, with no mac address filter. Complementary to the integration's "discovery" option. https://custom-components.github.io/ble_monitor/configuration_params#discovery

Probably meant for temporary use, but actually I've just left it enabled on my esp32 devices, and the ble_monitor integration with no issues, other than airtags and other random ble beacons being regularly discovered.

myhomeiot commented 2 years ago

I'm also playing with such feature but on HA side, look for input_text.settings_ble_gateway_add_device (in my case user should know the BLE device MAC address, which can be gathered from ESPHome log). Probably will be better to have Discovery switch on the gateway which can be turned on/off without changing configuration. I will think more about it.

ilarrain commented 2 years ago

If I ever disable discovery, I'd probably just disable it on home assistant's side. Handling helpers to provide the device list to the component is a pain. I think parsing ble messages should be home assistant's job, IMHO. The overhead on the esp and the network is negligible.

myhomeiot commented 2 years ago

In my BLE environment (3 ESP BLE Gateways) if I allow to pass all BLE advertisement to BLE Monitor it's start eating 30-40% of system CPU (Intel Celeron)

bjeanes commented 2 years ago

I would also like this. I have set up input_text.settings_ble_gateway_add_device approach and use it. However, it is pretty tedious to setup multiple devices like this. You have to put just a handful of MACs in the input text at a time (due to max char limit of states) and wait for each of them to be seen by ESP32 before you can put in the next one.

Furthermore, especially with devices like Mijia temp sensors where the MAC address is not on the packaging, it takes many steps to on board new devices.

Ideally, simply flipping on discovery on the ESP32 (via an input_boolean in HA, for instance) until all devices are found, then optionally turn it off. If needed, I can clean up any devices that got erroneously detected.

ilarrain commented 2 years ago

In my BLE environment (3 ESP BLE Gateways) if I allow to pass all BLE advertisement to BLE Monitor it's start eating 30-40% of system CPU (Intel Celeron)

Not the case on my install. I run home assistant container in a raspberry pi 4, along with ~20 other docker containers. I have 2 esp32 forwarding all ble messages with the proposed patch, and I live in an apartment (more ble congestion). Screenshot_20220510-193033_Home Assistant.jpg

bjeanes commented 2 years ago

I just wanted to report that I switched to your fork @ilarrain and enabled discovery: true and was able to add a few more devices in mere moments.

I think this change is great and would only suggest the addition of an enable_discovery() or similar so that one could toggle it back and forth from an input_boolean in HA and avoid reflashing.

myhomeiot commented 2 years ago

Not the case on my install. I run home assistant container in a raspberry pi 4, along with ~20 other docker containers. I have 2 esp32 forwarding all ble messages with the proposed patch, and I live in an apartment (more ble congestion).

I tested my setup with latest version of Passive BLE Monitor and yes, the problem gone, probably it's was a problem with some older versions.

myhomeiot commented 2 years ago

@ilarrain @bjeanes I added global (input_boolean.settings_ble_gateway_discovery) and per device (switch switch_ble_gateway_discovery and discovery option in YAML) discovery options in latest release Please check and let's me know if it's working as expected. Thanks you for collaboration!

PS: Full examples you can find here

bjeanes commented 2 years ago

Awesome! Looks great :). I'll test it tomorrow or this weekend and let you know if I find any issues, but based on the diff, it looks like it should be fine.