Introduction:I would like to be able to turn on/off PC by just switching on/off the switch on power extension cord with switch.
http://en.wikipedia.org/wiki/File:Socket_5.jpg
Turning on is simple - just switch on the power extension switch !

The issue is with turning off - all PCs needs some time to shut down properly

This idea is similar to the way how UPS communicates with PC in case of power failure.
My assumptions:- arduino will control the relay module which will power PC
- arduino will be connected to mains by power adapter and to PC with USB
- power cord switch will switch on/off the arduino power adapter not the PC
- arduino will auto-select the power source between power adapter and USB
My idea:1. Turning PC on:
a) switch on arduino power adapter
b) arduino starts and by default puts relay to ON mode and PC boots up
2. Turning PC off (this is tricky part and I'm not sure if it will work at all)
a) switch off arduino adapter
b) arduino switch itself to USB power source using built into board auto-select functionality
c) arduino "senses" that power adaptor is switched off
d) arduino sends message over USB (serial) to PC to power itself off
e) arduino goes into sleep for the time needed for PC to shut down
f) arduino wakes up (at this point PC is already down)
g) arduino set relay to OFF mode
My questions:ad. (2b) - will arduino switch silently to USB power after switching off power adaptor or it will shut down ? reboot ? or maybe is there some shield which allows for safe switching between power sources ?
ad. (2c) - how to do it ? is there a way to read some register in memory or something similar to get information what type of power source is currently used - USB or power adapter ? or maybe I can check the voltage on the power jack and pass it to arduino pin and measure in this way ?
ad. (2d) this is fine, should be quite easy, just need to write some script which will wait for such message on PC and if received power PC off
ad. (2e) this step is optional as some PC will after shut down power off all USB ports - in this way arduino will just switch off and relay will go to OFF mode
ad. (2f) only if PC is not powering off USB ports arduino will wake up and set relay into OFF mode