Building a home automation system – Power control (Part 3)

Just got myself a RFXtrx433 USB transceiver from RFXcom. It’s a tiny box which allows you the communicate with a wide range of home automation hardware that uses the 433 MHz band, check out the impressive list of supported hardware on their website. There is one store in Norway that sell these, and guess what, it’s in Strandgaten here in Bergen (walking distance) – http://www.smarthus.info/

There’s a guy named Kevin that have been working a nodejs library for it, available here: node-rfxcom. He’s made support for events and triggering of most of the protocols – it’s is under active development at the moment. It works quite well here for lighting2 equipment (Nexa / Home Easy based). I added support for lighting1 events (ARC – older protocol – uses code wheel), since it seems that Nexa still sell some equipment using this (the single wall button in my case).

So far I’m only using cheap Nexa plug-in modules and wall buttons, which seem to work well enough, but the plug-in modules aren’t exactly pretty. A lot of the lighting in my apartment is also hard-wired (halogen spots in the roof, no sockets), so sooner or later I’m going to have to get some real built in modules. This has to be done by a certified electrician and I want to be sure that I go for the right technology. I got a tip that insteon is planning on releasing european modules soon(tm), these are mesh-networked (bonus!). And since every receiver is also a sender/repeater I’m hoping they can be queried: “Hello lighting module A, what is your current dimming level?”

Anyway, I have the RFX unit up and running as a service on my home automation message bus now, so now it’s finally possible to subscribe for events from transmitters (ex: wall switch) and send orders to receivers (ex: plug in modules connected to lights). Subscribing to the coffee-machine and turning it off after 60 minutes, or turning off several lights/appliances if the last-man-out button near the exit door is pressed can now be done by:

Gist – 3923421

Now I need to find some suitable PIR (passive infra-red) motion sensors to use with the system, and also try to research which in wall technology to go for in the future – so that I can control more of the lighting here at home.

Flocking / Synchronization

There are a few behaviors in nature that seems really advanced, impressive and organic, that actually can be simulated on a computer using only a few simple rules. One of them is flocking – the “formation”-flying of birds or movement of schools of fish. There’s an old algorithm/simulation by Craig Reynolds called Boids (often used in screensavers and even used for modeling the flying bats in batman) that explains this pretty well. Make a few objects that react to their neighborhood according to the following three simple rules:

  • Separation – try to stay at least x units away from all neighbours.
  • Alignment – try to match the average direction of your neighbours.
  • Cohesion – steer towards the center location of your neighbours.

Flocking in paper.js

Click on the image above for a live demo 🙂

Implement the rules and depending on how you weight them you quickly get behavior that looks impressively organic. Was bored the other evening, and my coding fingers are itching since I’ve barely gotten to do any programming at work these last months – the meeting/planning vs programming ratio is through the roof. So I did a quick implementation for shits and giggles. Check it out here: http://goo.gl/eY8KY (or click the image above). I have no idea if it works with all browsers, but works with chrome at least.

There’s also a decent TED talk on the subject:

What’s it going to be used for? Notting really, but might be useful to know if I ever get to chance to program a large army of hunter killer robots with swarm capability.

The Shell – zsh, dotfiles, etc.

I decided to go for zsh again (instead of bash) as a default shell not that long ago. I’ve used it on and off before, it’s really powerful, but takes a lot of configuration to get access to all the nice features it offers. Whenever i reinstalled or changed computers I usually just returned to the de-facto bash shell.

These days configuration/plugin/themes collections like oh-my-zsh and the more recent fork prezto makes it really easy to get a a fully functional and good looking zsh up and running real quick. Git clone oh-my-zsh or prezto, activate the plugins you’re after and you got it 🙂

Zsh syntax highlighting

There are a few external plugins I really like as well – for example zsh-syntax-highlighting seen above. Clone and add to plugin list as describes. It offers similar shell syntax highlighting as the fish shell.

Oh, and the theme used above is from agnoster. Pretty minimal while giving a lot of information – using the powerline fonts (a series of patched fonts – a favorite among many vim users.) They’ve added pretty symbols to indicate things like branches, background jobs, root, etc. Looks a bit messy below, but that’s mostly because i wanted to try to show as many features as possible in the least amount of space.

Powerline

Works really well in iTerm2. The terminal to use if you’re on OS X.

I try to keep my dotfiles on github, that way it’s pretty easy to move between machines and keep them up to date. Nice to have access to all your aliases and settings on the machines you’re using. And whenever you’re on a new mac, to avoid going mental, just apply your collection of sane mac defaults. (“natural” scrolling my ass :p) 🙂

There are some pretty awesome collections of dotfiles on github – some worth checking out: holman’s, mathias’ and even whole projects like: dotfiles.github.com