Smart(er) Home – Knowing when the power is out

One of the benefits of a smart home system is knowing that everything is okay when we are not at home. We live in an area with a very high water table and have water in our sump pump year round. Over the past ten years in the house there have been 3 sump pump fails, but only one resulted in a bad flood. I needed a way to know if the power has gone out. Yes, there are battery backups, and I will invest in one at some point, but for now just getting an early warning will do. It was time to come up with some technology to solve the problem.

I thought of ways that I can use a RaspberryPi to monitor the sump crock water level, but if the power goes out, the internet goes out, and the notification will not be sent. To get around this I wrote a small script that will ping my router. If it is offline, then the script will look at our local power companies outage page to see if there are reported outages on our street. If there is an outage it will use Pushbullet to send a notification to my phone to tell me that the power is out, how many customers on my street are impacted, and a time that it is expected to be restored. Now I have an early warning that there may be a problem, and I can head home to address it. I put the script together in Bash, however I may move it to Python at some point.

OUTAGE_URL={URL for the Power Company outage page for my town}
STREET=(My Street}
USERS_TOTAL=`grep (My Street} savedFileName.html | cut -d '>' -f5 | rev | cut -c 5- | rev`
USERS_OUT=`grep (My Street} savedFileName.html | cut -d '>' -f7 | rev | cut -c 5- | rev`
ETA=`grep (My Street} savedFileName.html | cut -d '>' -f9 | rev | cut -c 5- | rev`

# Test to see if home internet is up
if [ $? ] = 0 then
echo "Internet is Up, Power is alive"
`wget $OUTAGE_URL`
#if curl -s "$OUTAGE_FILE" | grep -q "$STREET"
if grep -q "$STREET" $OUTAGE_FILE
echo "Users Out: $USERS_OUT"
echo "Power Expected Back: $ETA"
# curl -s -u $PUSHAPI -d type=note -d title="Power May be Out" -d body="Users Out: $USERS_OUT ETA: $ETA"
echo "I have the POWER"

I have this running on a VPS that I have purchased for a few dollars a month to play with. Sometimes the internet will stay up in a power outage, and my servers and modem are plugged into a UPS, but for peace of mind it is better to run this offsite. Over the past year I have had 1 false positive, but there were two times that this saved our basement from a flood. I had ample time to get home, hook up the generator and keep things dry.


I bring my MacbookPro with me to work everyday. I normally do not have a password on my screensaver, but I work with some pranksters that may want to mess with me while I am away from my desk, so I want to lock it down when I walk away. I have found a useful combination of apps that will get this done for me with very little work.

Marco Polo is a neat little bit of software that will tell you machine to do different things based on current status. For example you can have it enable the screensaver password when you are connected to the Wi-Fi at work, and disable the password requirement when you get back home. The software looks at a variety of factors called Evidence, which can be a WiFi connection, a specific program running time of day and so on. Then based on the evidence it finds changes determines the machines Context like Home or work. Based on the context you can set of different rules or actions to take place.

I have set 2 contexts on my machine Home and Work, based on the time of day. I would have liked to use WiFi as my rule, however MarcoPolo does not appear to see Hidden SSID’s which my work network is. So I opted to go with the Time of Day Rules and put in my work schedule, which will set the context to Work. When the context is set to work, I have MarcoPolo enable the screensaver password and launch the application Proximity.

Proximity is a small app that looks for a paired Bluetooth device and runs an Applescript for in range and another for out of range. There are several posts on the interwebs where people have gotten cell phones to sync contacts, check email and a whole host of other things. All I want it to do is activate my screensaver when I walk away and turn it off when I come back.

The activation script is fairly easy, with Script editor enter the following code Pretty straight forward, it will turn on the screensaver which is password protected – locking my Mac from pranking or snooping co workers.

tell application “ScreenSaverEngine” to activate

Now getting my mac to automatically unlock when I get back was a bit tricker. Since the screensaver is password protected I have to get the password entered.

tell application “System Events”

keystroke return

delay 1

keystroke enter your ScreenSaver password here

delay 1

keystroke return

end tell

This will type the password and “press” ok to unlock the screensaver.

It is pretty straight forward and easy to set up, and offers a bit of extra securityto my Mac when I am at work. Since I don’t need the extra protection at home MarcoPolo turns off the screensaver password quits Proximity.

With these two little programs I have a automatic way to boost the security on my macbook when I am at the office, never a bad thing to have

iTunes Auto Importing/Syncing

— UPDATE —  Well Apple you have finally fixed this up for me with iTunes 9.  Between the new Home Sharing feature that was widely talked about and the little tidbit of the “Automatically Add to iTunes” folder that was put in my automator actions are pretty much not needed.  I may tweak them so it will copy new music to the “Auto Folder” from one mac to another.

I tested this out today and it works like a charm, happy day.

We have 2 Macs at home and 2 iPods, and a fairly large music collection.  I like to maintain the same music collection on the 2 Macs, but sometimes I buy a song on my laptop, my wife rips a cd on the iMac and keeping the collections in sync is a pain.  I figured out a way that works well for me to Automagically keep things in sync using Automator and iCal plugins.  I created a workflow that will look at the iTunes music folder for anything that was added today and then copy the songs to my server.  After creating and testing the workflow, I saved it as an iCal plugin that runs every night.

Searches iTunes Music Folder and copies to server
Searches iTunes Music Folder and copies to server

This works great on the iMac that is at home with the server which is pretty much always mounted.  However, if the server is not mounted there was an error in the workflow as there was no place to copy the files to.  Automator to the rescue!  I made another workflow that will mount my server, and I have this set up to run first in iCal. I tried to do this all as one workflow, but it would never work correctly.  I will continue to play with it and see if I can get it all as one workflow.

This Workflow will connect to the server if it is not mounted
This Workflow will connect to the server if it is not mounted

So, now the iMac is automatically mounting my server, and copying any new music to it.  How to get this new aural goodness to my MacBook.  Since iTunes does not monitor folder (maybe in iTunes 9, please) I have more Automator voodoo to take care of it for me.

Workflow looks at the server and imports new tracks to iTunes
Workflow looks at the server and imports new tracks to iTunes

I started with the script to mount my server as my MacBook is not at home most of the time.  Then I have a second script that will look at the New Music folder on the server (that is target for the iMac workflow), and if it finds and Audio files that were added today, it will import them into iTunes.  You can choose a specific playlist or just to the iTunes library.  So far this is working really well for getting the new music from the iMac to the MBP.  I will be writing a second batch of workflow to go the other way (From MBP to the iMac).  If all goes as planned I will not have to manually manage the music between the machines.

I will update with any issues that I run into as time goes by…

–edit – fixed images —

2 macs 1 backup

I became a mac user a bit over a year ago when my windohs box finally died.  I wanted something new and easier so off the the Apple Store we went.  I purchased a 20″ iMac, and the world was a happy place.  Sometime later my windohs laptop mainboard went sizzle and I needed a new laptop.  My wife, how by the way is super cool headed off the the Apple Store and got me the machine I wanted.  Correction she got me a better machine that what I had decided on.  I was going to be happy with a 13″ MacBook, the wife (did I mention that she was super cool) got me the fully loaded 15″ MBP.  Mike was happy, and still is.  So now we have 2 happy Macs and I want a way to back up and sync files between the pair.

I looked at the Apple Time Capsule – great features, not so great on the price.  1TB at the time was $499, and I couldn’t quite do all that I wanted to. FreeNas was looking pretty good as a low overhead option, and I had a bunch of parts laying about to build a system.  I did not have a vast amount of storage, but was able to try it out as a Time Machine backup.  This set up worked well, but still was not all that I was looking for.  So after much looking I stumbled across this post on how to make a server using Ubuntu, netatalk and avahi.  It was promising and since I have some knowledge of Ubuntu, not too difficult.  I ordered a new small form factor case, an Intel Atom mb/cpu combo and a hard drive and it was off to the races.  I have been running this set up for a few weeks now and it is working great.  In later posts I will talk about some of the things that I am doing with it, and some of the custom configs that I am doing to make this a great option for syncing 2 macs 🙂