Sunday, January 27, 2013

Air con remote control success

After yet more hacking, I've stuck together just enough code to think I want to go and find a proper home automation framework.

I've got weather-util installed on a cron job doing:
0 * * * * weather ypad ~/butler/weather.txt

This gets me a small text file:
$ cat weather.txt 
Current conditions at Adelaide Airport, Australia (YPAD) 34-56S 138-31E 4M
Last updated Jan 26, 2013 - 11:30 PM EST / 2013.01.27 0430 UTC
   Temperature: 73 F (23 C)
   Relative Humidity: 46%
   Wind: from the SW (230 degrees) at 14 MPH (12 KT)
   Sky conditions: mostly clear
The first argument is an airport identifier. Next, I've used Blather to pull together a quick XMPP bot. It supports commands like
!ac on
!ac cool
!ac temp 23
!ac off
!weather

!weather just pipes the weather.txt back to whomever messaged the bot.

The !ac commands invoke some of the code to send commands to the air conditioner I talked about earlier.

Finally, the bot checks the configured owners for all Auth, and if it hasn't seen you in 8 hours, says hello.

It's far from the cleanest code I've ever written, and Blather is good but needs that little bit more to become "the rails of XMPP". Most importantly here though, I'm a little bit of regex away from writing some simple rules (IFTTT style), and adding the relevant cronjobs. The rules are going to be fairly terse:
while temp > 30; turn on AC

while temp < 25; turn off AC

I'd say if I did much more I'd want to refactor a lot of stuff to be more componentized - IE: jabber notification service when a decision is made doesn't need to be right next to the jabber command service.

I can't decide if I'd want to bring in something like Whenbot, or deal with something as complicated seeming as rhouse. Rhouse (linuxMCE) has a lot of UPnP stuff built it, but annoyingly the samsung smart devices are only using a subset of it - my phone notifies, the air con notifies back; rather than properly using M-SEARCHs.

Having spent a lot of time on this, I suspect that would be quite annoying to work with.

The next step I'll probably do is a further cleanup of my nmap code - when my phone's mac address walks in the door, the butler-bot should message me a greeting / fire up the AC decision engine.

Finally, I have to stick this on it's production server - my new raspberry pi.

More than happy to share the code I've got with anyone interested, it's in a few private bitbucket repos for now - I figured there would be few people with the same setup as I have; so kept it private (at least till I can make it into a few gems)...

No comments: