Hello, I have been trying to determine the perimeter or API command to lock a Windows 10 desktop and control the volume via System Bridge.
I assume it could be done using keystrokes but the super key (Windows) does not seem to be an acceptable character and the fn keyboard shortcuts for volume on a laptop do not work on desktops.
Are there any direct ways of doing this? Bonus if I can unlock my PC from HA as well!
Hellis81
(Hellis81)
February 2, 2025, 8:43am
2
ESP-Home.
There is a custom component that has keyboard support.
I have one on my work PC with a person sensor and card reader.
So I can unlock the PC with my card and as soon as I leave the PC the person sensor stops detecting me and locks the computer.
The person sensor sometimes misfires so not sure I recommend it.
But perhaps the newer versions of it is better.
esphome:dev
← tomaszduda23:dev
opened 06:56PM - 18 Oct 22 UTC
# What does this implement/fix?
Emulating a USB keyboard.
It needs:
- https… ://github.com/esphome/esphome/pull/7520
- https://github.com/esphome/esphome/pull/7513
Optional:
- https://github.com/esphome/esphome/pull/7210
**Quick description and explanation of changes**
It adds dependency to https://github.com/adafruit/Adafruit_TinyUSB_Arduino.
## Types of changes
- [ ] Bugfix (non-breaking change which fixes an issue)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] Other
## TODO
- [x] add esphome/components/web_server/server_index_v2_keyboard.h
- [x] framework-arduinoespressif32 uses tinyusb behind
- [x] part of implementation is duplicated in this PR already
- [ ] check esp32-idf https://github.com/espressif/esp-idf/blob/636ff35b52f10e1a804a3760a5bd94e68f4b1b71/examples/peripherals/usb/device/tusb_hid/main/tusb_hid_example_main.c
- [ ] check rpi pico https://github.com/raspberrypi/pico-examples/tree/master/usb/device/dev_hid_composite
- [x] check how to add new device type. This is needed for web server.
**Related issue or feature (if applicable):** fixes <link to issue>
https://github.com/esphome/feature-requests/issues/1918
**Pull request in [esphome-docs](https://github.com/esphome/esphome-docs) with documentation (if applicable):** esphome/esphome-docs#<esphome-docs PR number goes here>
## Test Environment
- [ ] ESP32
- [ ] ESP32 IDF
- [ ] ESP8266
- [x] ESP32-S2
- [x] ESP32-S3
## Example entry for `config.yaml`:
<!--
Supplying a configuration snippet, makes it easier for a maintainer to test
your PR. Furthermore, for new integrations, it gives an impression of how
the configuration would look like.
Note: Remove this section if this PR does not have an example entry.
-->
```yaml
external_components:
- source: github://pr#3917
components: [hid, keyboard, usb_device, web_server, component_iterator, api]
refresh: always
esphome:
name: esp-white-control
board: lolin_s2_mini
platform: ESP32
web_server:
local: true
button:
- platform: template
name: "Press ShiftLeft + B"
on_press:
then:
- keyboard.down:
id: kbd
keys:
- ShiftLeft
- 5
- delay: 100ms
- keyboard.set:
id: kbd
- platform: template
name: "Press K"
on_press:
then:
- keyboard.down:
id: kbd
keys: KeyK
- delay: 100ms
- keyboard.up:
id: kbd
keys: KeyK
- platform: template
name: "Press volume up"
on_press:
then:
- keyboard.set:
id: kbd
keys: 0x00E9
type: media_keys
- delay: 100ms
- keyboard.set:
id: kbd
type: media_keys
- platform: template
name: "Press volume down"
on_press:
then:
- keyboard.set:
id: kbd
keys: 0x00EA
type: media_keys
- delay: 100ms
- keyboard.set:
id: kbd
type: media_keys
keyboard:
- platform: hid
name: Blue kbd
hid_id: usb_hid
id: kbd
hid:
- platform: usb_device
id: usb_hid
type:
composite:
- keyboard
- media_keys
binary_sensor:
- platform: usb_device
mounted:
name: USB is mounted
ready:
name: USB is ready
suspended:
name: USB is suspended
- platform: keyboard
keyboard_id: kbd
capslock:
name: capslock
numlock:
name: numlock
scrollock:
name: scrollock
switch:
- platform: usb_device
detach:
name: Detach USB device
wake_up:
name: Wake up host
```
## Checklist:
- [x] The code change is tested and works locally.
- [x] Tests have been added to verify that the new code works (under `tests/` folder).
If user exposed functionality or configuration variables are added/changed:
- [x] Documentation added/updated in [esphome-docs](https://github.com/esphome/esphome-docs).
https://github.com/esphome/esphome-docs/pull/2414
I just found out about HASS Agent, which provides an entity for both the volume controls and screen lock!
Now to figure out a secure way of proximity unlocking… might not be worth the convenience.