How to setup ESPHome to control my Bluetooth controlled (Octocontrol) bed

OK, Sorry I just saw this in the spec sheet.


so, it seems that you have the correct board configured. Do you like that board? It’s freaking tiny! I do like that it has built in IR transmitter and 6-GPIO’s isn’t bad for a board that small. You could put that in some pretty tight enclosures or hide it easier than most.

I did not do a auto detect, but asked around back then and maybe got the same screenshot you just posted and selected the pico32 board.

It’s probably OK. Most of the time it will throw error’s if they don’t match but, not always and then it will manifest problems during the build and cause a nightmare.

So, you said the light is working? Are these Switches controlling 2 lights? I don’t speak this language or know what "name: “Bed verlichting HdV” is but, I see the icon is a lightbulb…

switch:
  - platform: template
    name: "Bed verlichting HdV"
    id: bed_verlichting_hdv
    icon: "mdi:lightbulb-outline"

  - platform: template
    name: "Bed verlichting LdV"
    id: bed_verlichting_ldv
    icon: "mdi:lightbulb-outline"

Also, what exactly are these status sensor’s for? Are these the remotes that go to the bed’s? bed1 and bed2?

binary_sensor:
  - platform: template
    name: "Bed HdV remote connection status"
    id: bed_hdv_remote_connection_status

  - platform: template
    name: "Bed LdV remote connection status"
    id: bed_ldv_remote_connection_status

Those are indeed the bed lights. (Its in Dutch)
And the sensors are connected when the esp is connected to the bed.

Can you open the log output then turn a light On/Off then try a button other than the “head up” button. Post log after that.

where did you get the service_uuid and characteristic_uuid’s that you are using? Did they come from some one else’s config or did you find them yourself through the esphome BLE components?

The uuid’s came from the config of _pm stated above in this thread.
Im off to bed now, got to work early tomorrow.
Ill post the logging asap. Thnx sofar!

That’s what I figured. If you look a little closer at the top, there are 2 people who shared their configs and uuid’s. They aren’t the same at all. I realize that you used one of those configs above and your able to toggle the light On/Off but, that’s no guarantee all the other ones will be identical too. Other than that and some minor differences, you’re config is basically the same as the others and how you send a command to make the bed do an action, they are identical.

Here is you’re “feet up” action. The command to send a BT service out of your esp32. They’re basically identical except uuid’s and value.

- platform: template
    name: "Bed1 feet up"
    icon: "mdi:bed"
    on_press:
      - ble_client.ble_write:
          id: rc2bed1
          service_uuid: ffe0
          characteristic_uuid: ffe1
          # List of bytes to write.
          value: [0x40, 0x02, 0x70, 0x00, 0x01, 0x09, 0x04, 0x40]

Here is another person’s “feet up” action

- platform: template
    name: "Feet up"
    id: feet_up
    icon: "mdi:bed"
    on_press:
      - ble_client.ble_write:
          id: bed
          service_uuid: aa5c
          characteristic_uuid: 5a55
          value: [0x68, 0x30, 0x31, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x31, 0x30, 0x34, 0x31, 0x36, 0x16]

They’re all totally different except for your light.

Here is one person’s uuid’s and Hex values

All controls (head / feet / head/feet combined / lamp) all use:
[Service UUID: 0xffe0]
[UUID: 0xffe1]

Specific commands:
Head up	  : 40 02 70 00 01 0b 02 40
Head down : 40 02 71 00 01 0a 02 40
Both up	  : 40 02 70 00 01 07 06 40
Both down : 40 02 71 00 01 06 06 40
Foot up   : 40 02 70 00 01 09 04 40
Foot down : 40 02 71 00 01 08 04 40

When logging I see repeating the commands above, for as long as the button 
is pressed. After that I see the following command: 40 02 73 00 00 0b 40 
(which does stop movement I guess, even in shorter than 300ms period?)

Lamp control
ON   40 20 72 00 08 de 00 01 02 01 01 01 01 01 40
OFF: 40 20 72 00 08 df 00 01 02 01 01 01 01 00 40

And here’s the other one that is very different.

service_uuid: aa5c
characteristic_uuid: 5a55

Head up: 0x68, 0x30, 0x31, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x31, 0x30, 0x36, 0x31, 0x38, 0x16
Head down: 0x68, 0x30, 0x31, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x31, 0x30, 0x39, 0x31, 0x3b, 0x16
Feet up: 0x68, 0x30, 0x31, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x31, 0x30, 0x34, 0x31, 0x36, 0x16
Feet down: 0x68, 0x30, 0x31, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x31, 0x30, 0x37, 0x31, 0x39, 0x16
Both up: 0x68, 0x30, 0x31, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x31, 0x32, 0x37, 0x31, 0x3b, 0x16
Both down: 0x68, 0x30, 0x31, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x31, 0x32, 0x38, 0x31, 0x3c, 0x16

It appears you just have the wrong uuid’s and/or the wrong hex values and they don’t match what your BLE receiver is programmed to accept and therefore can’t command the bed to move.

One of the posts above, they were talking about how they got the uuid’s and values, as well as what phone app they used… I’d try doing that or asking them directly what the process is. Maybe just as easy, you can get all that with the esp32 by just removing the comment '#'s at the very top… All of this stuff that’s commented out.

 on_ble_advertise:
#    - mac_address: xx:xx:xx:xx:xx:xx
#      then:
#        - lambda: |-
#            ESP_LOGD("ble_adv", "New BLE device");

Then flash the board again. You may also need to increase your log level to VERBOSE or higher detail VERY_VERBOSE.

logger:
  level: VERBOSE

You need to do all that or use one of those other guy’s methods from above. Whichever way you choose, you will need to record the correct data for your bed/remote and then go through the your whole code and replace each one that is incorrect. Once you do that, then flash and test it again. I suspect this is your only or at least the main problem.

Here are some esphome documentation that will help you understand what’s going on.

It’s probably a long shot but, if you want to try it. I changed 2 of your button’s and replaced the uuid’s and values with one of the other guy’s BLE commands posted at the top. Just drop these 2 in the row of other button: entities. I renamed them and added “test” in the names to easily distinguish them in HA when you test them and if they need deleted later on, they’re easy to find.

  - platform: template
    name: "Bed1 Test head up"
    id: test_button_head_down
    icon: "mdi:bed"
    on_press:
      - repeat:
          count: 100
          then: 
            - ble_client.ble_write:
                id: rc2bed1
                service_uuid: aa5c
                characteristic_uuid: 5a55
                value: [0x68, 0x30, 0x31, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x31, 0x30, 0x36, 0x31, 0x38, 0x16]
            - delay: 300ms    
     
         
          
  
  
- platform: template
    name: "Bed1 Test head down"
    id: test_button_head_up
    icon: "mdi:bed"
    on_press:
      - repeat:
          count: 100
          then: 
            - ble_client.ble_write:
                id: rc2bed1
                service_uuid: aa5c
                characteristic_uuid: 5a55
                value: [0x68, 0x30, 0x31, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x31, 0x30, 0x39, 0x31, 0x3b, 0x16]     
            - delay: 300ms          

Sorry for the response delay, i ran in to the limit of responses in my first 24h…

Wow Thanks!
I did use BT HCI snooping on my phone when using the app to read the hex codes, but didnt realize that the uuid’s could be different aswell. Ill check if i can find the BT log, or try one of the options you stated. Dont know if this will be today, schedule is quite packed…

Morning!
I’ve tracked down the needle in the haystack (From the BT snooping log i did earlier), unfortunately the UUID’s are the same as i had in my config;

[Service UUID: Unknown (0xffe0)]
[UUID: Unknown (0xffe1)]

Could we still benefit from using the ble advertise logging, or will this show the same info that i got from the HCI BT snooping log?

Updated ESPHome to the latest version and redeployed the config to the ESP board.
In the logging i see the following;
[D][ble_client.automation:188]: Found characteristic 0xFFE1 on device E2:29:0A:3F:0F:0C

Nice to see another user of the code!

Did you try the very basic example on the last post by Falling? (But then with the info you got from your Bluetooth snooping, with only one bed). Does the bed respond for movement?
You did see the same hex codes as mine?

Tried the test buttons from Falling, but with no movement on the bed.
And i did snoop the BT logging, and got the same HEX and UUID’s as Peter.

I used this config for the test;

#BedControl
binary_sensor:
  - platform: template
    name: "Bed remote connection status"
    id: bed_remote_connection_status

ble_client:
  - mac_address: E2:29:0A:3F:0F:0C
    id: rc2bedhdv
    on_connect:
      then:
        - lambda: |-
            ESP_LOGD("ble_client_lambda", "Connected to BLE device");
        - binary_sensor.template.publish:
            id: bed_remote_connection_status
            state: True
    on_disconnect:
      then:
        - lambda: |-
            ESP_LOGD("ble_client_lambda", "Disconnected from BLE device");
        - binary_sensor.template.publish:
            id: bed_remote_connection_status
            state: False

switch:
  - platform: template
    name: "Bed verlichting hdv"
    id: bed_verlichting_hdv
    icon: "mdi:lightbulb-outline"
    optimistic: true
    turn_on_action:
      - ble_client.ble_write:
          id: rc2bedhdv
          service_uuid: ffe0
          characteristic_uuid: ffe1
          # List of bytes to write.
          value: [0x40, 0x20, 0x72, 0x00, 0x08, 0xde, 0x00, 0x01, 0x02, 0x01, 0x01, 0x01, 0x01, 0x01, 0x40]
    turn_off_action:
      - ble_client.ble_write:
          id: rc2bedhdv
          service_uuid: ffe0
          characteristic_uuid: ffe1
          # List of bytes to write.
          value: [0x40, 0x20, 0x72, 0x00, 0x08, 0xdf, 0x00, 0x01, 0x02, 0x01, 0x01, 0x01, 0x01, 0x00, 0x40]
button:
  - platform: template
    name: "Bed1 Test head down"
    id: test_button_head_down
    icon: "mdi:bed"
    on_press:
      - repeat:
          count: 100
          then: 
            - ble_client.ble_write:
                id: rc2bedhdv
                service_uuid: ffe0
                characteristic_uuid: ffe1
                value: [0x40, 0x02, 0x70, 0x00, 0x01, 0x0b, 0x02, 0x40]
            - delay: 300ms    
  - platform: template
    name: "Bed1 Test head up"
    id: test_button_head_up
    icon: "mdi:bed"
    on_press:
      - repeat:
          count: 100
          then: 
            - ble_client.ble_write:
                id: rc2bedhdv
                service_uuid: ffe0
                characteristic_uuid: ffe1
                value: [0x40, 0x02, 0x71, 0x00, 0x01, 0x0a, 0x02, 0x40]     
            - delay: 300ms 

This is the logging from the test;

[13:15:16][D][button:010]: 'Bed1 Test head up' Pressed.
[13:15:17][V][esp32_ble:342]: (BLE) gattc_event [esp_gatt_if: 4] - 4
[13:15:17][V][esp32_ble_client:121]: [0] [E2:29:0A:3F:0F:0C] gattc_event_handler: event=4 gattc_if=4
[13:15:17][D][esp32_ble_client:110]: [0] [E2:29:0A:3F:0F:0C] ESP_GATTC_WRITE_CHAR_EVT
[13:15:17][V][esp32_ble:342]: (BLE) gattc_event [esp_gatt_if: 4] - 4
[13:15:17][V][esp32_ble_client:121]: [0] [E2:29:0A:3F:0F:0C] gattc_event_handler: event=4 gattc_if=4
[13:15:17][D][esp32_ble_client:110]: [0] [E2:29:0A:3F:0F:0C] ESP_GATTC_WRITE_CHAR_EVT
[13:15:18][V][esp32_ble:342]: (BLE) gattc_event [esp_gatt_if: 4] - 4
[13:15:18][V][esp32_ble_client:121]: [0] [E2:29:0A:3F:0F:0C] gattc_event_handler: event=4 gattc_if=4
[13:15:18][D][esp32_ble_client:110]: [0] [E2:29:0A:3F:0F:0C] ESP_GATTC_WRITE_CHAR_EVT
[13:15:18][V][esp32_ble:342]: (BLE) gattc_event [esp_gatt_if: 4] - 4
[13:15:18][V][esp32_ble_client:121]: [0] [E2:29:0A:3F:0F:0C] gattc_event_handler: event=4 gattc_if=4
[13:15:18][D][esp32_ble_client:110]: [0] [E2:29:0A:3F:0F:0C] ESP_GATTC_WRITE_CHAR_EVT
[13:15:18][V][esp32_ble:314]: (BLE) gap_event_handler - 3
[13:15:18][V][esp32_ble:342]: (BLE) gattc_event [esp_gatt_if: 4] - 4
[13:15:18][V][esp32_ble_client:121]: [0] [E2:29:0A:3F:0F:0C] gattc_event_handler: event=4 gattc_if=4
[13:15:18][D][esp32_ble_client:110]: [0] [E2:29:0A:3F:0F:0C] ESP_GATTC_WRITE_CHAR_EVT
[13:15:18][V][esp32_ble:314]: (BLE) gap_event_handler - 3
[13:15:19][V][esp32_ble:342]: (BLE) gattc_event [esp_gatt_if: 4] - 4
[13:15:19][V][esp32_ble_client:121]: [0] [E2:29:0A:3F:0F:0C] gattc_event_handler: event=4 gattc_if=4
[13:15:19][D][esp32_ble_client:110]: [0] [E2:29:0A:3F:0F:0C] ESP_GATTC_WRITE_CHAR_EVT
[13:15:19][V][esp32_ble:342]: (BLE) gattc_event [esp_gatt_if: 4] - 4
[13:15:19][V][esp32_ble_client:121]: [0] [E2:29:0A:3F:0F:0C] gattc_event_handler: event=4 gattc_if=4
[13:15:19][D][esp32_ble_client:110]: [0] [E2:29:0A:3F:0F:0C] ESP_GATTC_WRITE_CHAR_EVT
[13:15:20][V][esp32_ble:342]: (BLE) gattc_event [esp_gatt_if: 4] - 4
[13:15:20][V][esp32_ble_client:121]: [0] [E2:29:0A:3F:0F:0C] gattc_event_handler: event=4 gattc_if=4
[13:15:20][D][esp32_ble_client:110]: [0] [E2:29:0A:3F:0F:0C] ESP_GATTC_WRITE_CHAR_EVT
[13:15:20][V][esp32_ble:342]: (BLE) gattc_event [esp_gatt_if: 4] - 4
[13:15:20][V][esp32_ble_client:121]: [0] [E2:29:0A:3F:0F:0C] gattc_event_handler: event=4 gattc_if=4
[13:15:20][D][esp32_ble_client:110]: [0] [E2:29:0A:3F:0F:0C] ESP_GATTC_WRITE_CHAR_EVT
[13:15:20][V][esp32_ble:342]: (BLE) gattc_event [esp_gatt_if: 4] - 4
[13:15:20][V][esp32_ble_client:121]: [0] [E2:29:0A:3F:0F:0C] gattc_event_handler: event=4 gattc_if=4
[13:15:20][D][esp32_ble_client:110]: [0] [E2:29:0A:3F:0F:0C] ESP_GATTC_WRITE_CHAR_EVT
[13:15:21][V][esp32_ble:342]: (BLE) gattc_event [esp_gatt_if: 4] - 4
[13:15:21][V][esp32_ble_client:121]: [0] [E2:29:0A:3F:0F:0C] gattc_event_handler: event=4 gattc_if=4
[13:15:21][D][esp32_ble_client:110]: [0] [E2:29:0A:3F:0F:0C] ESP_GATTC_WRITE_CHAR_EVT
[13:15:21][V][esp32_ble:314]: (BLE) gap_event_handler - 3
[13:15:21][V][esp32_ble:314]: (BLE) gap_event_handler - 3
[13:15:21][V][esp32_ble:342]: (BLE) gattc_event [esp_gatt_if: 4] - 4
[13:15:21][V][esp32_ble_client:121]: [0] [E2:29:0A:3F:0F:0C] gattc_event_handler: event=4 gattc_if=4
[13:15:21][D][esp32_ble_client:110]: [0] [E2:29:0A:3F:0F:0C] ESP_GATTC_WRITE_CHAR_EVT
[13:15:21][V][esp32_ble:314]: (BLE) gap_event_handler - 3
[13:15:22][V][esp32_ble:342]: (BLE) gattc_event [esp_gatt_if: 4] - 4

I’ve also retested the control of the bed light, this is still working. Logs;

[13:21:52][V][esp32_ble:314]: (BLE) gap_event_handler - 3
[13:21:53][D][switch:012]: 'Bed verlichting hdv' Turning ON.
[13:21:53][D][switch:055]: 'Bed verlichting hdv': Sending state ON
[13:21:53][V][esp32_ble:342]: (BLE) gattc_event [esp_gatt_if: 4] - 4
[13:21:53][V][esp32_ble_client:121]: [0] [E2:29:0A:3F:0F:0C] gattc_event_handler: event=4 gattc_if=4
[13:21:53][D][esp32_ble_client:110]: [0] [E2:29:0A:3F:0F:0C] ESP_GATTC_WRITE_CHAR_EVT
[13:21:55][V][esp32_ble:314]: (BLE) gap_event_handler - 3
[13:21:55][V][esp32_ble:314]: (BLE) gap_event_handler - 3
[13:21:56][V][esp32_ble:314]: (BLE) gap_event_handler - 3
[13:21:56][V][esp32_ble:314]: (BLE) gap_event_handler - 3
[13:21:56][V][esp32_ble:314]: (BLE) gap_event_handler - 3
[13:21:56][D][switch:016]: 'Bed verlichting hdv' Turning OFF.
[13:21:56][D][switch:055]: 'Bed verlichting hdv': Sending state OFF
[13:21:56][V][esp32_ble:342]: (BLE) gattc_event [esp_gatt_if: 4] - 4
[13:21:56][V][esp32_ble_client:121]: [0] [E2:29:0A:3F:0F:0C] gattc_event_handler: event=4 gattc_if=4
[13:21:56][D][esp32_ble_client:110]: [0] [E2:29:0A:3F:0F:0C] ESP_GATTC_WRITE_CHAR_EVT
[13:21:59][D][switch:012]: 'Bed verlichting hdv' Turning ON.
[13:21:59][D][switch:055]: 'Bed verlichting hdv': Sending state ON
[13:21:59][V][esp32_ble:342]: (BLE) gattc_event [esp_gatt_if: 4] - 4
[13:21:59][V][esp32_ble_client:121]: [0] [E2:29:0A:3F:0F:0C] gattc_event_handler: event=4 gattc_if=4
[13:21:59][D][esp32_ble_client:110]: [0] [E2:29:0A:3F:0F:0C] ESP_GATTC_WRITE_CHAR_EVT
[13:22:00][V][esp32_ble:314]: (BLE) gap_event_handler - 3
[13:22:00][V][esp32_ble:314]: (BLE) gap_event_handler - 3
[13:22:00][D][switch:016]: 'Bed verlichting hdv' Turning OFF.
[13:22:00][D][switch:055]: 'Bed verlichting hdv': Sending state OFF
[13:22:00][V][esp32_ble:342]: (BLE) gattc_event [esp_gatt_if: 4] - 4
[13:22:01][V][esp32_ble_client:121]: [0] [E2:29:0A:3F:0F:0C] gattc_event_handler: event=4 gattc_if=4
[13:22:01][D][esp32_ble_client:110]: [0] [E2:29:0A:3F:0F:0C] ESP_GATTC_WRITE_CHAR_EVT
[13:22:02][V][esp32_ble:314]: (BLE) gap_event_handler - 3
[13:22:03][V][esp32_ble:314]: (BLE) gap_event_handler - 3
[13:22:03][V][esp32_ble:314]: (BLE) gap_event_handler - 3
[13:22:03][V][esp32_ble:314]: (BLE) gap_event_handler - 3

Seems all fine, except I do not see the “Connected to BLE device” logging? Possibly it also works without, but I had this (when i initially created this, have not verified logging recently )

Will check this asap, not home right now.
Weird thing is, the lights are working properly…

Hoping someone is able to figure out what is wrong with my config. I’ve got an Okimat/Okin controller and I have been able to sniff the bluetooth traffic. I’ve created a macro in nRF Connect that turns the light on and off. It seems that turning it on and off are the same values. Below I am turning it on and off succesfully.

Attached the XML of the macro which I can succesfully use in nRF Connect to turn/off the light of the bed:

<macro name="Light" icon="LED_ON">
   <assert-service description="Ensure 62741523-52f9-8864-b1ab-3b3a8d65950b service" uuid="62741523-52f9-8864-b1ab-3b3a8d65950b">
      <assert-characteristic description="Ensure 62741525-52f9-8864-b1ab-3b3a8d65950b characteristic" uuid="62741525-52f9-8864-b1ab-3b3a8d65950b">
         <property name="WRITE" requirement="MANDATORY"/>
      </assert-characteristic>
      <assert-characteristic description="Ensure 62741625-52f9-8864-b1ab-3b3a8d65950b characteristic" uuid="62741625-52f9-8864-b1ab-3b3a8d65950b">
         <property name="NOTIFY" requirement="MANDATORY"/>
      </assert-characteristic>
   </assert-service>
   <write description="Write 0x040200020000 to 62741525-52f9-8864-b1ab-3b3a8d65950b" characteristic-uuid="62741525-52f9-8864-b1ab-3b3a8d65950b" service-uuid="62741523-52f9-8864-b1ab-3b3a8d65950b" value="040200020000" type="WRITE_REQUEST"/>
   <wait-for-notification description="Wait for notification to 62741625-52f9-8864-b1ab-3b3a8d65950b" characteristic-uuid="62741625-52f9-8864-b1ab-3b3a8d65950b" service-uuid="62741523-52f9-8864-b1ab-3b3a8d65950b">
      <assert-value description="Assert value equals 0x080B000200000402020000DFFFC202FFDFA884EF" value="080B000200000402020000DFFFC202FFDFA884EF"/>
   </wait-for-notification>
   <wait-for-notification description="Wait for notification to 62741625-52f9-8864-b1ab-3b3a8d65950b" characteristic-uuid="62741625-52f9-8864-b1ab-3b3a8d65950b" service-uuid="62741523-52f9-8864-b1ab-3b3a8d65950b">
      <assert-value description="Assert value equals 0x080B000200000402020000DFFFC202FFDFA884EF" value="080B000200000402020000DFFFC202FFDFA884EF"/>
   </wait-for-notification>
   <write description="Write 0x040200020000 to 62741525-52f9-8864-b1ab-3b3a8d65950b" characteristic-uuid="62741525-52f9-8864-b1ab-3b3a8d65950b" service-uuid="62741523-52f9-8864-b1ab-3b3a8d65950b" value="040200020000" type="WRITE_REQUEST"/>
   <wait-for-notification description="Wait for notification to 62741625-52f9-8864-b1ab-3b3a8d65950b" characteristic-uuid="62741625-52f9-8864-b1ab-3b3a8d65950b" service-uuid="62741523-52f9-8864-b1ab-3b3a8d65950b">
      <assert-value description="Assert value equals 0x080B000000000402020000DFFFC202FFDFA884EF" value="080B000000000402020000DFFFC202FFDFA884EF"/>
   </wait-for-notification>
   <wait-for-notification description="Wait for notification to 62741625-52f9-8864-b1ab-3b3a8d65950b" characteristic-uuid="62741625-52f9-8864-b1ab-3b3a8d65950b" service-uuid="62741523-52f9-8864-b1ab-3b3a8d65950b">
      <assert-value description="Assert value equals 0x080B000000000402020000DFFFC202FFDFA884EF" value="080B000000000402020000DFFFC202FFDFA884EF"/>
   </wait-for-notification>
</macro>

Now on to my ESPHome configuration:

esp32_ble_tracker:  
  on_ble_advertise:
    - mac_address:
        - D6:0F:22:57:42:83
      then:
        - lambda: |-
            ESP_LOGD("ble_adv", "New BLE device");
            ESP_LOGD("ble_adv", "  address: %s", x.address_str().c_str());
            ESP_LOGD("ble_adv", "  name: %s", x.get_name().c_str());
            ESP_LOGD("ble_adv", "  Advertised service UUIDs:");
            for (auto uuid : x.get_service_uuids()) {
                ESP_LOGD("ble_adv", "    - %s", uuid.to_string().c_str());
            }
            ESP_LOGD("ble_adv", "  Advertised service data:");
            for (auto data : x.get_service_datas()) {
                ESP_LOGD("ble_adv", "    - %s: (length %i)", data.uuid.to_string().c_str(), data.data.size());
            }
            ESP_LOGD("ble_adv", "  Advertised manufacturer data:");
            for (auto data : x.get_manufacturer_datas()) {
                ESP_LOGD("ble_adv", "    - %s: (length %i)", data.uuid.to_string().c_str(), data.data.size());
            }

binary_sensor:
  - platform: template
    name: "Bed Peter connection status"
    id: bed_peter_connection_status

ble_client:
  - mac_address: D6:0F:22:57:42:83
    id: bed_peter
    on_connect:
      then:
        - lambda: |-
            ESP_LOGD("ble_client_lambda", "Connected to BLE device");
        - binary_sensor.template.publish:
            id: bed_peter_connection_status
            state: True
    on_disconnect:
      then:
        - lambda: |-
            ESP_LOGD("ble_client_lambda", "Disconnected from BLE device");
        - binary_sensor.template.publish:
            id: bed_peter_connection_status
            state: False

switch:
  - platform: template
    name: "Bed verlichting Peter"
    id: bed_verlichting_peter
    icon: "mdi:lightbulb-outline"
    optimistic: true
    turn_on_action:
      - ble_client.ble_write:
          id: bed_peter
          service_uuid: 62741523-52f9-8864-b1ab-3b3a8d65950b
          characteristic_uuid: 62741525-52f9-8864-b1ab-3b3a8d65950b
          value: [0x04, 0x02, 0x00, 0x02, 0x00, 0x00]
    turn_off_action:
      - ble_client.ble_write:
          id: bed_peter
          service_uuid: 62741523-52f9-8864-b1ab-3b3a8d65950b
          characteristic_uuid: 62741525-52f9-8864-b1ab-3b3a8d65950b
          value: [0x04, 0x02, 0x00, 0x02, 0x00, 0x00]  

Whenever I turn the switch on/off, nothing happens with the bed. I do see a write request in the logs

[20:42:15][D][switch:012]: 'Bed verlichting Peter' Turning ON.
[20:42:15][D][switch:055]: 'Bed verlichting Peter': Sending state ON
[20:42:15][D][esp32_ble_client:110]: [3] [D6:0F:22:57:42:83] ESP_GATTC_WRITE_CHAR_EVT
[20:42:19][D][switch:016]: 'Bed verlichting Peter' Turning OFF.
[20:42:19][D][switch:055]: 'Bed verlichting Peter': Sending state OFF
[20:42:20][D][esp32_ble_client:110]: [3] [D6:0F:22:57:42:83] ESP_GATTC_WRITE_CHAR_EVT

My sensor says the bed is connected. Changing the service and characteristic UUID to something random says that it doesn’t exist, so I guess they are correct. Also based upon the XML earlier provided.

<write description="Write 0x040200020000 to 62741525-52f9-8864-b1ab-3b3a8d65950b" characteristic-uuid="62741525-52f9-8864-b1ab-3b3a8d65950b" service-uuid="62741523-52f9-8864-b1ab-3b3a8d65950b" value="040200020000" type="WRITE_REQUEST"/>

I’ve tried several things but currently I am stuck. Anyone has a clue?

Thanks!

I’ve compared my output to yours, the only difference I see:
My log:
[esp32_ble_client:110]: [0] [MAC…
Your log
[esp32_ble_client:110]: [3] [MAC…

I was not able to figure out what this number means though… If I ask ChatGPT it reports this number is the number of bytes written…??

Thanks for checking. No clue if this might be a problem. I also have requested chatGPT to validate my configuration based on the XML output etc etc. All seems to be good.

I found similar commands and UUIDs in this github repository: GitHub - richardhopton/smartbed-mqtt
So all seems to be good.

I keep on searching. Trying to determine what I can do to “log” or do anything related.

EDIT: According to my ChatGPT the [3] is the handle

In ESPHome, the handle ([3] in your logs) is not something you directly change or configure; it's an internal identifier used by the ESPHome framework to track multiple BLE clients. If you only have one BLE client configured, this handle is typically 0 or 1. When multiple BLE clients are defined, the handle increments accordingly.

Do you already have other Bluetooth connections active on this ESP? (if this description for the 3 is true, I would expect this to be 0 similar to my logging

Yeah I’ve got multiple. Just connected the second bed (also fails) and it has the number 4. Also in the connection state. So it’s an “easy” way to differentiate multiple device requests in the log.

Strange though that it’s [0] and [3] in your case.