IoT USB Switcher

March 2023

Hacking a COTS USB 3.0 2 to 4 Switcher to allow for device power control and control via a Stream Deck.

Features:

  • Turn power to peripheral USB devices on and off

  • Send a button press to the switcher

  • Closed loop active input sensing

Summary

  • Bought COTS USB 3.0 2 to 4 Switcher

  • Removed back flow prevention diodes that allow power from the inputs to the outputs

  • Connected wires to the Input 1 power supply, output device power, switch button, and active input LEDs.

  • Assembled a protoboard with headers for a ESP32 Mini, MOSFET, and level shifter.

  • Connected the switch button and active input LED wires to the level shifter

  • Connected the Input 1 power supply and the output device power through the MOSFET. ESP32 is fed from the Input 1 power supply.

IoT Integration

The ESP32 runs ESPHome allowing it to easily integrate with my Home Automation. The Home Automation system can then be called from the Steam Deck using the Home Assistant plugin.

ESPHome Configuration

esphome:
  name: desk-km-peripheral-switch
  friendly_name: Desk K+M Peripheral Switch

esp32:
  board: esp32dev
  framework:
    type: arduino

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key:

ota:
  password:

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

  manual_ip:
    static_ip:
    gateway:
    subnet:
    
web_server:
  port: 80

output:
  - platform: gpio
    pin: 21
    id: switch_inputs

button:
  # Button output to change USB master
  - platform: output
    name: "Switch Inputs"
    output: switch_inputs
    duration: 500ms

switch:
  # Switch output to control supply power
  - platform: gpio
    pin:
      number: 22
      inverted: true
    id: enable
    name: "Enable"
    # icon: TODO


binary_sensor:
  # GPIO Binary Sensor to detect if Input 1 is active
  - platform: gpio
    id: input_1_active
    pin:
      number: 27
      mode:
        input: true
        pulldown: true
    name: "Input 1 Active"
    device_class: RUNNING
    on_state:
      then:
        - if:
            condition:
              - binary_sensor.is_on: input_1_active
            then:
              - text_sensor.template.publish:
                  id: state
                  state: "Input 1"
        - if:
            condition:
              and:
                - binary_sensor.is_off: input_1_active
                - binary_sensor.is_off: input_2_active
            then:
              - text_sensor.template.publish:
                  id: state
                  state: "Off"
                  
  # GPIO Binary Sensor to detect if Input 2 is active
  - platform: gpio
    id: input_2_active
    pin:
      number: 25
      mode:
        input: true
        pulldown: true
    name: "Input 2 Active"
    device_class: RUNNING
    on_state:
      then:
        - if:
            condition:
              - binary_sensor.is_on: input_2_active
            then:
              - text_sensor.template.publish:
                  id: state
                  state: "Input 2"
        - if:
            condition:
              and:
                - binary_sensor.is_off: input_1_active
                - binary_sensor.is_off: input_2_active
            then:
              - text_sensor.template.publish:
                  id: state
                  state: "Off"

# Create a template text sensor to display the output string
text_sensor:
  - platform: template
    name: "State"
    id: state
Previous
Previous

Home Automation Notificaton Lights

Next
Next

atmega32u4 Development Board