Bluetooth communication (specific protocol) with ESPHome?

Hi

I own a little flat garden that is controlable through a mobile app via Bluetooth Lilo Connect - Le jardin d'intérieur connecté, compact et intuitif - Prêt à Pousser 🇨🇭). I want to automate it through HA instead of not great manufacturer app.
I was thinking to use an ESP32 and pair it via bluetooth with the device and then be able to send the few commands I need at device through Bluetooth port. As far as I know Bluetooth once connected is like an UART (you send strings at device that answers with some strings back). I have found a Javascript that has already reverse-engineered the few commands handled by the Lilo (GitHub - jzarca01/assistant-lilo: Plugin pour LILO Pret a Pousser).
I have checked thoroughly ESPHome bluetooth documentation but I see nowhere a way to interact with a device once paired in Bluetooth. Is it not yet supported by ESPHome ?

Thanks for your help, explanations about best way to proceed there :wink:

Vincèn

Have a look at BLE Client — ESPHome

Thanks, will have a look at it although it doesn’t look very simple to implement :confused:

Just got myself my first esp32 and tinkered a bit. I didn’t wanna use the official app either and luckily I got it working after a while.

I’m sure this could be done much cleaner. I had to execute a command twice as a dirty fix since otherwise the light level jumps around to different values.

You can easily just use the scheduler card from HACS to automate on/off times for the device, that’s how I did it and it seems to work fine.

Just use any bluetooth scanner app to find the MAC address of your device and enter that below. Addresses and UIDs should be the same (hopefully). Brightness values go from 0 to 100 so you can just use a number card (I’m using the mushroom custom card) and set a value manually if needed.

Add it to your existing ESPHome devices config and hopefully it works for you too.

# Bluetooth LE component
esp32_ble_tracker:

ble_client:
  - mac_address: xx:xx:xx:xx:xx:xx
    id: lilo_connect
    auto_connect: true
    on_connect:
      then:
        - lambda: |-
            ESP_LOGD("ble_client_lambda", "Connected to BLE device");
    on_disconnect:
      then:
        - lambda: |-
            ESP_LOGD("ble_client_lambda", "Disconnected from BLE device");

switch:
  - platform: template
    name: "lilo_switch"
    id: template_switch
    optimistic: true
    turn_on_action:
      - ble_client.ble_write:
          id: lilo_connect
          service_uuid: C9D9BFE1-324C-4B79-BBAF-8A473E6540EC
          characteristic_uuid: C9D9BFE5-324C-4B79-BBAF-8A473E6540EC
          # bytes to write.
          value: [0x64]
    turn_off_action:
      - ble_client.ble_write:
          id: lilo_connect
          service_uuid: C9D9BFE1-324C-4B79-BBAF-8A473E6540EC
          characteristic_uuid: C9D9BFE5-324C-4B79-BBAF-8A473E6540EC
          # bytes to write.
          value: [0x00]

number:
  - platform: template
    name: "lilo_slider"
    id: lilo_slider
    optimistic: true
    min_value: 0
    max_value: 100
    step: 1
    mode: slider
    set_action:
      - ble_client.ble_write:
          id: lilo_connect
          service_uuid: C9D9BFE1-324C-4B79-BBAF-8A473E6540EC
          characteristic_uuid: C9D9BFE5-324C-4B79-BBAF-8A473E6540EC
          value: !lambda |-
              uint8_t value = id(lilo_slider).state;
              return {value};
      - delay: 200ms  # Adjust the delay duration as needed
      - ble_client.ble_write:
          id: lilo_connect
          service_uuid: C9D9BFE1-324C-4B79-BBAF-8A473E6540EC
          characteristic_uuid: C9D9BFE5-324C-4B79-BBAF-8A473E6540EC
          value: !lambda |-
              uint8_t value = id(lilo_slider).state;
              return {value};

@usercode0 thanks a lot for the share and I gave it a try here but it’s not working.
Each time I do something in HA I get that error in logs of ESP32:
[14:51:25][W][ble_client.automation:141]: Cannot write to BLE characteristic - not connected
and at boot when it tries to connect at device it lists these errors:

[14:53:04][W][ble_write_action:171]: Characteristic C9D9BFE5-324C-4B79-BBAF-8A473E6540EC was not found in service C9D9BFE1-324C-4B79-BBAF-8A473E6540EC
[14:53:04][W][ble_write_action:171]: Characteristic C9D9BFE5-324C-4B79-BBAF-8A473E6540EC was not found in service C9D9BFE1-324C-4B79-BBAF-8A473E6540EC
[14:53:04][W][ble_write_action:171]: Characteristic C9D9BFE5-324C-4B79-BBAF-8A473E6540EC was not found in service C9D9BFE1-324C-4B79-BBAF-8A473E6540EC
[14:53:04][W][ble_write_action:171]: Characteristic C9D9BFE5-324C-4B79-BBAF-8A473E6540EC was not found in service C9D9BFE1-324C-4B79-BBAF-8A473E6540EC

Any ideas what to do to get it working ? It looks to use different IDs no ? Mine is the original all metal bar with LEDS on it installed in a white plastic around !

I have the lilo connect model although the IDs might be different either way.

You can find the ID pretty easily using an app, I used "BLE Scanner (Connect & Notify) on Android. Just search for your device, connect to it and you should be able to find the service uuid.
There should be a main uuid at the top and a characteristic uuid. Usually it’s custom service and custom characteristic.
I just tried writing different values to different characteristics until the light came on. Select ‘Byte Array’ when writing values and use hex values like 00, 1B, 5A etc. 64 hex should be the maximum (100 in binary). Then update the uuids in the config and it should hopefully work.

Just to make sure I would check if 64 hex/100 binary is the maximum for your model too.

Hope it works.

@usercode0 Thanks a lot for the infos and I have found the good values I think but it’s very strange how it behaves.

First time I do a ON, the lilo goes on → off → on then off. If I push again it goes off and then that’s it ! I see in logs of ESP that it writes properly values in the device but device doesn’t react anymore till I power cycle the Lilo :frowning:
Got that issue too ?
Oki after doing a little of research on internet model I have doesn’t have dim capabilities but predefined mode for light:


            "01": "Photo mode",
            "02": "Spring",
            "03": "Summer"

So I replaced 64 by 03 and then all good :slight_smile:
Model I have is Lilo Connect and it uses these uuids:

service_uuid: 53E11631-B840-4B21-93CE-081726DDC739
characteristic_uuid: 53E11632-B840-4B21-93CE-081726DDC739

Oh that is interesting, that would explain the javascript implementation which I couldn’t make much sense of.
I assume maybe there is a different characteristic_uuid that directly controls the light and you picked a different one.
Otherwise it’s possibly just different hardware since I have the same model, although purchased very recently.

Either way, happy to see it works for you too :slight_smile:

1 Like