logo elektroda
logo elektroda
X
logo elektroda
Dostępna jest polska wersja

Czy wolisz polską wersję strony elektroda?

Nie, dziękuję Przekieruj mnie tam

Adding remote control (Home Assistant integration) to USB Switch with OBK

p.kaczmarek2 1836 0

TL;DR

  • A Ugreen 30346 USB switch gets a Wi-Fi add-on so Home Assistant can remotely cycle between four connected USB devices.
  • An OBK-compatible module short-presses the switch button by pulling the MCU pin to ground, using a Rel_n output and a 0.5-second autoexec.bat pulse.
  • The USB switch handles 4 USB devices, while the add-on module needs 3.3V from the USB bus through a step-down converter.
  • The setup works in Home Assistant and even lets Stream Deck trigger port changes, with the active-port LED moving after each press.
  • Isolation with an optocoupler and decoupling capacitors are optional but recommended, and the button pin stays pulled high by default.
Generated by the language model.
ADVERTISEMENT
📢 Listen (AI):
  • Image of a module with a circuit board and cables for testing.
    In this tutorial we will show you how to simulate a short button press on non-smart device with a WiFi module addon. We'll use it to control the Ugreen 30346 USB switch remotely via Home Assistant. For this purpose, we'll use an OBK-compatible WiFi module (could be a Beken chip, or Winner Micro, or BL602, LN882, or even ESP32) and an extra step down converter to power it.

    The Ugreen 30346 USB switch used here allows you to easily switch between 4 USB devices. Each button press activates next connected device. The LED next to the active USB port is lit. This allows you to, for example, share a single keyboard between multiple computers.
    Desk with two monitors, a keyboard, and various electronic devices.

    ADVERTISEMENT


    So, let's start with basic requirements. What do we need to do to simulate a button press?
    - we need to add our WiFi module to hub and power it, but USB is 5V, and WiFi module uses 3.3V, so we will need a step down converter or LDO regulator
    - we need to send a short pulse to a button (short it to ground), for like 0.5 second, so we will need to script OBK for that

    Let's start with looking into our switch. There is a single button that when held, shorts the Nuvoton MCU pin to ground:
    Electronic layout of the Ugreen 30346 USB switch with visible components and USB ports.
    The pin is pulled high by default. We can connect it to our WiFi module GPIO directly in most cases. If you need to have isolation, use optocoupler. Here is a photo showing it during testing phrase with our dev board:;
    Image of a module with a circuit board and cables for testing.
    See breakout topic: Solderless conversion board for CB2S/WB2S Tuya modules compatible with ESP12 boards
    You can also see related solution (nodeMCU conversion):
    [Youtube] How to make BK7231 development board - NodeMCU conversion - soldering guide, hot air, SMD
    In order to keep the pin high by default, we've used Rel_n role, because Rel_n is active-low, while simply Rel is active-high in OBK. Here is OBK config:
    Code: JSON
    Log in, to see the code

    In order to make the pin return to high state after half a second, we've also added a short autoexec.bat script.
    
    // 0.5 is delay in seconds, 1 is number of repeats - once
    addChangeHandler Channel1 == 1 addRepeatingEvent 0.5 1 setChannel 1 0
    

    The following is enough to control it via Home Assistant, just do HASS Discovery and you'll get:
    Screenshot of the MQTT user interface for the BK7231N device, showing controls, diagnostic information, and event log.
    Let's test it - observe the LED moving between ports, it marks active port:



    Okay, the prototype is now working, but we need to pack it all together in the case.
    We will need a 3.3V source for that.
    We've had a cheap step down converter module at hand:
    Miniaturized step-down converter module on AliExpress.
    It's a very cheap and little device that can be useful for many projects. Aparat from that, no other external parts are required by WiFi module like CB2S or WB2S, it works out of the box, but it's good to add some decoupling capacitors as well:
    Photo showing a circuit board with electronic modules and a resistor on a wire.
    Resistor on the photo is the pull up, it may not be necessary, as Beken has internal pull-ups on GPIOs.

    With this modification, it is even possible to connect the USB switch to Stream Deck and control it from there:



    Look for the device LEDs on each USB port on the right side of the video. They switch with each press.

    The same approach can be used to control, toggle and reset many other devices. Futhermore, the following mechanism can be integrated into Home Assistant automations, so we a reset can happen automatically at given time of day or if a problem is detected. So now our device is much more versatile! We could have also added a feedback mechanism (read which LED is on to determine which port is active), but that's a task for another day...

    Cool? Ranking DIY
    Helpful post? Buy me a coffee.
    About Author
    p.kaczmarek2
    Moderator Smart Home
    Offline 
    p.kaczmarek2 wrote 14237 posts with rating 12141, helped 647 times. Been with us since 2014 year.
  • ADVERTISEMENT
📢 Listen (AI):

FAQ

TL;DR: A single 0.5-s active-low pulse lets the Ugreen 30346 switch between its 4 USB ports remotely; “OBK's Rel_n keeps the pin high by default” [Elektroda, p.kaczmarek2, post #21305800] Home-Assistant discovery auto-creates the entity in under a minute. Why it matters: You upgrade a dumb USB switch to Wi-Fi control for ≈ $5 in parts.

Quick Facts

• USB switch: Ugreen 30346, 4×USB-A outputs [Elektroda, p.kaczmarek2, post #21305800] • Logic levels: 5 V device rail ➜ 3.3 V Wi-Fi module [Elektroda, p.kaczmarek2, post #21305800] • DC-DC/LDO: Typical 5–24 V in → 3.3 V out, ≈ $1 [AliExpress listing, 2024] • Required pulse: 0.5 s low on Nuvoton MCU pin [Elektroda, p.kaczmarek2, post #21305800] • Firmware: OpenBK r1.17+ supports Rel_n, change-handlers, HA discovery [OpenBK docs, 2024]

What hardware is required to add Wi-Fi control to the Ugreen 30346?

You need an OBK-compatible Wi-Fi module (BK7231N/T, BL602, LN882 or ESP32), a 5 V→3.3 V step-down or LDO, two jump wires, and optionally 0.1 µF decoupling capacitors [Elektroda, p.kaczmarek2, post #21305800]

Why must the GPIO be set to the Rel_n role?

Rel_n is active-low, so the line idles high and only pulls low during a trigger. This mimics the physical button that shorts the Nuvoton pin to ground [Elektroda, p.kaczmarek2, post #21305800]

How is 5 V from USB converted safely to 3.3 V?

Solder the USB 5 V line to a mini DC-DC buck module and take its 3.3 V output to the Wi-Fi VCC. The converter handles up to 24 V input and supplies 600 mA—well above the 80 mA typical Wi-Fi draw [AliExpress listing, 2024].

What OBK script simulates the button press?

addChangeHandler Channel1 == 1 addRepeatingEvent 0.5 1 setChannel 1 0 It forces the GPIO high 0.5 s after a low-going edge, giving one clean pulse [Elektroda, p.kaczmarek2, post #21305800]

How do I expose the switch to Home Assistant?

Enable MQTT and set HASS Discovery to 1 in OBK. Restart the module; Home Assistant will auto-add a switch entity under ‘OpenBK Devices’ within 60 s [Elektroda, p.kaczmarek2, post #21305800]

Is an optocoupler mandatory between Wi-Fi GPIO and button pin?

No. The Nuvoton pin is already pulled high and tolerant of 3.3 V logic. Use an optocoupler only if galvanic isolation is required [Elektroda, p.kaczmarek2, post #21305800]

What happens if I mistakenly select Rel (active-high) instead of Rel_n?

The GPIO will idle low, holding the button line grounded. The USB switch may cycle continuously or lock up—a known failure scenario [Elektroda, p.kaczmarek2, post #21305800]

Can I read which USB port is active?

Yes. Connect the port-LED cathodes to spare ADC-capable GPIOs and publish their states via OBK rules. The author notes it as ‘a task for another day’ [Elektroda, p.kaczmarek2, post #21305800]

Does this modification work with an ESP32 board?

Yes. OBK builds for ESP32 expose identical Rel_n and rule engines, so the configuration is unchanged [OpenBK docs, 2024].

How much current does the full mod draw?

The Wi-Fi module peaks at ≈80 mA during transmit and idles around 12 mA. The buck converter adds <2 mA overhead—well below USB’s 500 mA budget [ESP32 datasheet, 2023].

3-step quick build guide

  1. Solder 5 V and GND from the USB board to the buck module; feed 3.3 V to Wi-Fi VCC.
  2. Wire GPIO 26 (Rel_n) to the Nuvoton button pad; tie module GND to board GND.
  3. Flash OBK, assign Rel_n on pin 26, paste the 0.5 s autoexec script, enable HASS discovery. Build completed.

What pull-up value keeps the button line high?

The Nuvoton MCU and Beken GPIOs each supply internal ≈50 kΩ pull-ups, so no extra resistor is normally needed [OpenBK docs, 2024].
Generated by the language model.
ADVERTISEMENT