Sitelet https://github.com/jitu72/s_switch
Skip to content

Latest commit

 

History

8 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Remote PC Power Switch (ESP-01S + SinricPro)

Battery-powered ESP-01S firmware for remotely triggering a desktop PC's motherboard power button through SinricPro or Google Home. It uses secure WebSocket connectivity, OTA updates, WiFiManager captive-portal provisioning, EEPROM state storage, and serial activity logging.

Features

  • Remote PC power-button control through SinricPro or Google Home
  • Secure wss://ws.sinric.pro connection
  • OTA firmware updates
  • Captive-portal Wi-Fi setup
  • Relay-state restore after reboot or power loss
  • Serial activity history and diagnostics
  • Wi-Fi auto-reconnect with sleep disabled for reliable WebSocket operation

Hardware

  • ESP-01S / ESP8266 with 1 MB flash
  • ESP-01S 5 V Wi-Fi relay module with an SRD-5VDC-SL-C relay
  • Single-cell 18650 Li-ion battery
  • 5 V power-bank boost/charging/protection board
  • Desktop PC with an accessible motherboard PWR_SW / POWER SW header
  • Y-split power-button connection shared with the PC case switch
  • Motherboard internal USB 5 V and GND connection for battery charging

The current firmware targets the ESP-01S, not an ESP32. The ESP-01S has limited RAM, so the application keeps the diagnostic history intentionally small and does not enable verbose SinricPro/WebSocket library logging in the normal build.

Power and Circuit Wiring

The 18650 powers the relay module through the power-bank board. The battery is connected only to the board's battery pads; the relay module receives the regulated 5 V boost output.

flowchart TB
    subgraph POWER["LOW-VOLTAGE POWER AND CHARGING"]
        direction LR
        BAT["18650 Li-ion cell<br/>3.7 V nominal<br/>B+ / B-"]
        BOOST["Power-bank board<br/>charger + protection + 5 V boost"]
        USB5["Motherboard internal USB<br/>+5 V / GND"]
        BAT -->|"B+ to B+"| BOOST
        BAT -->|"B- to B-"| BOOST
        USB5 -->|"5 V charging input"| BOOST
    end

    subgraph CONTROL["ESP-01S RELAY MODULE"]
        direction TB
        VCC["5 V / VCC"]
        GND["GND"]
        MCU["ESP-01S / ESP8266<br/>Wi-Fi control"]
        COIL["5 V relay coil<br/>SRD-5VDC-SL-C"]
        VCC --- MCU
        GND --- MCU
        MCU -. "internal control<br/>(GPIO0)" .-> COIL
    end

    BOOST -->|"OUT+ / regulated 5 V"| VCC
    BOOST -->|"OUT- / GND"| GND

    subgraph LOAD["PC POWER BUTTON CIRCUIT"]
        direction LR
        PWR1["Motherboard<br/>PWR_SW pin 1"]
        SPLIT1["Y-split"]
        CASE1["PC case<br/>power switch"]
        COM["Relay COM"]
        NO["Relay NO"]
        PWR2["Motherboard<br/>PWR_SW pin 2"]
        SPLIT2["Y-split"]
        CASE2["PC case<br/>power switch"]
        PWR1 --- SPLIT1
        SPLIT1 --- CASE1
        SPLIT1 --- COM
        PWR2 --- SPLIT2
        SPLIT2 --- CASE2
        SPLIT2 --- NO
        COM -->|"momentary contact"| NO
    end

    COIL -. "isolated dry contact" .- COM

    classDef power fill:#fff3cd,stroke:#b8860b,color:#222
    classDef control fill:#d9edf7,stroke:#31708f,color:#222
    classDef danger fill:#f8d7da,stroke:#a94442,color:#222
    class BAT,BOOST,USB5 power
    class VCC,GND,MCU,COIL control
    class PWR1,COM,NO,PWR2 danger
Loading

The diagram separates the battery-powered low-voltage side from the relay's electrically isolated switched contacts:

18650 B+  ───────────────>  Power-bank B+
18650 B-  ───────────────>  Power-bank B-
Motherboard USB +5 V ────>  Power-bank 5 V charging input
Motherboard USB GND ─────>  Power-bank charging input GND

Power-bank OUT+ / 5 V  ──>  Relay module 5 V / VCC
Power-bank OUT- / GND  ──>  Relay module GND

Motherboard PWR_SW pin 1 ─> Y-split ─> Case switch wire 1
                                      └> Relay COM
Motherboard PWR_SW pin 2 ─> Y-split ─> Case switch wire 2
                                      └> Relay NO

The relay COM/NO pair acts like briefly pressing the PC's physical power
button. It does not supply power to the PC.

Wire the low-voltage side as follows:

Power-bank board ESP-01S relay module
B+ 18650 positive terminal
B- 18650 negative terminal
OUT+ / regulated 5V 5V / VCC
OUT- / GND GND

The ESP-01S and relay are integrated on the relay module, so no separate relay signal wire is required. The firmware drives the module's configured relay control input, GPIO0. The relay coil and screw terminals are electrically isolated from the ESP8266 control electronics, subject to the module's design and safe wiring.

PC Power-Switch Connection

Connect the relay's dry contacts to the two motherboard pins labeled PWR_SW, POWER SW, or PWRSW:

  • Use a Y-split on each motherboard PWR_SW pin.
  • Keep the original PC case power-switch wires connected to one branch of each split.
  • Connect the two additional branches to relay COM and NO.
  • Leave relay NC unused.
  • The two wires are not polarity-sensitive.

The relay briefly shorts the two PWR_SW pins, just like the case power button. The motherboard supplies the button-header sensing voltage; the relay does not connect the battery or 5 V boost output to the PC. This project controls the PC's power-button input and does not directly switch the PC's AC input or ATX power rails.

SinricPro Auto-Off Timer

Set the device's Auto Off duration to 3 seconds in SinricPro when creating the device, or later from the SinricPro dashboard under Timers. This is important because the relay is connected across the motherboard's power-button pins: it should close briefly like a physical button press and then release automatically. Do not leave Auto Off disabled or set to a long duration, because the relay could hold the power-button circuit closed.

Battery Charging from the PC

The motherboard's internal USB header provides the project's charging input:

  • Connect motherboard USB +5V to the power-bank board's regulated 5 V input.
  • Connect motherboard USB GND to the power-bank board's charging-input GND.
  • Keep the 18650 connected to the power-bank board's B+ and B- battery pads.

When the PC is running, the internal USB header supplies 5 V and the power-bank board charges the 18650. When the PC is off, the battery powers the boost output and keeps the ESP-01S relay module available for remote startup. The relay's dry contacts remain separate from the USB charging wires and the motherboard power-switch pins.

Verify the exact labels and polarity on the power-bank board before wiring: some boards label the 5 V charging input as IN+/IN-, 5V/GND, or use a micro-USB connector rather than exposed pads. Do not connect the motherboard USB 5 V to B+ or B-.

For reference, the relay screw terminals are:

  • COM is the common contact.
  • NO (normally open) connects to COM only when the relay is energized.
  • NC (normally closed) connects to COM while the relay is off.

Use COM and NO for the normal PC power-button connection. Do not use NC for this project.

Electrical and Battery Safety

  • Use one 3.7 V nominal 18650 cell only. Never connect the cell directly to the relay module's 5 V input.
  • Confirm the boost board output is approximately 5 V under load and can supply the ESP8266 Wi-Fi current peaks plus the relay coil.
  • Confirm the power-bank board supports charging the cell while its 5 V boost output is powering the relay module. Cheap boards may not support simultaneous charge and load operation.
  • Use a protected cell or verify that the power-bank board provides overcharge, over-discharge, and short-circuit protection.
  • Insulate the battery terminals and add a fuse close to the battery positive lead where practical.
  • Do not charge the battery while powering the relay unless the power-bank board explicitly supports safe simultaneous charging and load operation.
  • This project is intended to switch only the isolated motherboard power-button header, not hazardous mains voltage.
  • Disconnect the PC from AC power before opening the case or connecting the relay wires.
  • Keep the battery/boost wiring insulated and physically separated from the PC's mains input and internal power circuitry.

PlatformIO Configuration

The project uses the esp01_1m environment:

[env:esp01_1m]
platform = espressif8266
board = esp01_1m
framework = arduino
board_build.flash_mode = dout

Build the firmware:

pio run -e esp01_1m

Upload over a serial programmer:

pio run -e esp01_1m --target upload

After the first successful upload, OTA updates use the hostname smart-switch.

Credentials

Create src/secrets.h from src/secrets.example.h and fill in:

  • SINRIC_APP_KEY
  • SINRIC_APP_SECRET
  • SINRIC_SWITCH_ID
  • OTA_HOSTNAME
  • OTA_PASSWORD

src/secrets.h is ignored by Git and must never be committed.

Wi-Fi Provisioning

If no saved Wi-Fi credentials exist, the ESP-01S starts a setup access point:

  • SSID: SmartSwitch-Setup
  • Password: 12345678

Connect to that access point and open http://192.168.4.1, then select the home Wi-Fi network. The firmware reports the assigned IP address over serial.

Serial Monitor

Open the monitor at 115200 baud:

pio device monitor -b 115200

Normal SinricPro connection output includes:

[Event ...][SinricPro][...] Connected

Initialized means the SinricPro client was configured; Connected confirms that the secure WebSocket handshake completed. Disconnected is emitted after an established connection is lost.

Serial Commands

  • h: print activity history
  • c: clear activity history
  • w: clear saved Wi-Fi credentials and reboot into setup mode
  • s: force a relay-state sync to SinricPro

Troubleshooting

If Wi-Fi connects but SinricPro does not, enable temporary library diagnostics by adding this build flag to platformio.ini:

-D DEBUG_ESP_PORT=Serial

Remove that flag after troubleshooting. Verbose WebSocket diagnostics consume significant heap on the ESP-01S and can cause an out-of-memory reset when a SinricPro command is processed.

Keep TLS enabled. Do not add SINRICPRO_NOSSL for normal use because it sends the SinricPro connection without encryption.

Security Notes

  • Never commit src/secrets.h.
  • Rotate SinricPro credentials if they are exposed.
  • Change the default OTA password in src/secrets.h before production use.

About

Battery-powered ESP-01S Wi-Fi relay for remotely turning a PC on from SinricPro or Google Home, with secure connectivity, OTA updates, Wi-Fi provisioning, and persistent state recovery.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages