Author Topic: Bridge Amazon Echo to Vera, on github!  (Read 413617 times)

Offline arm

  • Sr. Newbie
  • *
  • Posts: 29
  • Karma: +12/-2
Bridge Amazon Echo to Vera, on github!
« on: April 23, 2015, 11:20:39 pm »
Howdy Folks,
Wanted to give you guys a sneak preview of my Amazon Echo to vera bridge.  It basically emulates a Phillips Hue gateway using UPNP and a subset of the Hue Api.  It runs on a R PI!

https://github.com/armzilla/amazon-echo-ha-bridge

Arm


Offline Z-Waver

  • Master Member
  • *******
  • Posts: 4370
  • Karma: +238/-118
Re: Bridge Amazon Echo to Vera, on github!
« Reply #1 on: April 24, 2015, 08:16:31 am »
What is the command flow?
I'm thinking it would be something like this?

Echo uploads voice sample.
Amazon processes voice or sends to Nuance.
Amazon issues Hue command. (Transmitted command or file stored on Amazon servers?)
RPi reads command from Amazon. (API or todo list hack?)
RPi sends HTTP Get to Vera.

Offline integlikewhoa

  • Master Member
  • *******
  • Posts: 5402
  • Karma: +144/-299
Re: Bridge Amazon Echo to Vera, on github!
« Reply #2 on: April 24, 2015, 05:59:03 pm »
IF YOU ARE JUST STARTING YOUR JOURNEY IN THIS 136+ PAGE THREAD PLEASE READ BELOW AND  THEN START FROM THE END!

Alot has changed since this thread has started. Arm and his Armzilla version kicked this thread off and it was then pushed even further buy Crush157 and his crush version. It has added a great web UI with easy to use settings, Harmony Hub, Nest support, Dimming and much much more.

There has been many updates and the changes. The change log and versions can be found through out the thread with the latest ones towards the end. They can also be found here.
https://github.com/bwssytems/ha-bridge/releases

Altho Arm hasn't been around in the last several months, thanks for kicking this off and also a big thanks to Crush for his updates and continued support.
« Last Edit: September 13, 2016, 08:32:15 pm by integlikewhoa »

Offline arm

  • Sr. Newbie
  • *
  • Posts: 29
  • Karma: +12/-2
Re: Bridge Amazon Echo to Vera, on github!
« Reply #3 on: April 24, 2015, 07:01:59 pm »
What is the command flow?
I'm thinking it would be something like this?

Echo uploads voice sample.
Amazon processes voice or sends to Nuance.
Amazon issues Hue command. (Transmitted command or file stored on Amazon servers?)
RPi reads command from Amazon. (API or todo list hack?)
RPi sends HTTP Get to Vera.

Since the Echo already supports wemo and the Philips Hue I simply wrote something to a fake a Hue gateway.
The Echo does the following to turn on a Wemo device or a Hue bulb:
  • Echo sends out a UPNP discovery request over multicast
  • The Wemo/Hue responds back with a URL for the service descriptor
  • Echo reads the service descriptor and stores that on device
  • When the Echo detects the keyword "Alexa, turn on my <device name>" it looks up the discovered device and changes it state

I initially reverse engineered a Wemo device (went to homedepot and bought ONE), however that could not emulate multiple devices like a Philips Hue Bridge could.  Eventually i settled on emulating a Philips Hue and whenever i would receive a state change request i would turn around and make a luup request.

I am in the process of improving the vera device registration on my bridge app as right now it is a face only an api mother could love.

e.g. inserting a device with a vera id of 41

POST http://host:8080/api/devices
{
"name" : "bedroom light",
"deviceType" : "switch",
  "onUrl" : "http://192.168.1.201:3480/data_request?id=action&output_format=json&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=1&DeviceNum=41",
  "offUrl" : "http://192.168.1.201:3480/data_request?id=action&output_format=json&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=0&DeviceNum=41"
}

let me know if anyone is curious to try

video soon

cheers,
arm

Offline integlikewhoa

  • Master Member
  • *******
  • Posts: 5402
  • Karma: +144/-299
Re: Bridge Amazon Echo to Vera, on github!
« Reply #4 on: April 24, 2015, 08:38:14 pm »
What do we need to begin testing?
ECHO..... Check
Vera..... Check

Apple, peach or Rasberry Pie.... checked the fridge nothing?

Any recommendations/requirements for this project? Is it non API pro friendly?


EDIT: Pi2 work or only the original Pi?
« Last Edit: April 24, 2015, 10:43:26 pm by integlikewhoa »

Offline arm

  • Sr. Newbie
  • *
  • Posts: 29
  • Karma: +12/-2
Re: Bridge Amazon Echo to Vera, on github!
« Reply #5 on: April 24, 2015, 11:21:42 pm »
What do we need to begin testing?
ECHO..... Check
Vera..... Check

Apple, peach or Rasberry Pie.... checked the fridge nothing?

Any recommendations/requirements for this project? Is it non API pro friendly?


EDIT: Pi2 work or only the original Pi?

I have it running on a raspberry pi 2, however since it is java you can run it on anything!
You can fetch the current runnable jar from https://github.com/armzilla/amazon-echo-ha-bridge/releases (currently requires java8).  The github page has some instructions to get you started.


Offline integlikewhoa

  • Master Member
  • *******
  • Posts: 5402
  • Karma: +144/-299
Re: Bridge Amazon Echo to Vera, on github!
« Reply #6 on: April 25, 2015, 01:58:53 am »
What do we need to begin testing?
ECHO..... Check
Vera..... Check

Apple, peach or Rasberry Pie.... checked the fridge nothing?

Any recommendations/requirements for this project? Is it non API pro friendly?


EDIT: Pi2 work or only the original Pi?

I have it running on a raspberry pi 2, however since it is java you can run it on anything!
You can fetch the current runnable jar from https://github.com/armzilla/amazon-echo-ha-bridge/releases (currently requires java8).  The github page has some instructions to get you started.

How could I run this on a windows 8.1 Sever (using it for Blueiris and PLEX media servers right now always on) with Java 8 update 40 on it. IP 192.168.1.100

Offline Z-Waver

  • Master Member
  • *******
  • Posts: 4370
  • Karma: +238/-118
Re: Bridge Amazon Echo to Vera, on github!
« Reply #7 on: April 25, 2015, 08:20:25 am »
Since the Echo already supports wemo and the Philips Hue I simply wrote something to a fake a Hue gateway.
The Echo does the following to turn on a Wemo device or a Hue bulb:
  • Echo sends out a UPNP discovery request over multicast
  • The Wemo/Hue responds back with a URL for the service descriptor
  • Echo reads the service descriptor and stores that on device
  • When the Echo detects the keyword "Alexa, turn on my <device name>" it looks up the discovered device and changes it state
This more than implies that this is entirely local and that there isn't a plethora of traffic and processing between Echo and Amazon. While that is certainly my desire, I very much doubt that this is the case with Echo, or ever will be.

Can you confirm that this is all local and internet free, or did you simply choose to 'pay no attention to the man behind the curtain'?

Offline arm

  • Sr. Newbie
  • *
  • Posts: 29
  • Karma: +12/-2
Re: Bridge Amazon Echo to Vera, on github!
« Reply #8 on: April 25, 2015, 03:22:09 pm »
Since the Echo already supports wemo and the Philips Hue I simply wrote something to a fake a Hue gateway.
The Echo does the following to turn on a Wemo device or a Hue bulb:
  • Echo sends out a UPNP discovery request over multicast
  • The Wemo/Hue responds back with a URL for the service descriptor
  • Echo reads the service descriptor and stores that on device
  • When the Echo detects the keyword "Alexa, turn on my <device name>" it looks up the discovered device and changes it state
This more than implies that this is entirely local and that there isn't a plethora of traffic and processing between Echo and Amazon. While that is certainly my desire, I very much doubt that this is the case with Echo, or ever will be.

Can you confirm that this is all local and internet free, or did you simply choose to 'pay no attention to the man behind the curtain'?
Did some leg work for you.  Captured traffic at the router to see the Echo's communication to the outside world.  Please poke any holes you see with my test methodology.

https://youtu.be/CFz15cIvoB0

Offline Ramias

  • Sr. Member
  • ****
  • Posts: 275
  • Karma: +7/-5
Re: Bridge Amazon Echo to Vera, on github!
« Reply #9 on: April 25, 2015, 05:34:31 pm »
ok I have it working now and was even able to upload info for my kitchen light but Alexa says she is unable to discover any connected devices.  Here is the command line I use to start this on a Windows box:

java -jar -Djava.net.preferIPv4Stack=true amazon-echo-bridge-0.1.0.jar --upnp.config.address=192.168.0.14

No host firewall turned on.  I can get to the web page for it from other machines on my network just fine.  When I browse to http://192.168.0.14:8080/api/devices it shows me:

Code: [Select]
[{"content":[{"id":"401e39c9-4bac-48f9-99e7-82145ba30c85","name":"kitchen light","deviceType":"switch","offUrl":"http://192.168.0.70:3480/data_request?id=action&output_format=json&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=0&DeviceNum=126","onUrl":"http://192.168.0.70:3480/data_request?id=action&output_format=json&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=1&DeviceNum=126"}],"facets":[],"totalElements":1,"totalPages":1,"size":1,"number":0,"last":true,"sort":null,"numberOfElements":1,"first":true}]
This is on a wired machine.  Tried again with the Jar on a wireless laptop; same issue.  Alexa can't discover it.
« Last Edit: April 25, 2015, 05:43:01 pm by Ramias »

Offline arm

  • Sr. Newbie
  • *
  • Posts: 29
  • Karma: +12/-2
Re: Bridge Amazon Echo to Vera, on github!
« Reply #10 on: April 25, 2015, 06:12:07 pm »
ok I have it working now and was even able to upload info for my kitchen light but Alexa says she is unable to discover any connected devices.  Here is the command line I use to start this on a Windows box:

java -jar -Djava.net.preferIPv4Stack=true amazon-echo-bridge-0.1.0.jar --upnp.config.address=192.168.0.14

No host firewall turned on.  I can get to the web page for it from other machines on my network just fine.  When I browse to http://192.168.0.14:8080/api/devices it shows me:

Code: [Select]
[{"content":[{"id":"401e39c9-4bac-48f9-99e7-82145ba30c85","name":"kitchen light","deviceType":"switch","offUrl":"http://192.168.0.70:3480/data_request?id=action&output_format=json&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=0&DeviceNum=126","onUrl":"http://192.168.0.70:3480/data_request?id=action&output_format=json&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=1&DeviceNum=126"}],"facets":[],"totalElements":1,"totalPages":1,"size":1,"number":0,"last":true,"sort":null,"numberOfElements":1,"first":true}]
This is on a wired machine.  Tried again with the Jar on a wireless laptop; same issue.  Alexa can't discover it.

can you post (or PM) the logs generated when you ran the device discovery?
I am looking for something like

upnp device settings requested:
hue lights list requested:

Offline Ramias

  • Sr. Member
  • ****
  • Posts: 275
  • Karma: +7/-5
Re: Bridge Amazon Echo to Vera, on github!
« Reply #11 on: April 25, 2015, 06:33:17 pm »
What logs?  Just the output to the console when I execute Java?

I dumped that to a text file but did not see the strings you posted.

What ports other than 8080 do/does this need on my host machine?

I had to stop the SSDP Discovery Service on Windows to free up 1900 UDP (that Java then took when I relaunched it) but I suspect there are more.

Offline arm

  • Sr. Newbie
  • *
  • Posts: 29
  • Karma: +12/-2
Re: Bridge Amazon Echo to Vera, on github!
« Reply #12 on: April 25, 2015, 07:11:25 pm »
What logs?  Just the output to the console when I execute Java?

I dumped that to a text file but did not see the strings you posted.

What ports other than 8080 do/does this need on my host machine?

I had to stop the SSDP Discovery Service on Windows to free up 1900 UDP (that Java then took when I relaunched it) but I suspect there are more.

There is a unicast/udp port that the app binds to to respond back to the SSDP discovery, default is 50000. You can override using the parameter --upnp.response.port=PORT however i dont think this is the case because the app should have bailed if there were any port conflicts. 

Can we try adding the following parameters to see if we are getting ssdp discovery packets?
--logging.level.com.armzilla.ha.upnp=DEBUG --logging.file=ha.log

Offline Ramias

  • Sr. Member
  • ****
  • Posts: 275
  • Karma: +7/-5
Re: Bridge Amazon Echo to Vera, on github!
« Reply #13 on: April 25, 2015, 07:12:02 pm »
AWESOME

Ok, I decided to try this on my Mac.  Had to first install Java then the actual JDK to launch this from the Mac terminal command line.

Added my one device like I always do.

IT WORKS.  I can turn on and off the kitchen lights with voice from my Echo.

I also see the upnp device settings requested and hue lights list requested in the console logs.

So... there's an issue with this running on Windows. I suspect it is a port issue with a standard Windows service taking up the port.

But that also means I may have an issue running this on the same Windows Server I run Plex on if I have DLNA enabled with Plex.

Offline arm

  • Sr. Newbie
  • *
  • Posts: 29
  • Karma: +12/-2
Re: Bridge Amazon Echo to Vera, on github!
« Reply #14 on: April 25, 2015, 07:13:35 pm »
AWESOME

Ok, I decided to try this on my Mac.  Had to first install Java then the actual JDK to launch this from the Mac terminal command line.

Added my one device like I always do.

IT WORKS.  I can turn on and off the kitchen lights with voice from my Echo.

I also see the upnp device settings requested and hue lights list requested in the console logs.

So... there's an issue with this running on Windows. I suspect it is a port issue with a standard Windows service taking up the port.

But that also means I may have an issue running this on the same Windows Server I run Plex on if I have DLNA enabled with Plex.

awesome!, let me spin up a vm to test the windows scenario.

Arm