GithubHelp home page GithubHelp logo

fsievers22 / esphome-ble-remote Goto Github PK

View Code? Open in Web Editor NEW
25.0 5.0 8.0 14.72 MB

ESPHome external component for a BLE HID client

License: MIT License

C++ 10.74% Python 1.49% C 87.76%
esphome esp32 ble ble-client ble-hid hid firetv remote firetv-remote amazon-remote esp-idf shield-remote hid-host

esphome-ble-remote's Introduction

ESPHome external component to read hid events from a ble client

The ble_client_hid external component foor ESPHome can be used to capture hid events like key presses from a hid device connected via Bluetooth LE. Boards without internal PSRAM seem to be not compatible

Tested working with:

How to Use

Add as external component:

See External Components:

external_components:
  # use ble_client_hid from this master branch in GitHub
  - source: github://fsievers22/esphome-ble-remote@master
    components: [ ble_client_hid ]

Component:

Multiple ble_client_hid components can be configured, but at max three. (See BLE Client notes for more info).

The device has to use the esp-idf framework:

esp32:
  board: az-delivery-devkit-v4  #modify to fit your board
  framework:                    #only works n esp-idf framework
    type: esp-idf

Each ble_client_hid component requires a ble_client.

esp32_ble_tracker:            

ble_client:
  - id: ble_client_1
    mac_address: "FF:FF:20:00:0F:15"    #modify to fit your ble device

ble_client_hid:
  - id: ble_client_hid_1
    ble_client_id: ble_client_1

Configuration variables:

  • id(Required, ID): The ID to use for code generation, and for regerence by dependant components
  • ble_client_id(Required, ID): The ID of the ble_client component associated with this component can be omitted if only one ble_client is registered

Events:

The component sends an event through the HomeAssistant Native API to HomeAssistant, when an hid event happens. The event is named esphome.hid_events and contains the usage as a string and the value. Example:

data:
  usage: "KEYBOARD_EXAMPLE"
  value: 1

The usage is a string describing what the value can be used for like the keycode of a keyboard button.

Battery sensor:

The ble_client_hid sensor lets you track the battery level of the BLE HID client.

esp32_ble_tracker:            

ble_client:
  - id: ble_client_1
    mac_address: "48:B0:2D:52:29:C6"    #modify to fit your ble device

ble_client_hid:
  - id: ble_client_hid_1
    ble_client_id: ble_client_1

sensor:
  - platform: ble_client_hid
    ble_client_hid_id: ble_client_hid_1
    name: "Battery"

Configuration variables:

  • ble_client_hid_id(Required, ID): The ID of the ble_client_hid component associated with this component, can be omitted if only one ble_client_hid is registered.
  • id(Optional, ID): Manuallyy specify the ID used for code generation
  • All other options from Sensor

last event sensors:

The component can expose the last received event through a combination of a sensor and a text sensor.

sensor:
  - platform: ble_client_hid
    type: last_event_value
    name: "Last Event Value"

text_sensor:
  - platform: ble_client_hid
    name: "Last Event Usage"

Configuration variables:

  • ble_client_hid_id(Required, ID): The ID of the ble_client_hid component associated with this component, can be omitted if only one ble_client_hid is registered.
  • id(Optional, ID): Manuallyy specify the ID used for code generation
  • All other options from Sensor or TextSensor

Example device configuration:

esp32:
  board: az-delivery-devkit-v4  #modify to fit your board
  framework:                    #only works n esp-idf framework
    type: esp-idf

esphome:
  name: example-ble-hid         

external_components:
  # use ble_client_hid from this master branch in GitHub
  - source: github://fsievers22/esphome-ble-remote@master
    components: [ ble_client_hid ]

# Enable logging
logger:
  level: INFO

# Enable Home Assistant API
api:

ota:
  password: !secret ota_password

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  fast_connect: on

esp32_ble_tracker:            

ble_client:
  - id: ble_client_1
    mac_address: "48:B0:2D:52:29:C6"    #modify to fit your ble device

ble_client_hid:
  - id: ble_client_hid_1
    ble_client_id: ble_client_1

sensor:
  - platform: ble_client_hid
    type: battery
    ble_client_hid_id: ble_client_hid_1
    name: "Battery"
  - platform: ble_client_hid
    type: last_event_value
    ble_client_hid_id: ble_client_hid_1
    name: "Last Event Value"

text_sensor:
  - platform: ble_client_hid
    ble_client_hid_id: ble_client_hid_1
    name: "Last Event Usage"

esphome-ble-remote's People

Contributors

benedikt-bartscher avatar fsievers22 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

esphome-ble-remote's Issues

crash with unhandled exception

Crashes with both my remotes (chromecast remote / cheap chinese shutter button).
Board is esp-wroom-32
Maybe this is because my board does not have psram? Not sure how to check it. But another board, esp32-cam, which definitely has psram, crashes the same way.

[I][esp32_ble_client:064]: [0] [2B:80:3C:5A:A1:11] 0x00 Attempting BLE connection
[I][esp32_ble_client:265]: [0] [2B:80:3C:5A:A1:11] auth complete. remote BD_ADDR: 2b803c5aa111
[D][ble_client_hid:131]: GATT HID service found on device 2B:80:3C:5A:A1:11
[I][esp32_ble_client:196]: [0] [2B:80:3C:5A:A1:11] Connected
[D][ble_client_hid:145]: GATTC search finished with status code 0
[D][esp32_ble_tracker:245]: Starting scan...
[D][ble_client_hid:036]: Reading client characteristics
[W][ble_client_hid:239]: read_char failed
[W][ble_client_hid:239]: read_char failed
[D][ble_client_hid:070]: Found 6 characteristics
Guru Meditation Error: Core  1 panic'ed (LoadProhibited). Exception was unhandled.

Core  1 register dump:
....

I'd be happy to try and fix myself, if you point where to look

Chromecast remote support?

Hello @fsievers22

Is the chromecast remote supported? I saw ticket #23 but for me it seems not to work. How can I connect?
My config:

`esphome:
name: esp-wohnzimmer

esp32:
board: esp32dev
framework:
type: esp-idf

Enable logging

logger:

Enable Home Assistant API

api:
encryption:
key: "deleted"

ota:
password: "deleted"

wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password

Enable fallback hotspot (captive portal) in case wifi connection fails

ap:
ssid: "Esp-Wohnzimmer Fallback Hotspot"
password: "deleted"

external_components:

use ble_client_hid from this master branch in GitHub

  • source: github://fsievers22/esphome-ble-remote@master
    components: [ ble_client_hid ]

captive_portal:

esp32_ble_tracker:

ble_client:

  • id: ble_client_1
    mac_address: "84:C6:92:A8:D8:3D" #modify to fit your ble device

ble_client_hid:

  • id: ble_client_hid_1
    ble_client_id: ble_client_1
    bluetooth_proxy:
    active: true

sensor:

  • platform: ble_client_hid
    ble_client_hid_id: ble_client_hid_1
    type: battery
    name: "Battery"

  • platform: ble_client_hid
    type: last_event_value
    name: "Last Event Value"

  • platform: xiaomi_lywsd03mmc
    mac_address: "A4:C1:38:C0:E6:5A"
    bindkey: "deleted"
    temperature:
    name: "Kueche Temperature"
    id: kueche_temperature
    humidity:
    name: "Kueche Humidity"
    id: kueche_humidity
    battery_level:
    name: "Küche Xiaomi Battery Level"
    id: kueche_xiaomi_battery_level3

text_sensor:

  • platform: ble_client_hid
    name: "Last Event Usage"`

I got my mac adress by logging in to chromecast via adb and enter
adb shell dumpsys bluetooth_manager
The response was:
Bonded devices:
84:C6:92:A8:D8:3D [ LE ] Chromecast Remote

I also tried to do a pairing of the remote (home and back buttons until led is on)

But i guess it is not working. Is everything correct from your point of view?

Just an idea for making Esphome component to read/shiff from any BLE HID Server input

Hi fsievers22 and congrats for the great project!
I'm not quite sure is this the right place for asking you a question but if it's not just tell me and I'll erase it from here.

My programmer skills are far away from yours and I'm trying to make an Esphome project aimed to reading from BLE HID device server input, just a raw data or whatever it is coming from the device. Text sensor seemed to me as a good solution. What do you think how much harder would be to turn your project into the new Esphome project for input reading from BLE HID server device?
Thank and regards!

Working key layout for new Fire Remote Pro

Just thought I would share the working keycodes for the new Fire Remote Pro with the extra buttons.

//Keymap for light-up amazon fire remote pro with multiple extra buttons static std::map<uint8_t, std::string> KEYMAP {{0x52,"UP"},{0x51,"DOWN"},{0x50,"LEFT"},{0x4f,"RIGHT"}, {0x21,"VOICE"},{0x66,"POWER"},{0xf1,"BACK"},{0x23,"HOME"}, {0x40,"MENU"},{0xb4,"REWIND"},{0xcd,"PLAY_PAUSE"},{0xb3,"FAST_FORWARD"}, {0xe9,"VOL_UP"},{0xea,"VOL_DOWN"},{0xe2,"MUTE"},{0x58,"ENTER"}, {0x80,"HEADPHONES"},{0x9c,"CHN_UP"},{0x9d,"CHN_DOWN"},{0x8d,"TV"}, {0x33,"SETTINGS"},{0x7e,"ONE"},{0x7f,"TWO"},{0xa1,"PRIME"}, {0xa2,"NETFLIX"},{0xa3,"DISNEY"},{0xa4,"HULU"}};

Multiple buttons register as the same button

I went back to the old code because one I flashed the new version all of the extra buttons on the fire remote pro registered as the same button. I don't know if this can be fixed.

I'm super happy with the old code, except it still won't connect to anything other than fire or shield remotes, it sits at discovered device and never connects.

text_sensor not working with latest esphome

text_sensor currently only changes from 0 to 1

[14:25:57][D][ble_client_hid:184]: Received HID input report from handle 48
[14:25:57][D][hid_parser:350]: Parsing HID report with report ID (1)
[14:25:57][D][hid_parser:442]: HIDReportItemValue(usage_page: 7, usage: 80, value: 0)
[14:25:57][D][text_sensor:064]: '': Sending state 'Keyboard LeftArrow'
[14:25:57][D][sensor:110]: 'bleproxy-lr Last Event Value': Sending state 0.00000  with 0 decimals of accuracy
[14:25:57][D][ble_client_hid:207]: Send HID event to HomeAssistant: usage: Keyboard LeftArrow, value: 0

Hi Fabian!

First at all, thank you for sharing this.

Im new here so, im sure im wrong publishing this here, anyways, I wanted to ask you if you can help me.

I have a remote of a Fire Tv stick, with no use because the stick was stolen from my house (can you believe it?).
I thought that I may be able to use it with my esp32 to turn on automations, lights... etc. but after a while of researching I wasn't able to find a solution using the example that ESPHome gives about an BLE iTag.

I have no experience in coding, and no experience in custom sensors for ESPHome. Im pretty sure your code will save me, but can you give me a glance of how to use it? Thank you!

ESP-IDF Issue - Max Notification Reached, registration failed

First of all, thank you for this awesome esphome component.
I tried to pair with "Alexa Remote Pro" but while reading the characteristics it fails with this error:

E (18960) BT_APPL: Max Notification Reached, registration failed.

which is caused by espressif/esp-idf#6376.
I think there is not much we can do in this repo, i just wanted to keep track of the issue.

Remotes that this works with

Hi!
I tried this with 3 different generations of remotes:
The one without the alexa mic, the first one with the mic and the first one that had IR on board

Only the one that has IR I could get to work....

Do you have any additional infos here ? Could you make others work ?

(Minor info: I also got the crash issue reported elsewhere, I did downgrade to using the arduino framework to avoid it for now)

Greetings,
Lukas

Sony TV bluetooth remote

I was testing this with a Sony TV Bluetooth remote.
The remote disconnects after a while and then have to be paired again.

Document board compability

As discussed in #17 not all esp32 boards are supported. Currently i only know about the internal PSRAM limitation, maybe there are more. I think boards with ethernet should work better, because bluetooth/wifi can interfere on esps

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.