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

Added parse_data service #572

Merged
merged 1 commit into from
Dec 3, 2021
Merged

Added parse_data service #572

merged 1 commit into from
Dec 3, 2021

Conversation

myhomeiot
Copy link
Collaborator

Send RAW HCI packet data to the BLE Montitor integration, used by ESPHome BLE Gateway

We discussed this here

This code tested and fully working but I will be glad if you take a look into async_parse_data_service function and change it as you think it's should be.

Thanks in advance!

PS: You can also add user permission check for service calls to prevent regular users calling services, by changing

    hass.services.async_register(
        DOMAIN,
        SERVICE_CLEANUP_ENTRIES,
        service_cleanup_entries,
        schema=SERVICE_CLEANUP_ENTRIES_SCHEMA,
    )

to

    platform = entity_platform.async_get_current_platform()
    platform.async_register_entity_service(
        SERVICE_CLEANUP_ENTRIES,
        SERVICE_CLEANUP_ENTRIES_SCHEMA,
        "async_cleanup_entries_service"
    )

As example in my integration I did it in this commit

Send RAW HCI packet data to the BLE Montitor integration, used by ESPHome [BLE Gateway](https://github.com/myhomeiot/esphome-components#ble-gateway)
@Ernst79
Copy link
Collaborator

Ernst79 commented Dec 3, 2021

Nice work, I will try to test is a.s.a.p. If I understand it correct, you use an ESPHome device to receive BLE messages and than broadcast the same data again? So it is working as some kind of "range extender".

Just curious, what is the benefit of this, ESPHome is also capable of processing this data to ESPHome sensors, isn't it? One of the advantage I can think of myself, BLE monitor is supporting more sensors. than ESP Home. But are there other advantages?.

I'll look into the user permission check, thanks.

@Magalex2x14
Copy link
Collaborator

Magalex2x14 commented Dec 3, 2021

ESPhome device receives BLE advertisement, and without further processing sends it via the local network (WiFi) to HomeAssistant, where ble_monitor parses it. Cool solution! For example, in this way, you cannot have a bluetooth interface at all on the HA host, but catch the data with ESP32 boards scattered around the rooms.

@myhomeiot
Copy link
Collaborator Author

Nice work, I will try to test is a.s.a.p. If I understand it correct, you use an ESPHome device to receive BLE messages and than broadcast the same data again? So it is working as some kind of "range extender".

Just curious, what is the benefit of this, ESPHome is also capable of processing this data to ESPHome sensors, isn't it? One of the advantage I can think of myself, BLE monitor is supporting more sensors. than ESP Home. But are there other advantages?.

I'll look into the user permission check, thanks.

It's not urgent at all, so take your time ;-) Most users which want to test it and use already did it manually with this PR.
I forget to tell you in previous message, please also change the service name, etc if needed, I will change everything accordingly.

Yes, I use ESPHome devices to receive BLE messages, add HCI header and send it by WiFi to Home Assistant and your integration.

Yes, ESPHome can process BLE messages but has a limited devices support. Unload BLE processing to external component helps to free the ESP memory. BLE stack in ESPHome use relatively huge amount of RAM and sometimes if you have on top of BLE stack 10-15 BLE sensors components its start reboot spontaneously. BLE Gateway it's a one components with low code and memory footprint which process data from all sensors.

Sure in the case when ESP, for example, control the heater for reliability you should have temperature reading on board and this is not a solution. But in case when your heater connected to Home Assistant or in case when you just need extend BLE coverage it's a better solution.

But, for my opinion the main pain with regular ESPHome BLE sensors components (why I create BLE Gateway component) that if you have BLE device which moves from area to area you should have BLE sensor component for this device at the all ESPHome devices. In this case in Home Assistant you will have all these sensors entities from all ESPHome devices :-)
With BLE Gateway I can have one package yaml (like in Home Assistant) with BLE Gateway configuration and all my BLE devices macs, which I can include into all my ESPHome devices configurations and forget about this problem ;-)

@myhomeiot
Copy link
Collaborator Author

ESPhome device receives BLE advertisement, and without further processing sends it via the local network (WiFi) to HomeAssistant, where ble_monitor parses it. Cool solution! For example, in this way, you cannot have a bluetooth interface at all on the HA host, but catch the data with ESP32 boards scattered around the rooms.

Exactly ;-)

@Ernst79
Copy link
Collaborator

Ernst79 commented Dec 3, 2021

I tried to add your suggestion about the user permission check, But I get the following error. Most likely, as we have defined in in async_setup, while your example has it in async_setup_platform.

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/setup.py", line 254, in _async_setup_component
    result = await task
  File "/config/custom_components/ble_monitor/__init__.py", line 191, in async_setup
    platform = entity_platform.async_get_current_platform()
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 740, in async_get_current_platform
    raise RuntimeError("Cannot get non-set current platform")
RuntimeError: Cannot get non-set current platform

@Ernst79
Copy link
Collaborator

Ernst79 commented Dec 3, 2021

Tested the example, works perfect. device is added as expected

image

I do think that we need to add some documentation for this new feature. I'll merge this part and create a page in the docs. May I ask you to fill this page?

@Ernst79 Ernst79 merged commit 8edccce into custom-components:master Dec 3, 2021
@Ernst79
Copy link
Collaborator

Ernst79 commented Dec 3, 2021

I added the page here,

https://custom-components.github.io/ble_monitor/parse_data

Could you check if you want some more info?

I have an issue with the automation example, to put it in the docs, the jekyll docs are hiding everything between double {{ xxx }}, so the example (last line with packet) isn't correct. Not sure how to fix this,

@myhomeiot
Copy link
Collaborator Author

I tried to add your suggestion about the user permission check, But I get the following error. Most likely, as we have defined in in async_setup, while your example has it in async_setup_platform.

I will try to implement this and will make PR.

I do think that we need to add some documentation for this new feature. I'll merge this part and create a page in the docs. May I ask you to fill this page?

I can try, if you make small sketch with list of points which you think should be explained.

@Ernst79
Copy link
Collaborator

Ernst79 commented Dec 3, 2021

I already made a first start of the page, I think the page should explain what the service does and how it can be used. I would only explain the BLE monitor side here, and provide some links to your ESPHome BLE gateway.

You can just edit the page here
https://github.com/custom-components/ble_monitor/blob/master/docs/parse_data.md

The final result is displayed here, about a minute after you upload changes.
https://custom-components.github.io/ble_monitor/parse_data

@myhomeiot
Copy link
Collaborator Author

I tried to add your suggestion about the user permission check, But I get the following error. Most likely, as we have defined in in async_setup, while your example has it in async_setup_platform.

Yes, it's look more challenged and requires lot of changes. If you like Nabucasa way and when you have the inspiration to do refactoring you can do it as they suggest.
Currently not many peoples aware and use Home Assistant user permissions, so it's definitely can wait ;-)

Thanks you for your work!

@Ernst79
Copy link
Collaborator

Ernst79 commented Dec 5, 2021

6.2.0 has been released

@myhomeiot
Copy link
Collaborator Author

6.2.0 has been released

Thanks you!
I added the way when ESPHome devices will get MAC addresses directly from BLE Monitor configuration, so it's will make the configuration even simpler.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants