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

LED BLE does not connects on Home Assistant but connects on ESPHome #105338

Open
distante opened this issue Dec 8, 2023 · 13 comments
Open

LED BLE does not connects on Home Assistant but connects on ESPHome #105338

distante opened this issue Dec 8, 2023 · 13 comments
Assignees

Comments

@distante
Copy link

distante commented Dec 8, 2023

The problem

(This is an update version of the stale #93671)

I am trying to connect a LED BLE device. For this, I configured an ESP32 dev board to work as a Bluetooth proxy.

The ESP32 part seems to be working as expected, it reports the devices.

Running the Add LED BLE integration part on Home assistant, I see the LED listed there, and I can trigger a connection.

When triggered, I see in the debug logs that the a connection is done successful:

21:56:05][I][bluetooth_proxy:278]: [0] [78:9C:E7:0D:33:4D] Connecting v3 with cache
[21:56:05][D][esp32_ble_tracker:215]: Pausing scan to make connection...
[21:56:05][I][esp32_ble_client:069]: [0] [78:9C:E7:0D:33:4D] 0x00 Attempting BLE connection
[21:56:06][I][esp32_ble_client:149]: [0] [78:9C:E7:0D:33:4D] Connected
[21:56:06][D][esp32_ble_tracker:266]: Starting scan...

But Home assistant fails
image

The log I see in HA is :

/usr/local/lib/python3.11/site-packages/led_ble/led_ble.py:347: FutureWarning: This method will be removed future version, use the services property instead. resolved = self._resolve_characteristics(await client.get_services())
21:56:06 – (ADVERTENCIA) components/led_ble/config_flow.py

in "All logs"

2023-12-08 21:52:53.452 WARNING (MainThread) [led_ble.led_ble] LEDBLE-0D334D: Device unexpectedly disconnected; RSSI: None
2023-12-08 21:56:06.023 WARNING (MainThread) [py.warnings] /usr/local/lib/python3.11/site-packages/led_ble/led_ble.py:347: FutureWarning: This method will be removed future version, use the services property instead.

What version of Home Assistant Core has the issue?

core-2023.12.0

What was the last working version of Home Assistant Core?

No idea

What type of installation are you running?

Home Assistant OS

Integration causing the issue

LED BLE

Link to integration documentation on our website

https://www.home-assistant.io/integrations/led_ble/

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

I have tried to do some reverse engineering to this BLE device sniffing the BT logs on my Android device while using the recommended app (https://play.google.com/store/apps/details?id=com.ledlamp) and I got some codes for it.

For example, this is the turn off code : 7eff0400ffffffffef
image

Then I connected my laptop directly to the device and tried to send those commands directly to the given FFE1 characteristic and it works as expected, I could turn it off, on, change some colors that I had sniffed before:
image

After some research I am 95% sure those codes are the same as the ones listed here https://github.com/kquinsland/JACKYLED-BLE-RGB-LED-Strip-controller/blob/master/Magic_numbers.md

And being used here with Java in https://github.com/kquinsland/JACKYLED-BLE-RGB-LED-Strip-controller/blob/master/files/src/main/java/com/karlquinsland/android/btleled/ControllerDriverClass.java

Maybe that can help for something?

Is there some way I can help with this? I have done 0 python but with some guidance I can try to implemented stuff if needed.

@home-assistant
Copy link

home-assistant bot commented Dec 8, 2023

Hey there @bdraco, mind taking a look at this issue as it has been labeled with an integration (led_ble) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of led_ble can trigger bot actions by commenting:

  • @home-assistant close Closes the issue.
  • @home-assistant rename Awesome new title Renames the issue.
  • @home-assistant reopen Reopen the issue.
  • @home-assistant unassign led_ble Removes the current integration label and assignees on the issue, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


led_ble documentation
led_ble source
(message by IssueLinks)

@stavroskool
Copy link

Have exactly the same issue. Recognized by ESP32 (Bluetooth board proxy) but LED BLE 0Dxxxx fails to connect

@distante
Copy link
Author

I have cloned home assistant core and blindly trying to debug what is happening.

There I get this error trace when the connection problem happens:

2023-12-13 21:01:57.144 ERROR (MainThread) [homeassistant.components.led_ble.config_flow] Unexpected error
Traceback (most recent call last):
  File "/workspaces/home-assistant-core/homeassistant/components/led_ble/config_flow.py", line 68, in async_step_user
    await led_ble.update()
  File "/home/vscode/.local/lib/python3.11/site-packages/led_ble/led_ble.py", line 150, in update
    await self._ensure_connected()
  File "/home/vscode/.local/lib/python3.11/site-packages/led_ble/led_ble.py", line 334, in _ensure_connected
    _LOGGER.log("%s: Connecting; RSSI: %s", self.name, self.rssi)
  File "/usr/local/lib/python3.11/logging/__init__.py", line 1555, in log
    raise TypeError("level must be an integer")
TypeError: level must be an integer

what I can update there is that the rssi is None. Of course, I have no idea for what that is used.

@distante
Copy link
Author

the client.connect call timesout...

@issue-triage-workflows
Copy link

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates.
Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍
This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

@8none1
Copy link

8none1 commented Mar 20, 2024

As far as I can tell these lights are not supported by flux_led. They don't have a corresponding protocol defined in here:

https://github.com/Danielhiversen/flux_led/blob/master/flux_led/protocol.py

i.e. there are no protocols defined which start 0x7e (in fact the string 7e doesn't appear anywhere in the protocol file).

If this is true then I expect that because these devices name themselves BLELEDxxxxxx the core integration expects them to be supported and then cannot actually talk to them.

If that is true, then the manifest file would need to be update to exclude these devices. https://developers.home-assistant.io/docs/creating_integration_manifest/#bluetooth

I don't see a mechanism to exclude devices though.

@8none1
Copy link

8none1 commented Mar 20, 2024

Ah, it looks like it's possible to exclude unsupported devices here:
https://github.com/home-assistant/core/blob/dev/homeassistant/components/led_ble/const.py

My device name is LEDBLE-01-9201.

I don't know how that differs from the supported device names, but perhaps the -01- would be enough to help?
It looks like it wouldn't help with OP's device though, but LEDBLE-0D might.

Are there any example device names from working LEDBLE devices?

@github-actions github-actions bot removed the stale label Mar 20, 2024
@8none1
Copy link

8none1 commented Mar 21, 2024

.. and the reason it fails to connect is because (on my device at least) the write characteristic is 0xffe1 but the core integration isn't expecting it to be at that address:

https://github.com/Bluetooth-Devices/led-ble/blob/28f06609c6c38232dcb25a0b813dc7929569aa0b/src/led_ble/const.py#L15

@dany547
Copy link

dany547 commented Apr 15, 2024

I have th.e same LEDBLE-01-9201 but for some reason it flailed to connect to Home Assistant . I guess it has something to do with the device ID?

`Logger: led_ble.led_ble
Source: runner.py:189
First occurred: 11:51:41 AM (15 occurrences)
Last logged: 11:54:31 AM

LEDBLE-01-9807: Device unexpectedly disconnected; RSSI: None`

@issue-triage-workflows
Copy link

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates.
Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍
This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

@distante
Copy link
Author

@bdraco Maybe this helps to fix the problem. IDK.

I ended up creating a virtual light.

on my esp32.ymal

substitutions:
  bluetooth_virtual_light_mac: THE:LBE:MAC:HERE

packages:
  bluetooth_virtual_light: !include common/bluetooth-virtual-light.yaml

common/bluetooth-virtual-light.yaml

esphome:
  includes: 
    - common/bluetooth-virtual-light.h

###############################
########## BLUETOOTH #########
#############################
# bluetooth_proxy:
#   active: true

      
# esp32_ble_tracker:
#   scan_parameters:
#     # We currently use the defaults to ensure Bluetooth
#     # can co-exist with WiFi In the future we may be able to
#     # enable the built-in coexistence logic in ESP-IDF
#     active: false

binary_sensor: 
  - platform: template
    name: "Led BLE Connected"
    id: led_ble_connected_sensor


ble_client:
  - mac_address: ${bluetooth_virtual_light_mac}
    id: led_strip_ble_client
    on_connect:
      then:
        - lambda: |-
            ESP_LOGD("virtual_ble_light", "Connected to BLE device");
        - binary_sensor.template.publish:
            id: led_ble_connected_sensor
            state: ON
        - switch.turn_off: led_ble_on_off_switch

    on_disconnect:
      then:
        - lambda: |-
            ESP_LOGD("virtual_ble_light", "Disconnected to BLE device");
        - binary_sensor.template.publish:
            id: led_ble_connected_sensor
            state: OFF

light:
  - platform: rgb
    id: rbg_led
    name: BLE LED
    red: red_channel_output
    green: green_channel_output
    blue: blue_channel_output
    default_transition_length: 0.25s
    on_state: 
      - lambda: |-
          ESP_LOGD("virtual_ble_light", "State Send");
    on_turn_on:
      - lambda: |-
          id(led_ble_on_off_switch).turn_on();
    on_turn_off:
      - lambda: |-
          id(led_ble_on_off_switch).turn_off();

output: 
  - platform: template
    id: red_channel_output
    type: float
    min_power: 0.003
    zero_means_zero: true
    write_action:
      - lambda: |-
            SSDBluetoothVirtualLight::updateRed(state);
            // char buf[30];
            // sprintf(buf, "red_channel_output=%.6f", state);
            // ESP_LOGI("virtual_ble_light", buf);
  - platform: template
    id: green_channel_output
    type: float
    min_power: 0.003
    zero_means_zero: true
    write_action:
      - lambda: |-
            SSDBluetoothVirtualLight::updateGreen(state);
            // char buf[30];
            // sprintf(buf, "green_channel_output=%.6f", state);
            // ESP_LOGI("virtual_ble_light", buf);
  - platform: template
    id: blue_channel_output
    type: float
    min_power: 0.003
    zero_means_zero: true
    write_action:
      - lambda: |-
            SSDBluetoothVirtualLight::updateBlue(state);
            // char buf[30];
            // sprintf(buf, "blue_channel_output=%.6f", state);
            // ESP_LOGI("virtual_ble_light", buf);
      - ble_client.ble_write:
          id: led_strip_ble_client
          service_uuid: FFE0
          characteristic_uuid: FFE1
          value: !lambda |- 
            return SSDBluetoothVirtualLight::getCreateColorUpdateArray();


switch:
  - platform: ble_client
    ble_client_id: led_strip_ble_client
    name: "Enable Bluetooth"
    internal: true

  - platform: template
    id: led_ble_on_off_switch
    name: "Turn On Led"
    internal: true
    restore_mode: ALWAYS_OFF
    turn_on_action:
      - ble_client.ble_write:
          id: led_strip_ble_client
          service_uuid: FFE0
          characteristic_uuid: FFE1
          value: !lambda |- 
            return SSDBluetoothVirtualLight::turnOnArray;

    turn_off_action:
      - ble_client.ble_write:
          id: led_strip_ble_client
          service_uuid: FFE0
          characteristic_uuid: FFE1
          value: !lambda |- 
            return SSDBluetoothVirtualLight::turnOffArray;
      - lambda: |-
            ESP_LOGD(SSDBluetoothVirtualLight::logTag, "SEND MESSAGE TO TURN OFF");

bluetooth-virtual-light.h

// #include <esphome.h>
#include <vector>
namespace SSDBluetoothVirtualLight {
  const char* logTag = "ssd_virtual_bluetooth_light";
  const std::vector<uint8_t> turnOffArray = {126, 255, 4, 0, 255, 255, 255, 255, 239};
  const std::vector<uint8_t> turnOnArray =  {126, 255, 4, 1, 255, 255, 255, 255, 239};
  const std::vector<uint8_t> noColorArray =  {126, 255, 5, 3, 0, 0, 0, 255, 239};

  float red = 0;
  float green = 0;
  float blue = 0;

    std::vector<uint8_t> getCreateColorUpdateArray()
    {
      
      uint8_t convertedRed = static_cast<uint8_t>(red * 255);
      uint8_t convertedGreen = static_cast<uint8_t>(green * 255);
      uint8_t convertedBlue = static_cast<uint8_t>(blue * 255);
      
      return {126, 255, 5, 3, convertedRed, convertedGreen, convertedBlue, 255, 239};
  }    
  
  

  void updateRed(float value){
    red = value;
  }
  
  void updateGreen(float value){
    green = value;
  }

  void updateBlue(float value){
    blue = value;
  }


}

@schitzo92
Copy link

Is this Problem actually fix?
i have the Same Problem and cant Connect

@schitzo92
Copy link

IMG_9349

cant Connect it with ledble
Need to Connect it with ledble led LAMP

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

No branches or pull requests

6 participants