Home automation should be cheap. The IoT should be an Internet of Cheap Things.
I bought a 1st Gen Lifx bulb from Amazon during their Christmas blitzkrieg sale for $35. The Amazon Echo can control the Lifx bulb using a “skill”. Amazon’s cloud talks to the Lifx cloud and sends a command to the bulb. But to control it, you have to say things like “Alexa, tell Lifx to turn on the bedroom lights”. That’s not exactly easy to remember at 2am if I wake up and just want to turn on the light…
I want to be able to say “Alexa, turn on the light” And, it would be nice if the automation depended less on the Amazon and Lifx clouds. The brains and control of home automation should be in the home.
The Echo supports local home automation switches like the Belkin wemo. Fauxmo is a wemo emulator written in python. Golifx is a Lifx bulb controller written in Go. Putting these together, it’s easy to build a quick Echo->Fauxmo->Lifx bulb switch that runs on Linux and lets me say “Alexa, turn on the light”
All you need is:
- python and golang installed
- fauxmo.py python script
- golifx binary:
go get -u github.com/pdf/golifx/cmd/lifx
- Some changes are needed for fauxmo.py to run the lifx program
- add import os to the list of imports at the top of the script
- Choose a high numbered port, and set the line that says self.port = 55555 (or some other available high port)
This is required so that fauxmo stays on the same port – otherwise the Echo won’t be able to find it when it restarts.
- Find the lines below and modify them similarly to below. Note that the paths will be different for you. So, fix the paths.
These modifications just add a system command to run the lifx executable using two bash scripts.
Although I have not done this yet, it should be possible to remove the request / response object and just have the on() and off() return true
def on(self): # r = requests.get(self.on_cmd) # I'm not sure how to create a response object without a request # so this is just a bogus request to a local webserver r = requests.get("http://localhost/") # you need to create the on.sh and off.sh scripts cmd="/home/username/home_automation/golifx/bin/on.sh" os.system(cmd) return r.status_code == 200 def off(self): #r = requests.get(self.off_cmd) r = requests.get("http://localhost/") cmd="/home/username/home_automation/golifx/bin/off.sh" os.system(cmd) return r.status_code == 200 # add the new device called "light" FAUXMOS = [ ['light', rest_api_handler('on', 'off')], # COMMENT OUT the two examples in the FAUXMOS array #['office lights', rest_api_handler('http://192.168.5.4/ha-api?cmd=on&a=office', .. #['kitchen lights', rest_api_handler('http://192.168.5.4/ha-api?cmd=on&a=kitchen',.. ]
- Create on.sh and off.sh – these are simple bash scripts that run the lifx executable.
They are also referenced in the changes made to fauxmo.py above, so be sure the paths are correct.
The paths in the scripts will need to be changed to suit your environment.
- The on.sh script:
#!/bin/bash # on.sh cd "$HOME/home_automation/golifx/bin" export GOPATH="$HOME/home_automation/golifx" ./lifx light power on
The only difference in the two scripts is the last word.. on or off
After you create the scripts, chmod them to 755 (executable)
- The on.sh script:
- Run ./fauxmo.py -d (debug mode) and watch the output.
- Say, “Alexa, discover devices”
- Amazon Echo should say it found one device, and fauxmo.py should say what it’s doing as well.
- Try saying “Alexa, turn on the light” and “Alexa turn off the light”. If all is working, she will say “okay” and the light will turn on/off.
- When you are satisfied that things are working, run ./fauxmo.py & at system startup.
More to do:
- The lifx bulb brightness and color can be controlled too!
- Rather than the lifx binary, any linux command could be issued.
- “Alexa turn on the service” – start any linux service
- “Alexa turn on the system check” – run some scripts to check a series of things and generate a report.
- “Alexa turn on the emergency alert” – send an email / sms / tweet
- “Alexa turn on the device” – integrate some other device, or IoT controller of whatever.