I was able to get this all working! I’m not sure I’ve done it correctly or optimally though so caveat emptor.
I bought several Atom Lite devices (and curiously, though I think I followed the same installation steps, at least one of them identifies as arduino in the sense that there’s arduino references in its configuration - yet the others don’t). I have one of these set up as a Bluetooth proxy for my AC Infinity fan and that’s working. So I then set up another one using the esphome web page, to control my obscure and unknown Bluetooth device (it’s a fibre optic star ceiling controller). I then edited the configuration to include ble_client and the appropriate _write commands.
A while ago I’d used sniffers etc to watch how the included phone app talks to the device and identified the service and attributes and the values sent to it. I’d turned that into a single line script to turn it on:
$gatttool --adapter=BC:14:EF:62:4A:B3 -i hci0 -b FF:21:03:29:C8:09 --char-write-req -a 0x000a -n a5ff010602ffdba4003900ff05ff01ff010500aa
What doesn’t show up here though is the service and characteristic UUID that’s needed. In order to recall the service uuid and characteristic uuid I had to go back into Bluetoothctl and connect to the device. Once connected it then lists all the values found for the device.
I could then replicate this one-liner in the esp32 yaml:
ble_client:
- mac_address: FF:21:03:29:C8:09
id: YX_LED
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: "starceiling"
turn_on_action:
- ble_client.ble_write:
id: YX_LED
service_uuid: 0000ffb0-0000-1000-8000-00805f9b34fb
characteristic_uuid: 0000ffb1-0000-1000-8000-00805f9b34fb
value: [0xa5, 0xff, 0x01, 0x06, 0x02, 0xff, 0xdb, 0xa4, 0x00, 0x39, 0x00, 0xff, 0x05, 0xff, 0x01, 0xff, 0x01, 0x05, 0x00, 0xaa]
- ble_client.ble_write:
id: YX_LED
service_uuid: 0000ffb0-0000-1000-8000-00805f9b34fb
characteristic_uuid: 0000ffb1-0000-1000-8000-00805f9b34fb
value: [0xa5, 0xff, 0x01, 0x06, 0x02, 0xff, 0xdb, 0xa4, 0x00, 0x39, 0x00, 0xff, 0x05, 0xff, 0x01, 0xff, 0x01, 0x05, 0x00, 0xaa]
turn_off_action:
- ble_client.ble_write:
id: YX_LED
service_uuid: 0000ffb0-0000-1000-8000-00805f9b34fb
characteristic_uuid: 0000ffb1-0000-1000-8000-00805f9b34fb
value: [0xa5, 0x00, 0x01, 0x06, 0x02, 0xff, 0xdb, 0xa4, 0x00, 0x39, 0x00, 0xff, 0x05, 0xff, 0x01, 0xff, 0x01, 0x05, 0x00, 0xaa]
- ble_client.ble_write:
id: YX_LED
service_uuid: 0000ffb0-0000-1000-8000-00805f9b34fb
characteristic_uuid: 0000ffb1-0000-1000-8000-00805f9b34fb
value: [0xa5, 0x00, 0x01, 0x06, 0x02, 0xff, 0xdb, 0xa4, 0x00, 0x39, 0x00, 0xff, 0x05, 0xff, 0x01, 0xff, 0x01, 0x05, 0x00, 0xaa]
this creates a switch entity in HA - just on or off right now but it works. Usually. It’s always been a bit flaky connecting to the device so I’ve simply executed the gatttool commands twice (send the “on” or “off” command twice). So in the esp32 yaml I also repeat the command twice.