This is part 3 for my guide on how to control cheap wireless power outlets using a Amazon Echo and a Raspberry Pi. Part 1 covered Siri and HomeKit. Part 2 covered the Google Home which I plan on improving since ha-bridge works with Google Home. This tutorial assumes you already setup the outlets.
Currently the Amazon Echo does not support controlling devices within your network if they are not a supported device. Luckily for us a great open source project called ha-bridge solves this issue. Ha-bridge works by emulating the Philips Hue api to other home automation gateways such as an Amazon Echo or Google Home. It can handle basic commands such as “On”, “Off” and “brightness”. It’s pretty amazing how they were able to reverse engineer the hue api. Ha-bridge is primarily written in Java and has a web interface.
- If you haven’t already be sure to follow my guide on setting up the cheap wireless power outlets to work with a raspberry pi.
- Login to your raspberry pi terminal and create a directory for ha-bridge
mkdir habridge
&&
cd habridge/ - Download jar file for ha-bridge (Latest release)
wget https://github.com/bwssytems/ha-bridge/releases/download/v3.5.1/ha-bridge-3.5.1.jar
- Install java and wait….
sudo apt-get update && sudo apt-get install oracle-java8-jdk
- Run the jar executable
sudo java -jar -Dserver.port=80 ha-bridge-3.5.1.jar
- If you get an error message like: “java.net.BindException: Address already in use“, then you need to change your port for ha-bridge.
sudo java -jar -Dserver.port=8080 ha-bridge-3.5.1.jar
- If you are running apache, follow these steps if you want to change it and run ha-bridge on port 80
- In a web browser, go to your pi’s ip address. http://192.168.1.11:80. If you are using a custom port, be sure to change change :80. You should now see the ha-bridge gui interface
- Click on Manual Add and follow the example below. When choosing Execute Script/Program, the program path needs to in the On Url/Off Url input
- Be sure to use your outlet codes and add the device
- Click on My Echo to open up your amazon echo configuration page.
- Click on Smart Home then Discover devices. Your echo will search for the ha-bridge and should discover your device
- You should now be able to tell Alexa to turn on or off the lamps
If you would like to have ha-bridge start automatically, follow my guide to setup Systemctl. Below is my service config to start ha-bridge.
[Unit] Description=HA Bridge Wants=network.target After=syslog.target network-online.target [Service] Type=simple ExecStart=/usr/bin/java -jar -Dserver.port=80 /home/pi/habridge/ha-bridge-3.5.1.jar Restart=on-failure RestartSec=10 KillMode=process [Install] WantedBy=multi-user.target
Please let me know in the comments below if you have any questions or feedback.
Thanks for reading. Make sure you follow me on Twitter to stay up to date on the progress of my side projects T.LY, Weather Extension, and Link Shortener Extension. If you are interested in the tech I use daily, check out my uses page.
i still haven’t gotten my 315Mhz outlets to work with codesend etc… but this tutorial worked perfectly with the weird solution i currently have in place.
thanks Tim!
Awesome! habridge is really neat.
Hi Tim
We may have a need to control a specific Ceiling Fan (with Lamp) – which itself has a IR remote controller to switch / adjust speed and lamp ON/OFF control.
Logitech Harmony Hub has IR and is compatible with Echo – do u think the Logitech Harmony can learn fan IR remote codes ?
Regards
Are you able to capture the rf codes from the ceiling fan remote? If so, you should be able to set the harmony remote to ha-bridge. Currently I have the light button on my harmony remote controlling my lamps.
Hi Tim
The fan is a Infrared controlled appliance.
Is the Harmony remote you mentioned same as a Harmony Hub ?
Please advise.
Thanks
Yes this is the one I have http://amzn.to/21yl5Ay
Hey Tim,
Does this solution work if I were to want the HA Bridge to send the command to a different IP address? The reason I ask is that even when extending the RF range with a wire like you mentioned, I can’t really cover the whole house.
My thought is to duplicate the hardware from the one Raspberry Pi Zero W and just blast the RF from a 2nd or 3rd point…but I’m not sure I’d need to run multiple HA Bridge installs. I would think I could direct the command to the specific IP address of each Pi in the bridge settings but I’m not sure which protocol to use. I never could get the “http:///rfoutlet/” solution to execute the scripts so I’m thinking perhaps that is the problem to solve first and then figure out how to get the HA Bridge to execute an HTTP command to trigger the switches.
Hey Andy, yes I think you could send a command to additional pi’s. I don’t think you would have to run multiple versions of HA. You just need 1 pi that acts as the hub and sends messages to the other pi’s. The easiest way would probably be using http. Get the web version working first. Let me now if you have any questions.
I have this same issue with getting my signal to all of my devices in my house wiring. I don’t have room in my panel to bridge the phases either. I was trying this approach you mentioned in having two ha-bridge services replicated on two different PI’s. This doesn’t seem to be successful so far. I don’t follow on how to send from the one to the second the commands. Did you overcome this or find a workaround? Any insights you can offer or point me to would be greatly appreciated.
Hello Tim, your posts have been very informative nice and clear.
I took quite a while trying to get a fauxmo version running but didn’t quite get there. So I’ve followed your instructions (I think) quite closely but I’m at the same point as I am with the fauxamo version. Everything seems to be running but Alexa can’t discover any devices.
Any clues as to what may be wrong?
Thanks
I’m not familiar with fauxamo. Were you able to get ha-bridge setup?
Sorry I wasn’t that clear. I managed to get ha-bridge set up.
The UPNP discovery listener running and ready message comes up …so all good..
but if then if I asked the echo to discover devices it would say none found…looking at the terminal window on the PI it would be active with messages but nothing from the address of the Echo. I set up fauxmo and that did similar in that it appeared to work and said it was replying to the Echo when I said discover but again the Echo failed to find any devices..
However that was yesterday and I tried everything to get it to work and must have tried to discover devices a hundred times and reboots etc
Today I start ha-bridge and ask The echo to discover and it found a LUX Light device straight away . I’m not sure what the lux light is but it must be my PI as it calls it Lamp1 which was the title I gave it.
Nothing has changed since yesterday and I had already booted it numerous times . So I’m completely stumped as to why it now works… Still as long as it keeps working I’ll be happy..
Thanks for responding and the implied offer of assistance.. Great article ..
Great! Glad you got it working
Hi Tim,
Another great post – thank you!!! I have this set up and working with my Pi-controlled outlets now. Another benefit of this is it allows you to control and monitor the state of your outlets through the Alexa app from outside your network.
Thanks!! Glad you found it helpful
great project works well
I used a pi zero w and loaded with Turnkey image for the wifi hotspot and setup features
then added the ha-bridge works with amazon echo dot
setup systemctl to auto start works well
would like to leave 5 minute delay before starting to configure wifi if at a different location
have had no sucsess as yet
thank you Tony
Thank you Tim
Found a solution
sudo crontab step to end and type
@reboot sleep 300 && sudo java -jar -Dserver.port=80 /home/pi/habridge/ha-bridg$
do not set up as *.service on bootup
Now Save Ctrl+X
I can relocate pi and Amazon to another location
powerup Turnkey default hotspot will come up
logon to hotspot
change wifi credentials it will send you an email with its ip if you can not find
reboot wait 5 mins http// to ip and connect to HA-Bridge