Small steps to an autonomous future

Wed, Mar 30, 2016

Summary: Every morning my lights turn themselves on, along with my amplifier which begins playing a random song off my wake up playlist.

My current setup is a Raspberry Pi B+ with a HiFiBerry DAC+. The pi runs Home Assistant for home automation (lights, plugs, scripts), with Mopidy and Mopify providing the music and user interface.

My home assistant dashboard looks like this:

Blackstock Home Assistant

While the pi looks like this:

Raspberry pi and rf chips

This is actually my older pi model C from 2011, without the HiFiBerry DAC attached. The breadboard and chips are used to communicate with the remote control RF plug sockets. This tutorial by Tim Leland provides the starting point. WiringPi and pinout are useful to get the right pinouts.

I bought 5 pairs of 433Mhz RF Transmitter module + receivers for £4.50 from amazon, the breadboard and cables were a pound each, and 10 remote control plug sockets from ebay for £35.

After connecting up the RF module and installing Tim's RFSniffer module, by using the remote control for the plugs we can sniff the 433Mhz codes it is sending to each plug and note them down.

Once we've got the codes for each plug, we then use the codesend module from Tim's code to send out each individual on/off trigger.

You can see the codes as home assistant command switches in my home assistant configuration file:

oncmd: "/var/www/rfoutlet/codesend 29955 offcmd: "/var/www/rfoutlet/codesend 29964

Controlling the music from home assistant is done in a rather inelegant way. Mopidy has an api - the many front ends communicate with it usually using the javascript api. However, you can also post to it with JSON - the API details are here.

So, my morning music script can be seen in this gist. After the Home Assistant automation script turns on the uplighter, fairy lights and amplifier, what it is doing is:

  1. Clearing the mopidy tracklist
  2. Adding playlist using the Spotify identifier - to find, right click on a song or playlist and select ‘copy Spotify URI’*
  3. Set to random
  4. Begin playing

The future

I'd like to implement more scenes and automation rules, as well as setting up Owntracks for location tracking. At present we see if people's phones are connected to the network to check if they are home, which is not that effective a solution.

Scoring MEPs in the European Parliament