Controlling the HDMI 2.1 KVM via serial console (with Home Assistant)

After a little bit of tinkering and using some forum posts here for reference, I’ve successfully integrated my HDMI 2.1 dual-monitor KVM into Home Assistant by using the bottom “AUX” USB-C port for serial communication. I figured this out after referring to this post followed by me stumbling onto the AUX/USB-C method of serial access. This approach avoids the need for the RJ11 to MGMT/Control ports and enables switching between inputs via automation.

When connected from a USB A port on my Home Assistant Yellow to the AUX port, the KVM presents as /dev/ttyACM0. It behaves as a serial device (default baud rate was 9600) and accepts standard serial commands for switching video inputs. The top AUX port did not allow proper control of both displays (despite using the 9: V=N [Enter] approach highlighted here) on the dual-monitor version, whereas the bottom AUX port worked consistently.

To control the KVM, I used the shell_command integration in Home Assistant to send commands over the serial interface:

configuration.yaml:

input_button:
  kvm_input_1:
    name: KVM to PC 1
  kvm_input_2:
    name: KVM to PC 2
  kvm_input_3:
    name: KVM to PC 3
  kvm_input_4:
    name: KVM to PC 4

shell_command:
  kvm_input_1: "echo -ne '9:V=1\r\n' > /dev/ttyACM0"
  kvm_input_2: "echo -ne '9:V=2\r\n' > /dev/ttyACM0"
  kvm_input_3: "echo -ne '9:V=3\r\n' > /dev/ttyACM0"
  kvm_input_4: "echo -ne '9:V=4\r\n' > /dev/ttyACM0"

These shell commands are triggered via input_button entities and associated automations:

automations.yaml:

- id: kvm_input_1_button
  alias: KVM Input 1 Button
  description: Call shell_command.kvm_input_1 when the input button is pressed
  trigger:
    - platform: state
      entity_id: input_button.kvm_input_1
      to: 'pressed'
  condition: []
  action:
    - service: shell_command.kvm_input_1
  mode: single

- id: kvm_input_2_button
  alias: KVM Input 2 Button
  description: Call shell_command.kvm_input_2 when the input button is pressed
  trigger:
    - platform: state
      entity_id: input_button.kvm_input_2
      to: 'pressed'
  condition: []
  action:
    - service: shell_command.kvm_input_2
  mode: single

- id: kvm_input_3_button
  alias: KVM Input 3 Button
  description: Call shell_command.kvm_input_3 when the input button is pressed
  trigger:
    - platform: state
      entity_id: input_button.kvm_input_3
      to: 'pressed'
  condition: []
  action:
    - service: shell_command.kvm_input_3
  mode: single

- id: kvm_input_4_button
  alias: KVM Input 4 Button
  description: Call shell_command.kvm_input_4 when the input button is pressed
  trigger:
    - platform: state
      entity_id: input_button.kvm_input_4
      to: 'pressed'
  condition: []
  action:
    - service: shell_command.kvm_input_4
  mode: single

The user interface is built using a simple Lovelace card with stateless buttons that call the appropriate service:

Card configuration:

title: KVM Input Selector
columns: 4
square: false
cards:
  - show_name: true
    show_icon: true
    type: button
    name: PC 1
    icon: mdi:monitor
    tap_action:
      action: perform-action
      perform_action: shell_command.kvm_input_1
      target: {}
  - show_name: true
    show_icon: true
    type: button
    name: PC 2
    icon: mdi:monitor
    tap_action:
      action: perform-action
      perform_action: shell_command.kvm_input_2
      target: {}
  - show_name: true
    show_icon: true
    type: button
    name: PC 3
    icon: mdi:monitor
    tap_action:
      action: perform-action
      perform_action: shell_command.kvm_input_3
      target: {}
  - show_name: true
    show_icon: true
    type: button
    name: PC 4
    icon: mdi:monitor
    tap_action:
      action: perform-action
      perform_action: shell_command.kvm_input_4
      target: {}

This setup allows seamless control of all four KVM inputs directly from Home Assistant, with no reliance on KVM toggles or physical buttons which is ideal for me as I don’t have physical access to my KVM from where I’m working.

I’m sure there’s room for improvement from the HA side but I couldn’t find many (if any) resources or instructions for integrating the KVM this way and figured it might help someone in the future.

2 Likes