logo elektroda
logo elektroda
X
logo elektroda

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

p.kaczmarek2 1893 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 14493 posts with rating 12502, helped 651 times. Been with us since 2014 year.
  • ADVERTISEMENT
📢 Listen (AI):

FAQ

TL;DR: In a 0.5-second OBK pulse mod, “Rel_n is active-low” makes a Ugreen 30346 USB switch remote-controllable from Home Assistant. This FAQ is for users who want to add Wi‑Fi control to a non-smart USB switch using a 3.3V OBK-compatible module powered from USB 5V. [#21305800]

Why it matters: It turns a simple 4-port USB switch into an automation target for Home Assistant, Stream Deck, and scheduled reset tasks without replacing the original hardware.

Option Input Output Best use in this project
Step-down converter 5V USB 3.3V Preferred add-on power source mentioned for fitting the Wi‑Fi module inside the case
LDO regulator 5V USB 3.3V Simpler alternative when you only need 3.3V regulation
Direct GPIO-to-button line 3.3V logic Active-low short to GND Best when the MCU button input is already pulled high
Optocoupler Isolated control Active-low short via isolation Better when galvanic isolation is required

Key insight: The mod works because the switch’s button line is normally pulled high, so an OBK GPIO configured as active-low can briefly pull it to ground and mimic one human button press.

Quick Facts

  • The target device is a Ugreen 30346 USB switch, and each press advances to the next active USB port while the matching LED lights up. [#21305800]
  • The Wi‑Fi add-on needs 3.3V, while the USB switch provides 5V, so the build uses a step-down converter or an LDO regulator. [#21305800]
  • The OBK momentary-press timing shown in the script is 0.5 seconds with 1 repeat, which returns the GPIO to its idle state automatically. [#21305800]
  • CB2S and WB2S modules are shown as usable examples, and the thread notes that no other external parts are required for basic operation beyond power conversion, though decoupling capacitors are recommended. [#21305800]

How do I add Home Assistant remote control to a Ugreen 30346 USB switch using an OBK-compatible WiFi module?

Add a 3.3V OBK-compatible Wi‑Fi module, wire one GPIO to the switch’s button line, and script a short active-low pulse. 1. Power the module from the USB switch’s 5V rail through a step-down converter or LDO. 2. Connect the GPIO to the Nuvoton button input that is pulled high by default. 3. Set that pin to Rel_n;1, then enable HASS Discovery so Home Assistant exposes the control automatically. [#21305800]

What’s the safest way to simulate a short button press on a non-smart USB device with OpenBK7231T_App?

Use a GPIO that briefly shorts the button line to ground, because the thread shows the switch button works by grounding a pulled-up MCU input. The safest direct method is active-low control with the line left high at idle. If isolation is required, use an optocoupler instead of a direct GPIO connection. [#21305800]

Why is the Rel_n role used in OBK for this USB switch mod instead of the regular Rel role?

Rel_n is used because the USB switch button input must stay high when idle and go low only during a press. The thread states that Rel_n is active-low, while regular Rel is active-high. That makes Rel_n the correct role for simulating one grounded button press on this Nuvoton input. [#21305800]

How do I write the OBK autoexec.bat script so the GPIO pulls the button line low for only 0.5 seconds?

Use an OBK change handler that schedules one delayed reset of the channel after 0.5 seconds. The thread’s exact logic is: when Channel1 becomes 1, add one repeating event after 0.5 seconds to set Channel 1 back to 0. That creates a momentary active-low pulse instead of a latched output. [#21305800]

What is OBK-compatible hardware, and which chips like BK7231, Winner Micro, BL602, LN882, or ESP32 can be used for this kind of mod?

“OBK-compatible hardware” is Wi‑Fi module hardware that runs OpenBK7231T_App, letting a GPIO be scripted and exposed to platforms like Home Assistant, with support extending beyond one chip family. The thread explicitly lists Beken, Winner Micro, BL602, LN882, and even ESP32 as usable options for this style of button-press mod. [#21305800]

What is HASS Discovery in Home Assistant, and how does it expose an OBK device automatically?

“HASS Discovery” is a Home Assistant integration mechanism that publishes device details automatically, so compatible entities appear without manual entity creation, reducing setup work after flashing and configuring the module. In this project, the thread says HASS Discovery is enough to make the OBK-controlled USB switch appear in Home Assistant for remote use. [#21305800]

How can I power a CB2S or WB2S WiFi module from a 5V USB switch that only provides USB power?

Convert the switch’s 5V USB supply down to 3.3V before powering the CB2S or WB2S module. The thread uses a cheap step-down converter module for this and states that CB2S or WB2S otherwise work out of the box. It also recommends adding decoupling capacitors for better supply stability. [#21305800]

Step-down converter vs LDO regulator for powering a 3.3V WiFi module from USB 5V — which is better in this USB switch project?

The thread favors a small step-down converter because one was available, compact, and easy to fit into the case. Both options satisfy the same electrical need: converting 5V USB to 3.3V for the Wi‑Fi module. Choose the step-down converter when you want the exact approach demonstrated in the build. [#21305800]

What does the addChangeHandler and addRepeatingEvent command do in the OBK script for a momentary button press?

It turns a normal channel toggle into a timed momentary press. addChangeHandler watches for Channel1 becoming 1, and addRepeatingEvent 0.5 1 schedules one event 0.5 seconds later to run setChannel 1 0. That sequence gives one short pulse, not a permanently asserted GPIO. [#21305800]

How should I connect a WiFi module GPIO to a Nuvoton MCU button input that is pulled high by default?

Connect the GPIO to the button line so the GPIO can pull that input to ground briefly. The thread shows the Nuvoton MCU pin is pulled high by default and the physical button shorts it to ground when pressed. That is why an active-low OBK role maps cleanly to the original switch behavior. [#21305800]

When would an optocoupler be a better choice than a direct GPIO connection for simulating a button press?

Use an optocoupler when you need electrical isolation between the Wi‑Fi module and the target device. The thread says direct GPIO connection is acceptable for this switch, but explicitly recommends an optocoupler if isolation is required. That is the safer choice when you cannot share grounds confidently. [#21305800]

What troubleshooting steps help if the Ugreen USB switch changes ports unreliably or triggers multiple presses after the OBK mod?

Shorten the active pulse to the shown 0.5-second behavior, confirm the pin idles high, and check power quality. Multiple presses can happen if the GPIO stays low too long instead of resetting once. The thread also recommends decoupling capacitors and notes an external pull-up resistor may be unnecessary because Beken GPIOs have internal pull-ups. [#21305800]

How do pull-up resistors and internal GPIO pull-ups affect this active-low button simulation circuit?

They keep the button line at a defined high level until the GPIO forces it low. The thread shows an added pull-up resistor in a test photo, then notes it may not be necessary because Beken GPIOs include internal pull-ups. In this active-low design, stable pull-up behavior prevents false presses when the line is idle. [#21305800]

In what way could I add feedback to detect which USB port LED is active and report that state back to Home Assistant?

Read which port LED is on and convert that into a reported state. The thread explicitly proposes this as the missing feedback path: detect the lit LED to determine the active USB port, then send that state back to Home Assistant. That would upgrade the mod from blind switching to state-aware switching. [#21305800]

How can this OBK-controlled USB switch be integrated with Stream Deck or Home Assistant automations for scheduled switching or reset tasks?

Expose the OBK device in Home Assistant, then trigger it from Stream Deck or automations that call the switch entity. The thread shows Stream Deck control working and states the same mechanism can run scheduled actions, including timed resets or problem-triggered resets. That makes the mod useful beyond manual port cycling. [#21305800]
Generated by the language model.
ADVERTISEMENT