Skip to content

Commit a82c80b

Browse files
committed
Document usb_host_hid component
1 parent cdfa793 commit a82c80b

File tree

4 files changed

+97
-0
lines changed

4 files changed

+97
-0
lines changed

changelog/2025.7.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ ESPHome 2025.7.0 - 16th July 2025
1919
PI4IOE5V6408, components/pi4ioe5v6408, pca9554a.jpg
2020
SX126x, components/sx126x, sx126x.png
2121
SX127x, components/sx127x, sx127x.png
22+
USB HID Host, components/usb_host_hid, usb.svg, dark-invert
2223
XMWSDJ04MMC, components/sensor/xiaomi_ble, xiaomi_mijia_logo.jpg
2324

2425

components/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ Hardware Peripheral Interfaces/Busses
167167
OpenTherm, components/opentherm, opentherm.png
168168
SPI Bus, components/spi, spi.svg
169169
UART, components/uart, uart.svg
170+
USB HID Host, components/usb_host_hid, usb.svg, dark-invert
170171
USB Host, components/usb_host, usb.svg, dark-invert
171172
USB UART, components/usb_uart, usb.svg, dark-invert
172173

components/usb_host.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ possible to configure devices directly in this component, but this has no applic
2323
vid: 0x1725
2424
pid: 0x1234
2525
26+
.. note::
27+
28+
This component cannot be used in combination with
29+
:doc:`/components/usb_host_hid` as both components need to assume control of
30+
the plugged USB devices, which would create a conflict.
2631

2732
Configuration variables:
2833
************************

components/usb_host_hid.rst

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
USB HID Host Interface
2+
======================
3+
4+
5+
.. seo::
6+
:description: Instructions for setting up a USB HID Host interface on an ESP32 in ESPHome
7+
:image: usb.svg
8+
9+
The USB HID Host interface on the ESP32-S2, ESP32-S3 and ESP32-P4 is used to
10+
connect to USB HID (Human Interface Device) peripheral devices, that is,
11+
keyboards and mouses. Multiple devices may be configured and connected at once.
12+
By default, devices must be directly connected to the ESP32, but this can be
13+
changed by setting the ``enable_hubs`` option to ``true``.
14+
15+
This component only supports **keyboards** today. Key presses, assuming a
16+
standard US keyboard layout, will be accumulated internally. It is therefore
17+
most useful in combination with a :doc:`/components/key_collector`, as
18+
illustrated below.
19+
20+
.. code-block:: yaml
21+
22+
# Example configuration entry
23+
usb_host_hid:
24+
enable_hubs: true
25+
keyboards:
26+
- id: kbd_1
27+
vid: 0x1725
28+
pid: 0x1234
29+
30+
key_collector:
31+
- id: reader_1
32+
source_id: kbd_1
33+
# Collects whole lines of text, up to <Return>.
34+
end_keys: "\r"
35+
timeout: 1s
36+
# on_result:
37+
# ...
38+
39+
.. note::
40+
41+
This component cannot be used in combination with
42+
:doc:`/components/usb_host` as both components need to assume control of the
43+
plugged USB devices, which would create a conflict.
44+
45+
Configuration variables:
46+
************************
47+
48+
- **id** (*Optional*, :ref:`config-id`): The id to use for this component.
49+
- **enable_hubs** (*Optional*, boolean): Whether to include support for hubs.
50+
Defaults to ``false``.
51+
- **keyboards** (*Optional*, list): A list of keyboard devices to configure.
52+
53+
Keyboard configuration options:
54+
*******************************
55+
56+
- **id** (*Optional*, :ref:`config-id`): An id to assign to the device.
57+
- **check_class**: (*Optional*, boolean): Whether to check the device's HID
58+
class is indeed “keyboard”.
59+
- **vid** (**Required**, int): The vendor ID of the device. Use 0 as a wildcard.
60+
- **pid** (**Required**, int): The product ID of the device. Use 0 as a wildcard.
61+
62+
If a device is configured and a device is connected that matches the
63+
configuration, the device will be connected to the ESP32 and log entries will
64+
appear at the DEBUG level. If the log level is set to VERBOSE, then individual
65+
key presses will be logged. The device will remain connected until it is
66+
disconnected or the ESP32 is reset.
67+
68+
.. warning::
69+
70+
If multiple devices are plugged in that match the same wildcard
71+
configuration, only the first one will be correctly handled. A log entry at
72+
WARNING level will appear for subsequent conflicting devices. Make sure you
73+
have one ``keyboards`` configuration declared for each of the devices you
74+
intend to plug in, and that they do not conflict with each other.
75+
76+
If a device is plugged in that does not match any configured device, it will be
77+
ignored and a log entry will appear at the DEBUG level.
78+
79+
If a configured device is plugged in that does *not* declare itself as a HID
80+
keyboard, it will be ignored and a log entry will appear at the WARNING level.
81+
Some devices may work just fine (they report key presses) with this component,
82+
but do not declare themselves as keyboards, in which case you can set
83+
``check_class`` to ``false``.
84+
85+
See Also
86+
--------
87+
88+
- :doc:`/components/usb_host_hid`
89+
- :apiref:`usb_host_hid/usb_hid.h`
90+
- :ghedit:`Edit`

0 commit comments

Comments
 (0)