Home Automation and HA Bridge
Home Assistant and HA Bridge
Today I decided to get home-assistant voice activated with my Amazon Echo. There are multiple ways of doing this, but I chose the easiest and laziest for now.
What does it enable me to do?
“Alexa, turn on my living room lights”
My living room lights turn on and Alexa says “Okay”.
“Alexa, turn on my Apple TV”
My Harmony Hub turns on my Samsung TV, Onkyo A/V receiver and Apple TV. The Onkyo changes the HDMI input to the Apple TV. Alexa says “Okay”.
“Alexa, turn on sexy time”
All the lights in the house turn off, except the bedroom lights which turn red. Yeah, this is a thing. All I need now is for some Barry White to stat playing and I have a real creepy scenario complete! Oh and Alexa says “Okay”.
So let’s take a quick look on the pieces needed to begin. I won’t go into detail on everything you can do, just what you need to know to get going.
Requirements
- A computer of some sort, I use a Raspberry Pi running Raspbian.
- An Amazon Echo
- A working installation of home-assistant on the computer
- A working installation of ha-bridge on the computer
There are many ways to configure this…again, I’m going for simple. You can work out the rest yourself.
How does this work?
Here is the secret sauce that makes the magic happen:
- The Amazon Echo listens to my voice commands
- The Amazon Echo can turn on, off or dim Philips Hue lights
- HA-Bridge can pretend to be a Philips Hue bridge
- HA-Bridge can send instructions to other systems
- HA-Bridge fools the Amazon Echo into thinking that it is controlling lights when in fact it’s controlling whatever we want
The only downside is that we’re restricted to “turn on”, “turn off” and “dim” commands. But, we’re going with simple so it’ll do for now.
Show me
Okay, you want a full example. Let’s take a look at getting a simple light to turn on and off.
In home-assistant I have set up my LimitlessLED (also known as Easybulb) lights.
platform: limitlessled
bridges:
- host: 10.0.0.5
version: 5
port: 8899
groups:
- number: 1
type: rgbw
name: Office
- number: 2
type: rgbw
name: Living Room
- number: 3
type: rgbw
name: Kitchen
- number: 4
type: rgbw
name: Bedroom
Now when I run home-assistant I can see those in my interface and interact with them by flicking the ‘switch’.
Home-assistant very kindly exposes all of your devices over a REST API with a nice and simple syntax. Note that I have HTTPS enabled and an API password.
# Turn on the lights
curl -X POST -H application/json -H X-HA-Access:API_PASSWORD -d '{"entity_id":"light.office"}' https://my-pi:8123/api/services/homeassistant/turn_on
# Turn off the lights
curl -X POST -H application/json -H X-HA-Access:API_PASSWORD -d '{"entity_id":"light.office"}' https://my-pi:8123/api/services/homeassistant/turn_off
Let’s take a look at how to set up HA-Bridge to talk to those lights.
Open up the Manual Add
tab in the HA-Bridge web interface:
For more information on the REST API we will call, check out the HA help documentation
Using the example URL’s above we enter in the following details:
==Name==: Whatever you want to say to Alexa, e.g. “Office Lights”
==Device Type==: Custom
== On URL==: https://my-pi:8123/api/services/homeassistant/turn_on
== Dim URL==: Blank
== Off URL ==: https://my-pi:8123/api/services/homeassistant/turn_off
== HTTP Headers ==: [{"name":"X-HA-Access", "value":"API_PASSWORD"}]
==HTTP Verb==: POST
==Content Type==: application/json
==Content Body ON==: {"entity_id":"light.office"}
==Content Body OFF==: {"entity_id":"light.office"}
Now press “Add Bridge Device” and HA-Bridge will now be ready to let Alexa discover it. Open your Alexa mobile app or open up The Amazon Echo Smart Home page and Discover devices.
Alexa will pick up your newly created bridge device as a Philips Hue light and make it available for voice activation. I use lights, scripts, scenes and more. As long as I can ‘turn on’ and ‘turn off’ then I’m voice activating it.
Try as I might, I can’t get Alexa to turn on my fiancé though.
Boom.