Jump to content

Smart On/Off switch for pc using relay

Hello,
I was planning to mod my pc, to power it on and off using a smart home device like alexa. I don't want to use wake on lan, since from my experience it's rather unreliable and buggy at times.

My plan was to use a relay, which would close the circuit between the two pins, on which the on/off switch is positioned. I was thinking about something like this. I would then try to power the relay using one of the onboard usbs, since they should be able to provide enough power, while the computer is shut down. 

Now my question is, since I am not that familiar with electronics, if this would even work? can i use the relay to close and open the circuit between the two power pins ? would the usb power be enough ? is there any other power source in my pc that i could use ? i really dont want to power it from an external power source.

Link to comment
Share on other sites

Link to post
Share on other sites

Well this is an interesting topic. You definitely can use the relay module to turn on your pc but turning it off may be more troublesome if your just gonna cut the supply to it because your pc needs to shutdown properly. A better option would be to pull a parallel connection from the power button header on your mother board and connect the relay there. That way, the relay will act like the power button and will shut down the pc properly.

 

As for the power supply, the Amazon site states that it can run off a USB port so i guess you can do that. If you dont want to use a USB port you could directly connect it to your pc's power supply but i wouldn't advise doing that because it may damage your power supply.

 

Good luck !! 

 

Link to comment
Share on other sites

Link to post
Share on other sites

You can simply use the power switch wires going to the front panel power button ... short them for a short period like half a second or a second to command operating system to shut down, or keep them shorted for around 5 seconds to force shut down (command power supply to power off ignoring the operating system)

 

You can use a simple npn transistor to create connection between the two wires... send a signal into the base of a npn transistor using your microcontroller and the transistor turns on and connects the two wires together.

 

Link to comment
Share on other sites

Link to post
Share on other sites

21 hours ago, Mr_sparky said:

Well this is an interesting topic. You definitely can use the relay module to turn on your pc but turning it off may be more troublesome if your just gonna cut the supply to it because your pc needs to shutdown properly. A better option would be to pull a parallel connection from the power button header on your mother board and connect the relay there. That way, the relay will act like the power button and will shut down the pc properly.

 

As for the power supply, the Amazon site states that it can run off a USB port so i guess you can do that. If you dont want to use a USB port you could directly connect it to your pc's power supply but i wouldn't advise doing that because it may damage your power supply.

 

Good luck !! 

 

Ah, it seems i was a bit unclear about how i would do this, so here the clarification (it's basically what you said ^^):

  • Make a parallel line of the power button switch, so i can either turn it on using the button, or using the relay.
  • The relay would function as the button, shorting the circuit for a short time (1-2s max) so the pc starts.
  • If the relay bugs out, or breaks, the circuit will either not be shorted and i can still power on and off using the switch, or the circuit is permantly shorted which will trigger 1 start and an immediate power off, since the psu should detect the constant short and not power the pc on a second time, until i remove the relay and stop the permanent short.


For the exact reason you mentioned, i wanted to go usb, because it's easier and standardised, and i won't have to tinker around with the psu.

Im still looking for the type of cable that fits onto the power button pins, because i would rather not cut the case cables, but just extend them with some custom cables.

Link to comment
Share on other sites

Link to post
Share on other sites

21 hours ago, mariushm said:

You can simply use the power switch wires going to the front panel power button ... short them for a short period like half a second or a second to command operating system to shut down, or keep them shorted for around 5 seconds to force shut down (command power supply to power off ignoring the operating system)

 

You can use a simple npn transistor to create connection between the two wires... send a signal into the base of a npn transistor using your microcontroller and the transistor turns on and connects the two wires together.

 

yes, as mentioned in the comment above, i planned to short the front panel power button. I wanted to go with the "smart" relay, because then i would not have to tinker around with a some esp32/rasp-py thingy. Is there some advantage to using the npn transistor, as opposed to the relay ?

Link to comment
Share on other sites

Link to post
Share on other sites

I was also unsure due to the descriptions (and the lack of documentation) on the images.
screenshot.PNG.53e95858cb44f02e61ab6e66cb1d430a.PNG
On the fourth image, it says DC 0-30V with a motor(or other consumer) of 5-30V. Why the voltage of the motor has to have atleast 5V is not quite clear to me, maybe because the circuit needs some resistance, to prevent being shorted (and being damaged) ? Either way, the image also shows 3 lines, as opposed to two lines:

  • +
  • -
  • Motor

As i said, not really a electrician ^^ how does that 3-line concept fit into my idea ?

Link to comment
Share on other sites

Link to post
Share on other sites

13 hours ago, shortyluky said:

<bang pow snip>

OK, so here's my take on the whole mess. Well first things first, I think your idea is cool, whats your experience level with this kind of stuff? your expectations should match your acquired skill level. How much work are you willing to do? as far as I'm aware, there is no turn key solution to this sort of thing. How much are you willing to spend on components? I would shoot (pun) for around 50 bucks USD.

 

IOT boot switch!!!

 

Jumping (pun) right in, the 'jumper' interface.... solution, the jumper pins are standard 2.54mm pitch headers (double check me), if your wanting to run your switch in parallel as a redundancy, yes, do it! do it now!

2x2 headers

Jumper wires

So, after a bit of cutting and stripping, you could wire your mobo jumper pins to an off board controller, and connect your switch in parallel off board.

(I'm not even going to try and draw this in paint, use your imagination. I can provided graphics upon request)

 

Switching the jumper.... solution, the jumper pins need to be connected / shorted for at least 50ms to turn the PC on/off, longer just dose a hard shutdown, I think its 8 seconds? so... you have options. you could use a relay, an N channel Mosfet, or what I recommend is a SSR, solid state relay. You can expect to see .5mA across the jumper pins (jacked from Intel), well there about. A single pole, single throw, normally open ssr is right below, its though hole too. Now, the typical forward voltage of this guy is 1.15 volts @ 8mA, so I'm using a 261 ohm resistor. Refer to the image below (assumes 3.3v logic).

solid state relay

image.png.df18057f02bb0d5752ccd35067b45d17.png

resistor

 

Controller board..... solution, I would recommend the 'HUZZAH32' , why? well let me explain. Its 20 bucks USD off the shelf. It has arduino support. It has an integrated lipo charger (alternative power solution btw). its supported by the 'fauxmoESP' library (more on that later). It has great documentation. It comes in black, my favorite color. It has micro usb power + charging + programing. Slap your TLP222A + hacked together wiring harness on the HUZZAH32, and your ready to go fight with firmware.

documentation

 

interfacing with Alexa.... solution, the 'fauxmoESP' library. So what the hell is that? exactly! Using black magic it connects your Huzzah32 board to Alexa. Its more complicated than that, refer to this tutorial here, there's even a sexy video. The linked tutorial goes over an example project with the fauxmoESP library. I'm not going to touch on the firmware bit, it would just take to long, if your interested, quote me and I can give ya a break down or help with your sketch.

 

Powering all the things.... solution... umm yeah a solution, that's really up to you. You have 3? options as far as I can tell.

1.) power it with a USB cable (connector on the board)

2.) power it from an unpopulated USB header on your motherboard. Use a few extra jumper cables I linked above (you get 20), the pitch is also 2.54mm.

image.png.1a8a655054ff471398fac7dac3ce8722.png

3.) hack apart your power supply (not recommended)

4.) use a battery in conjunction with the molex power. If your pc is on more than its off, and you get the right capacity battery, *attacked by math* you should be able to battery operate your IOT switch given your current draw is low and the battery has enough time to charge between power cycles.

 

Your going to need a small prototyping board to solder all your wires and components to, yes soldering, its not that hard if ya have the gear.

 

I hope your project turns out well, let me know if this helped or just pissed ya off.

Link to comment
Share on other sites

Link to post
Share on other sites

Couldn't leave well enough alone. I adapted an adafruit example, hopefully this will give you a good starting point. Assumes the ssr is connected to pin 13 on the esp board. Let me know if it doesn't compile, I really didn't feel like download the ide and setting up the libraries just to test it (the great formatting of 2019).

 

Example/Test Code

Spoiler

   /*
   *  Adafruit sketch modified by keyboardcowboy
   *  IOT computer boot switch, quick and dirty.
   *  6/9/2019
   */
	
    #include <Arduino.h>
    #include <ESP8266WiFi.h>
    #include "fauxmoESP.h"
     
    #define WIFI_SSID "wifi_ssid"
    #define WIFI_PASS "wifi_pass"
     
    #define SERIAL_BAUDRATE 115200
     
    fauxmoESP fauxmo;
     
    #define SSR_PIN 13

    volatile boolean switch_pushed = false; //off by default!
    // -----------------------------------------------------------------------------
    // Wifi
    // -----------------------------------------------------------------------------
     
    void wifiSetup()
    {
      // Set WIFI module to STA mode
      WiFi.mode(WIFI_STA);
     
      // Connect
      Serial.printf("[WIFI] Connecting to %s ", WIFI_SSID);
      WiFi.begin(WIFI_SSID, WIFI_PASS);
     
      // Wait
      while (WiFi.status() != WL_CONNECTED)
      {
        Serial.print(".");
        delay(100);
      }
      Serial.println();
     
      // Connected!
      Serial.printf("[WIFI] STATION Mode, SSID: %s, IP address: %s\n", WiFi.SSID().c_str(), WiFi.localIP().toString().c_str());
    }
     
    void setup()
    {
      pinMode(SSR_PIN, OUTPUT);		//set ssr pin as an output
      digitalWrite(SSR_PIN, LOW);	//set the state low
     
      // Init serial port and clean garbage
      Serial.begin(SERIAL_BAUDRATE);
      Serial.println();
      Serial.println();
      Serial.println("IOT Power Switch sketch");
      Serial.println("After connection, ask Alexa/Echo to 'turn Computer on' or 'off'");
     
      // Wifi
      wifiSetup();
      // for gen3 devices or above
      fauxmo.setPort(80);
      fauxmo.enable(true);
     
      // Fauxmo
      fauxmo.addDevice("computer");
     
      fauxmo.onSetState([](unsigned char device_id, const char *device_name, bool state, unsigned char value) {
        Serial.printf("[MAIN] %s state: %s\n", device_name, state ? "ON" : "OFF");
     
        if ((strcmp(device_name, "computer") == 0))
        {
            // this just sets a variable that the main loop() does something about
            switch_pushed = true; //we don't really care about the 'state' or 'value'
        }
      });
    }
	
    void loop()
    {
      fauxmo.handle();
	  
      //acts as a momentary push button
      if(switch_pushed)
      {
          digitalWrite(SSR_PIN, HIGH); //close the SSR
          delay(250); //wait 250ms
          digitalWrite(SSR_PIN, LOW); //open the SSR
          switch_pushed = false; //reset the state
      }
      //delay(50); //idk if you should pole the handle that often
    }

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

On 6/9/2019 at 7:51 AM, KeyboardCowboy said:

Your going to need a small prototyping board to solder all your wires and components to, yes soldering, its not that hard if ya have the gear.

I'm going to be honest, I already bought the stuff mentioned in my solution and will try it on some garbage pc, to see if it works or everything starts burning ?

But your solution intrigues me, since I wanted to do  project with esp32 stuff anyway and having to do soldering is just the cherry on top (although I've never done that, have to buy some gear probably). I guess i'll try your solution too, since obviosly the green board sucks ?

 

On 6/9/2019 at 7:51 AM, KeyboardCowboy said:

I would shoot (pun) for around 50 bucks USD.

Money ain't the issue on this project, I'm rewarding myself for the finals, by doing some long wanted pc modding ?

 

 

On 6/9/2019 at 7:51 AM, KeyboardCowboy said:

let me know if this helped or just pissed ya off.

Not at all pissed, I'm amazed by how much thought you put into this, thanks dude ?.

I'll post an update when the thing works (or doesn't).

Link to comment
Share on other sites

Link to post
Share on other sites

15 hours ago, shortyluky said:

I'm going to be honest, I already bought the stuff mentioned in my solution and will try it on some garbage pc, to see if it works or everything starts burning ?

Badly drawn guide.

Spoiler

image.png.a0dfb76468bf41b2830489f6f0497229.png

Make sure your in the right mode when you test it, should be momentary.

Quote

Once paired the left button controls the upper relay, the middle button controls the lower relay and the right button toggles the mode for the two relays between the relay action being latch-on, latch-off to momentary. If you cycle power to it, it does seem to remember the last state it was in, which is nice and the way it should be. -amazon review

also it looks like you need to use an app or something before you can pair it to Alexa.

-- Sorry for not initially answering your original question. USB power should also be enough.

Link to comment
Share on other sites

Link to post
Share on other sites

Drum roll please ..........

IT WORKS !

So I ended up buying these 3 items (from the german amazon, but you should be able to find similar items in your regions amazon):
 

The setup is really straightforward:

  1. Cut the power cable extension into 2 pieces, so that you have 2 cables with female headers and 2 cables with male headers.
  2. Remove the insulation from the ends of the cables, so you can intertwine them
    1. Make sure that you intertwine always 1 female header cable with 1 male header cable
    2. You could also solder them, but my soldering station has not been delivered yet (thanks for nothing amazon)
    3. You should now have 2 pieces of cabling, with each 1 female and 1 male header, and and open end, where the cables have been intertwined/soldered
  3. Stick them into the relay like this
    1666758175_NewProject(2).png.9e78a22c5e9fbd4f6cade76c1267736c.png
    1. The order/polarity does not matter here, only where you put the cables in.
  4. Then connect the 2 female headers to the motherboard, where the front panel headers are
    1. You could use an extension cable for this step, since the cut cables are very short and cablemanagement could be a problem
  5. Connect the 2 male headers to the front panel cables
  6. Plug in the micro-USB into the motherboard and then into the relay
  7. Follow the guide on connecting the relay to EweLink and then to Alexa or whatever you want to use
  8. Make sure that the relay in the "momentary" mode and not on "interlock" or "self-lock"

Voila! You should now still be able to use the front panel buttons, while also using some smart dudette to turn on your pc.
You can also use the same procedure for the restart button, just use the second relay this time. This is also why i bought the dual relay version.
Some shrinkwrap might be useful for insulating the cables.

Here are some pics on how i did this in my build: 
Placement on the backside
IMG_20190613_185720.thumb.jpg.7d53c6bbccab8cb7252a41a295b008b9.jpgIMG_20190613_185729.thumb.jpg.dbd687adb9952cdf76f26449e41d8342.jpg

Poorly visible micro usb and front panel connection

IMG_20190613_185741.thumb.jpg.8d69f3b23c3674d243fdbac3765bfffb.jpgIMG_20190613_185738.thumb.jpg.a2645a19f1548ebed3f066d1fec251e0.jpg
I will also upload some video as proof later on.

 

Link to comment
Share on other sites

Link to post
Share on other sites

On 6/13/2019 at 11:40 PM, shortyluky said:

Drum roll please ..........

IT WORKS !

So I ended up buying these 3 items (from the german amazon, but you should be able to find similar items in your regions amazon):
 

The setup is really straightforward:

  1. Cut the power cable extension into 2 pieces, so that you have 2 cables with female headers and 2 cables with male headers.
  2. Remove the insulation from the ends of the cables, so you can intertwine them
    1. Make sure that you intertwine always 1 female header cable with 1 male header cable
    2. You could also solder them, but my soldering station has not been delivered yet (thanks for nothing amazon)
    3. You should now have 2 pieces of cabling, with each 1 female and 1 male header, and and open end, where the cables have been intertwined/soldered
  3. Stick them into the relay like this
    1666758175_NewProject(2).png.9e78a22c5e9fbd4f6cade76c1267736c.png
    1. The order/polarity does not matter here, only where you put the cables in.
  4. Then connect the 2 female headers to the motherboard, where the front panel headers are
    1. You could use an extension cable for this step, since the cut cables are very short and cablemanagement could be a problem
  5. Connect the 2 male headers to the front panel cables
  6. Plug in the micro-USB into the motherboard and then into the relay
  7. Follow the guide on connecting the relay to EweLink and then to Alexa or whatever you want to use
  8. Make sure that the relay in the "momentary" mode and not on "interlock" or "self-lock"

Voila! You should now still be able to use the front panel buttons, while also using some smart dudette to turn on your pc.
You can also use the same procedure for the restart button, just use the second relay this time. This is also why i bought the dual relay version.
Some shrinkwrap might be useful for insulating the cables.

Here are some pics on how i did this in my build: 
Placement on the backside
IMG_20190613_185720.thumb.jpg.7d53c6bbccab8cb7252a41a295b008b9.jpgIMG_20190613_185729.thumb.jpg.dbd687adb9952cdf76f26449e41d8342.jpg

Poorly visible micro usb and front panel connection

IMG_20190613_185741.thumb.jpg.8d69f3b23c3674d243fdbac3765bfffb.jpgIMG_20190613_185738.thumb.jpg.a2645a19f1548ebed3f066d1fec251e0.jpg
I will also upload some video as proof later on.

 

Nicely done dude. Sorry i didn't reply to your questions, I was really busy over the past few weeks.

Link to comment
Share on other sites

Link to post
Share on other sites

  • 1 year later...
On 6/9/2019 at 7:51 AM, KeyboardCowboy said:

OK, so here's my take on the whole mess. Well first things first, I think your idea is cool, whats your experience level with this kind of stuff? your expectations should match your acquired skill level. How much work are you willing to do? as far as I'm aware, there is no turn key solution to this sort of thing. How much are you willing to spend on components? I would shoot (pun) for around 50 bucks USD.

 

IOT boot switch!!!

 

Jumping (pun) right in, the 'jumper' interface.... solution, the jumper pins are standard 2.54mm pitch headers (double check me), if your wanting to run your switch in parallel as a redundancy, yes, do it! do it now!

2x2 headers

Jumper wires

So, after a bit of cutting and stripping, you could wire your mobo jumper pins to an off board controller, and connect your switch in parallel off board.

(I'm not even going to try and draw this in paint, use your imagination. I can provided graphics upon request)

 

Switching the jumper.... solution, the jumper pins need to be connected / shorted for at least 50ms to turn the PC on/off, longer just dose a hard shutdown, I think its 8 seconds? so... you have options. you could use a relay, an N channel Mosfet, or what I recommend is a SSR, solid state relay. You can expect to see .5mA across the jumper pins (jacked from Intel), well there about. A single pole, single throw, normally open ssr is right below, its though hole too. Now, the typical forward voltage of this guy is 1.15 volts @ 8mA, so I'm using a 261 ohm resistor. Refer to the image below (assumes 3.3v logic).

solid state relay

image.png.df18057f02bb0d5752ccd35067b45d17.png

resistor

 

Controller board..... solution, I would recommend the 'HUZZAH32' , why? well let me explain. Its 20 bucks USD off the shelf. It has arduino support. It has an integrated lipo charger (alternative power solution btw). its supported by the 'fauxmoESP' library (more on that later). It has great documentation. It comes in black, my favorite color. It has micro usb power + charging + programing. Slap your TLP222A + hacked together wiring harness on the HUZZAH32, and your ready to go fight with firmware.

documentation

 

interfacing with Alexa.... solution, the 'fauxmoESP' library. So what the hell is that? exactly! Using black magic it connects your Huzzah32 board to Alexa. Its more complicated than that, refer to this tutorial here, there's even a sexy video. The linked tutorial goes over an example project with the fauxmoESP library. I'm not going to touch on the firmware bit, it would just take to long, if your interested, quote me and I can give ya a break down or help with your sketch.

 

Powering all the things.... solution... umm yeah a solution, that's really up to you. You have 3? options as far as I can tell.

1.) power it with a USB cable (connector on the board)

2.) power it from an unpopulated USB header on your motherboard. Use a few extra jumper cables I linked above (you get 20), the pitch is also 2.54mm.

image.png.1a8a655054ff471398fac7dac3ce8722.png

3.) hack apart your power supply (not recommended)

4.) use a battery in conjunction with the molex power. If your pc is on more than its off, and you get the right capacity battery, *attacked by math* you should be able to battery operate your IOT switch given your current draw is low and the battery has enough time to charge between power cycles.

 

Your going to need a small prototyping board to solder all your wires and components to, yes soldering, its not that hard if ya have the gear.

 

I hope your project turns out well, let me know if this helped or just pissed ya off.

@KeyboardCowboy Thanks for providing your detailed solution. Due to the pandemic situation, I need to remotely power on/off my pc. Therefore, I would like to give your suggested solution a shot. Unfortunately, most links are broken. Could you update them please?

Kind regards

Link to comment
Share on other sites

Link to post
Share on other sites

  • 2 years later...

Just search Alexa relay.

To turn PC on wire it into the PC on switch. 

For turning off PC create a webserver and a shutdown script. Alexa can activate the script to shut down the PC properly.

If you're interested in a product please download and read the manual first.

Don't forget to tag or quote in your reply if you want me to know you've answered or have another question.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×