Jump to content

Automatically turn on PC when power is back?


prathapml
 Share

Recommended Posts

Here's the situation.

I live in an area where the electricity supply is highly unpredictable. Power might blackout for only 2 minutes, or there might be a 7-hour powercut in a single day without any warning. So one of my home machines is supplied by an APC 650VA UPS (for power regulation and backup, with USB monitoring, pretty decent for home). The UPS is capable of giving backup power to this PC for 20 mins. I have configured 'Power Options' to turn off monitor in 2 mins, and to put the computer into 'Sleep' mode if its running on battery for more than 5 mins.

All of this has been fine so far, but lets say I want to call this PC my download machine (because of low power consumption). Now at this point, two concerns arise. One, to power off the PC in time in case of a powercut, which is taken care of by Windows' own Power Options. Two, the PC needs to 'sense' when the power (mains, AC power) is back, and turn on and get back to where it was.

That second concern is what is seeming quite complex right now. I can confirm that the APC UPS (link to specs underlined) pretty much works like a laptop battery, which means it can inform the OS when power is off and power is back. But if the PC is 'put to sleep' during a powercut, there is no OS sitting there to realize that the power is back! So I went looking in the BIOS, for a way to turn on the PC, but all it seems to offer is "Power State after power failure" with the options "Off, On, Last State". But this option is relevant only if I don't already have a UPS to manage the power situation (thank heavens, else the electricity issues here would have killed my PC long ago). I'm trying to automate this because these power failures happen all too often in a single day, and at daytime I am usually not at home to turn the PC on manually.

Therefore, that's where I'm stuck. I mean, powercut happens, PC goes into sleep mode. Power comes back, PC is still stuck in sleep mode. I'm looking for a way to somehow wake it up automatically when power is back. If you think there's a solution, please do post here, just about any suggestion is welcome. I'm hoping someone has an idea about this.

Link to comment
Share on other sites


A question:

How do you get the PC "out of sleep" or "turn it again on" manually?

I mean, by pressing "any key", by "left or right clicking" the mouse, by pressing the "on/off" button of the case (I am assuming the PC has an ATX supply), or how?

jaclaz

Link to comment
Share on other sites

Hi jaclaz,

You are right, the PC has an ATX power supply. I turn it back on manually through either pressing the on/off button of case, or by pressing the "Wake up" key on my keyboard (standard feature in no-name multimedia keyboards with 115 keys). The BIOS offers options to wake up by pressing any key on keyboard or by a mouse-click, but I've currently disabled that option, because I felt that people at home might accidentally wake up the PC when I actually want it to sleep. But I could enable that option if it can somehow automate the wakeup procedure when power comes back.....

Link to comment
Share on other sites

Remember that I am much more on the "electromechanical" side than on the "electronics" one when it comes to technical knowledge, but most probably what I am suggesting is also the simplest workaround, possibly an smallish electronic circuit based on the same idea could be easily made.

Get two wires out of the PC connected parallel to the on/off switch button, let's call them "switch" wires.

Get two wires out of the PC connected to 0 and +12V (as an example from a floppy or HD connector), let's call them "power" wires.

Have TWO relays, first with 240 V AC coil and second with 12 V DC coil.

Connect the two "switch" wires out of the PC to the normally open contact of first relay.

Connect the coil of first relay to mains (outside of the UPS) through a normally closed contact of second relay.

Connect the coil of second relay to the "power" wires.

I hope the above is clear enough, if you need I can draw a small schematics for it.

The principle is the following:

1. mains go out

2. mains returns, the coil of first relay is attracted, "virtually" pressing the power button

3.the ATX power gives +12 V, thus attracting the coil of second relay, which makes first relay go back to "open"

4. when mains goes out again (loop to 1. above) the 12V go out, closing the circuit to the coil of first relay, thus making it ready to send a "pulse" to the power switch when mains will come back

You will have the (very little) power consumption at the +12 V level when the PC is switched off as a side effect.

A capacitor may be needed to allow for some "wait" and avoid possible "bumps" due to mains going out and back in a very short time. :unsure:

jaclaz

Link to comment
Share on other sites

@jaclaz-That sounds like a marketable item.

Mark

It's not... for a very simple reason. What's to guarantee that the PC would turn on? What if the power was back and a 2nd pressing of the power button was required? As the idea is presented, if power was restored and the relays actived (essentially pressing the power button) and the PC was still off, there would be no 2nd pressing of the button, the button would just stay stuck to ON.

Link to comment
Share on other sites

@jcarle

Yep, but of course, designing a very small electronic board with a minimal "intelligence" and able to "loop" checking for the PC being on would be easy.

My post was just a basic idea of how this can be made the "poor man's" way, with something that you may find in your backyard "laboratory" in your preferred junkyard, or even in the litter bin. ;)

jaclaz

Link to comment
Share on other sites

Am I missing something here? Prathapml, have you tried the "On" option in the BIOS? I don't have the BE650's, but in my office we have Smart-UPSs (SUA1500RM2U), and I set up a schedule where each night they automatically shutdown the servers, then turn themselves off. Before we arrive in the office the following day, the UPSs turn back on, and in turn the servers turn back on as well because I set the BIOS option to "On" after power fail.

The Power State after Power Failure will react even if the OS was shut down properly because power failure on motherboards occurs if the motherboard loses power, not the OS. That's why you have a "Last State" option - if the PC was already off, leave it off... if it was on, turn it back on.

Give the ON option a shot and see how that works out.

The only scenario where this won't work is if the Battery Backup shuts your PC down, but the power comes back on before it shuts itself off. Since the computer hasn't lost power, the Power Failure option won't kick in.

Edited by rendrag
Link to comment
Share on other sites

.....because power failure on motherboards occurs if the motherboard loses power....

....Since the computer hasn't lost power, the Power Failure option won't kick in.

Thanks rendrag, but thats exactly the problem in this case. The PC/motherboard never does truly "lose power" because it only goes into sleep mode, and even then the UPS is supplying it with power 24 hours a day.

I might have to do it the way jaclaz is suggesting, it does seem workable. But then I'm lazy and wonder if there's an easier way to do it, through software or something? :P

The PowerChute software that comes with the APC UPS does not seem to offer any such functionality. So I then looked to see whether I could use Wake-On-LAN signals from my other desktop can solve this (the other desktop has a really huge battery to back it up, but its graphics card is power hungry so can't use it as download machine). But WOL only seems to work if the PC to be "woken up" is switched off or hibernated. The "sleeping" PC isn't able to be woken up, because as far as the network card knows, the PC is already "awake". Moreover, since I won't be at home, I need to send WOL signals over the Internet to my DSL router, which will forward the same to the sleeping PC, but WOL-over-Internet works very spottily if at all it works. And in any case, I have no way of knowing when power comes and goes if I'm not at home, plus WOL would again make this a manual way of doing it.

Link to comment
Share on other sites

How soon after a power outage do you have the APC shut your computer down? If it doesn't run all the way down, then as you've noticed, it rides out the outage. If you have it run all the way down, it shouldn't have enough power to ride out the outage and should shut off... that will create the power failure your PC needs to see to have the BIOS option kick in

Link to comment
Share on other sites

I have an idea... if you like to do a bit of wizardry...

If you use a router, such as the Linksys WRT54GL, which gives you access to an SSH session, then you can login to your router and do work from there. It's possible to add a serial port to the WRT54GL (the PCB traces are there, you just need to solder a header). Using the serial port, you could attach a small serial controlled switch which you could attach to your PC. So, once everything was setup, you could something like "1) Login to your router using SSH then 2) run a command such as 'hitpower' that would flick the serial switch."

Link to comment
Share on other sites

That sounds like a marketable item.

No. You don't want the hands of any average consumer near 240 volt mains! And any basic screw-up on their part (a single wire wrong) and they can fry their PC or worse (death is very much a possibility here, and you could easily be sued over it). And there are regulations and laws to respect when it comes to selling such items. It would have to be something safe, with proper protection/isolation/grounding/etc.

It's not... for a very simple reason. [snip]

There's plenty more reasons. Say, if you ever want to turn off/shut down your computer. This would automatically restart it. Then all kinds of issues possible in case of power bumps, brownouts and what not.

Yep, but of course, designing a very small electronic board with a minimal "intelligence" and able to "loop" checking for the PC being on would be easy.

Well, making a truly good product wouldn't quite be that easy for most people. Instead of just relays, some might be tempted to go with logic gates, timers and what not, but in the end, the best way to do it is using a microcontroller which would monitor the power and act accordingly. But still... Think protection against transients, isolation (and safety in general), perhaps monitoring when the user presses the power button to shut the PC down (and even then -- what about when you go start > shutdown? it couldn't know for sure; you'd likely have to just assume, seeing the PC turned itself off, without losing mains power). And then *good* code for the power monitoring during various events which most people couldn't easily simulate themselves... And you have to keep in mind not all countries use 240 volt power either (e.g. all of north america). There's a LOT of things that comes in play here.

(I work with embedded systems for a living)

I have an idea... if you like to do a bit of wizardry...

If you use a router, such as the Linksys WRT54GL, which gives you access to an SSH session, then you can login to your router and do work from there. It's possible to add a serial port to the WRT54GL (the PCB traces are there, you just need to solder a header). Using the serial port, you could attach a small serial controlled switch which you could attach to your PC. So, once everything was setup, you could something like "1) Login to your router using SSH then 2) run a command such as 'hitpower' that would flick the serial switch."

That's a pretty good idea, but it could be even simpler. If you have a WRT54GL, I'd hunt down a MIPS version of the "wol" binary (or compile one yourself). Then I'd schedule (cron job) a shell script that would ping the box say, every 5 minutes, and if it's not responsive, send a "magic packet" to it using the said wol binary (of course WOL must be enabled in your BIOS). Nothing to build/modify/hack/connect or anything. Only takes a couple minutes to setup, and it's real easy to test (once you get the wol command line right, try a simple script, then setup the cron job, turn PC off, and see if it kicks in/works).

Link to comment
Share on other sites

That's a pretty good idea, but it could be even simpler. If you have a WRT54GL, I'd hunt down a MIPS version of the "wol" binary (or compile one yourself). Then I'd schedule (cron job) a shell script that would ping the box say, every 5 minutes, and if it's not responsive, send a "magic packet" to it using the said wol binary (of course WOL must be enabled in your BIOS). Nothing to build/modify/hack/connect or anything. Only takes a couple minutes to setup, and it's real easy to test (once you get the wol command line right, try a simple script, then setup the cron job, turn PC off, and see if it kicks in/works).
That's a pretty good idea but there's a simple flaw in the cron job, doing a voluntary shutdown would have the machine wake up by the cron job five minutes later. I'd take your idea and simply suggest that the wake on lan binary be scripted with the proper parameters in a batch file (do they have batch files in linux?) that could be executed via an SSH login.

ie: Box is down, log in to the router using SSH and then run the WOL batch file.

If you want to get really creative, you could execute the WOL directly from the router's web interface if you modified, say, the administration page that's served by the internal web browser.

Link to comment
Share on other sites

doing a voluntary shutdown would have the machine wake up by the cron job five minutes later

I completely forgot about that one. Yes, you can script things (not using batch files though), but it might be tricky to make a script "know" when you actually mean to wake the machine or not.

One could get pretty creative, and make the computer reconfigure the router (sending commands over telnet or ssh, or deleting/creating/renaming a file over SCP/FTP or such which the script would look for before sending magic packets) on a voluntary shutdown so it doesn't send the magic packets anymore (not until you re-enable it when booting up).

SSH or telnet or the web interface works fine for WOL, but that's not automated unfortunately, he'd have to keep checking periodically if the box is up, and waking it up manually.

I don't think there's an easy answer unfortunately.

Edited by crahak
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.


×
×
  • Create New...