ESPHome BLE Keyboard

It is strange that the Dmitry has not yet made this correction. After all, without it, media buttons do not work at all. :roll_eyes:

I am a little lost, so this allows me to use an ESP for as virtual Bluetooth keyboard for devices? (Similar to how the Logitech remotes did?)

Also, can I switch between multiple devices, or would I need a separate ESP for each one? I have a Shield, Android TV and PC for example, can I switch between each device?

I’ve run out of ESPs, so working out how many more I need to order
Thanks :slight_smile:

Hi,
I am having the following problem:
After the ipad connects to the esp32 bluetooth, every time I restart the esp32, the ipad cannot automatically reconnect to the esp32 via bluetooth. On Android phones I don’t have this problem. Currently I have not found out the cause of the problem

How to install this?

Variant1:


Variant2:


This is cool for sure and much appreciated. Maybe its just me and a lack of imagination but, im struggling to think of any reasons to need a keyboard. Sure, you can find a use for controlling the volume on something or a few keys to toggle this or that but a full size keyboard seems overkill for those things. What am i missing or not thinking of here?

I’m having this same compile problem with EspHome 2024.3.0

Any ideas?

Compiling .pioenvs/esp-keyboard-wake/lib3d0/ESP32 BLE Arduino/BLEAdvertising.cpp.o
In file included from .piolibdeps/esp-keyboard-wake/ESP32 BLE Arduino/src/BLECharacteristic.h:19,
                 from .piolibdeps/esp-keyboard-wake/ESP32 BLE Arduino/src/BLEDescriptor.h:14,
                 from .piolibdeps/esp-keyboard-wake/ESP32 BLE Arduino/src/BLE2902.h:13,
                 from .piolibdeps/esp-keyboard-wake/ESP32 BLE Arduino/src/BLE2902.cpp:15:
.piolibdeps/esp-keyboard-wake/ESP32 BLE Arduino/src/FreeRTOS.h:61:28: error: 'ringbuf_type_t' has not been declared
  Ringbuffer(size_t length, ringbuf_type_t type = RINGBUF_TYPE_NOSPLIT);
                            ^~~~~~~~~~~~~~

@Tomsdad did you ever resolve this? I am trying to use this and am getting the same error unfortunately…

I never did. I fell back to the old solution that I had that uses this: https://github.com/clubcotton/esphome/blob/main/playground/esp32_ble_keyboard.h

I had the same issue. Managed to resolve the compilation by setting use_default_libs to false.

In the example provided in the documentation, in the last line, replace true with false.

ble_keyboard:
id: mamontech_keyboard
name: “MamonTechKeyboard”
manufacturer_id: “MamonTech”
battery_level: 50
reconnect: true
buttons: true
use_default_libs: false

1 Like

Your change helped it get further, but now I get a new error:

Linking .pioenvs/esphome-web-c66cb0/firmware.elf
/config/.esphome/platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: .pioenvs/esphome-web-c66cb0/src/main.cpp.o:(.literal._Z5setupv+0x670): undefined reference to `vtable for esphome::esp32_ble_server::NimBLEServer'
/config/.esphome/platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: .pioenvs/esphome-web-c66cb0/src/main.cpp.o:(.literal._Z5setupv+0x674): undefined reference to `vtable for esphome::esp32_ble_server::NimBLEServer'
/config/.esphome/platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: .pioenvs/esphome-web-c66cb0/src/main.cpp.o:(.literal._Z5setupv+0x678): undefined reference to `vtable for esphome::esp32_ble_server::NimBLEServer'
collect2: error: ld returned 1 exit status
*** [.pioenvs/esphome-web-c66cb0/firmware.elf] Error 1
========================= [FAILED] Took 26.31 seconds =========================

Any ideas?

Did you replace or download the external component? For me it works like this (replace the substitutions with your own :)):

# BLE Keyboard project
# https://github.com/dmamontov/esphome-blekeyboard

############# User configuration #############

substitutions:
  board: esp32-poe-iso #!! Include your own board
  mdns_name: my_ble_kb

  # Wifi credentials
  wifi_ssid: !secret wifi_ssid
  wifi_password: !secret wifi_password

  # OTA and API
  ota_password: "abcde"
  api_password: "FulG0C3MsqsWr01isFywdnO7azeXU67qIVXtJHBz9js="

  # Software configuration
  input_text_entity_id: "input_text.blekeyboard_new_message" # A string object for entering arbitrary text.


########### End user configuration ###########


############# Base configuration #############
esphome:
  name: $mdns_name
  comment: "https://github.com/dmamontov/esphome-blekeyboard"

esp32:
  board: $board

# Enable logging
logger:

# Enable OTA
ota:
  password: $ota_password
  platform: esphome

# Enable WiFi
wifi:
  #fast_connect: on
  ssid: $wifi_ssid
  password: $wifi_password
  
# Enable Home Assistant API
api:
  encryption:
    key: $api_password

########### End base configuration ###########

# Enable components
external_components:
#  - source:
#      type: local
#      path: ../components
  - source: github://dmamontov/esphome-blekeyboard

ble_keyboard:
  id: my_ble_keyboard
  name: $mdns_name
  manufacturer_id: "Apple"
  reconnect: true
  battery_level: 50
  buttons: true

text_sensor:
  - platform: homeassistant
    id: input_text
    entity_id: $input_text_entity_id
    internal: true

sensor:
  - platform: wifi_signal
    name: "WiFi Signal"
    update_interval: 60s

button:
  - platform: restart
    entity_category: "config"
    name: "Restart"

  - platform: template
    name: "Release"
    id: key_release
    icon: "mdi:send"
    on_press:
      then:
        - ble_keyboard.print:
            id: my_ble_keyboard
            text: !lambda "return id(input_text).state;"
        - ble_keyboard.release: my_ble_keyboard

#  - platform: template
#    name: "Ctrl + A"
#    id: key_ctrl_a
#    icon: "mdi:vector-combine"
#    on_press:
#      then:
#        - ble_keyboard.combination:
#            id: my_ble_keyboard
#            delay: 8
#            keys:
#              - 0x80
#              - "a"

#  - platform: template
#    name: "Calc"
#    id: key_calc
#    icon: "mdi:calculator"
#    on_press:
#      then:
#        - ble_keyboard.press:
#            id: my_ble_keyboard
#            code:
#              - 0
#              - 2

  - platform: template
    name: "_Start advertising"
    id: start_advertising
    icon: "mdi:bluetooth-connect"
    on_press:
      then:
        - ble_keyboard.start: my_ble_keyboard

  - platform: template
    name: "_Stop advertising"
    id: stop_advertising
    icon: "mdi:bluetooth-off"
    on_press:
      then:
        - ble_keyboard.stop: my_ble_keyboard

However I am experiencing a different issue. After the ESP restarted, it is not connected anymore. From the looks of this thread no one else experienced that. Is this an isolated issue on my device? Or am I missing some configuration?