Save power with automatic wake on lan
Computers can use a lot of power depending on the computer and what it’s used for. I have two at home, one thats a power-house gaming machine, and the other is a file server with 11 drives in it. These two machines always being on can add a good $70-100 dollars to my electric bill, but it’s just not very convenient to have to always turn these computers on and off (particularly the file server which sits in my closet).
If only there was a way these computers could turn on and off automatically!
Luckily there is and it involves (1) smart phone (an iphone in my case), (1) netbook (or any low power device, even a router, arduino, etc), (X) wake on lan capable computers, and (1) home network.
The base concept is my computers don’t need to be on when I’m not home or asleep and when I am home, they should be on.
The two scenarios that need to know if I’m home or not are easiest to solve by checking whether or not my phone is connected to the wifi network by pinging it. What I have set up is a little rails app that runs on my low powered netbook (which is always on) that constantly checks to see if my phone is connected and decides whether or not to turn things on or off, it’s my “Mission Control” app as I call it.
The logic with turning things on or off is:
- If phone is connected, and computers are off, turn on
- If phone is not connected for >= 15 and computers are on, turn computers off
This is the script I put together that incorporates the above logic in the Mission Control rails app:
https://gist.github.com/1562959
You may be questioning a couple things in the script like, what does Machine.alive?, sleep, and wake actually do? They are the functions in the Machine model that ping the machine to see if it’s alive and tell it to go to sleep or not.
http://gist.github.com/1563033
You may notice that I’m ssh’ing into a Windows machine and the reason for that is I have ssh setup with cygwin. The alternative to this would be to shut down via RPC command, but I could only get it to turn completely off, not hibernate which was what I needed in order to utilize wake on lan.
I also mentioned a third scenario, going to sleep, how is this accomplished? Going to sleep is an override of the logic that is in checker.rb. In the machine control rails app, there is a simple mobile site using jquery mobile that shows that status of machines and has a simple sleep/wake button (there is a shake to refresh if you have Mission Control setup).
If you wanna check out the code or even set this up for yourself it’s up on Github. The rails app may actually be a little overkill. Everything it does can be accomplished in a bash script, but I intend to build it out some more, maybe include some XBMC integration or some more advanced control.
