Skip to content

Elod-T/pcrelay

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 

Repository files navigation

ESP8266 pc relay!

This is an easy project based on the esp8266 board and a relay. It works with both Amazon Alexa, the Google Assistant and Apple Homekit(Siri)!

Hardware requirements:

  • your favorite esp8266 board (I recommend getting a Wemos D1 Mini, AliExpress link)
  • a relay board (for a more compact and easy setup, you can get the Relay Shield for the Wemos D1 Mini, AliExpress link)
  • some jumper cables (at least 2 pcs female-male and 2pcs male-male, but it depends on your setup, AliExpress link)

Wemos with relay

Software requirements:

  • Arduino ide or any kind of firmware flasher(for example EspTool)

Wiring:

If you have the Wemos D1 Mini and the Relay shield you can just simply follow this diagram. Warning: perform these instruction ONLY when you unplug your pc from the wall! (I do not take responsibility for injuries) You have to unplug your existing power switch cables from your pc's motherboard and connect it to the relay's common and normally open pins (the order of the cable doesn't matter). I did this with 2 male-male jumper cables. After that you have to connect your motherboard's power switch pins to the same 2 pins on the relay as before (the order of the cable doesn't matter too). And finally you have to put the relay shield on the top of the Wemos board, be careful with it's orinetation.

Created with https://www.circuitlab.com/

(D1, GND and 5V are already connected because of the shield)

If you have a regular relay and esp8266 board you have to perform the exact same steps as above. After that you have to connect the relay to the board with 3 jumper cables.

  • 5V -> 5V
  • GND -> GND
  • IN -> D1 (any port of your choice)

Code:

Make sure to replace the CAPITALIZED texts in the pcrelay.ino file. If you want you can customize the relay port (do not change for the Wemos), and the intervallum it pushes the button for by default.

Flashing:

First you have to install the CH340G drivers on your system (only on Windows and Mac). And then install the esp8266 board using this tutorial. In Arduino Ide change your board to Wemos D1 Mini and leave the other options on default. Hit upload and you are good to go! If you have chosen the OTA version you have to do this once, after that you can upload firmware wirelessly!

Usage:

Your board connects to the wifi, and then to the mqtt broker(if you don't have one check out CloudMqtt) and subscribes to the topic. If it receives any form of "ON" or "OFF" it is going to do the same thing: turn on the relay, wait (default: 1 seconds) and then turn off the relay. If it receives a number it does the same thing but it wait the number received (max 10). This feature is useful when your pc frozes and you want to force it to turn off (for example 10 seconds wait time will definitely turn off any pc). Be careful with force shutdown because it is basically equal to unplugging your pc from the wall, so you can lose data.

Update:

If you have the OTA version just download the newest pcrelay.ino file, compile it with your config. And then go to http://your.esp.8266.ip/update and then upload your compiled firmware. If you have the version without the OTA (TODO) just simply flash it like it is the first time.

Alexa and Google Home support

It is possible through Home Assistant. You have to install Home Assistant, then configure the mqtt broker, and finally set up Google Assistant, Alexa or Apple Homekit (Siri). After that you have to add the your switch to the configuration.yaml file, and then expose the switch to your favorite voice assistant! Example switch config:

switch:
  - platform: mqtt
    name: "YOUR RELAY NAME"
    command_topic: "YOUR COMMAND TOPIC"

TODO

  • Working project with basic functionality
  • OTA update functionality
  • Optional version without OTA update

Thank you

if you if you've made it through! This is my first GitHub repo, so any help, comment or critique is appriciated!