Playing around with Amazon Echo (technical interface discussion)

At least 1 person has figured it out

That is amazing. I like that he only had to ask for Smart Things once.

Funny part is I watched this video on my MacBook sitting next to my Echo. My Echo kept trying to respond to his “Alexa
” commands. LOL

2 Likes

Right
 Because he “opened” the SmartThings Echo App. How many such Apps can be open concurrently?

1 Like

I can not think of any. I tried “Open I Heart Radio” and it just started playing my last station.

It appears what they are doing is;

You can “Open” an app, then alexa is “in it” - and she asks you a question, your answer goes to the open app.
If you don’t answer, it closes the app - and you are back to talking to the echo and not the app
If you do answer, your answer goes to the app - so if you say something the app doesn’t know about, it’ll make a sound like “cant help you”

One app open at a time.

You used to also be able to say “exit appname”, but they’ve changed it so a bit of silence will auto exit apps.

yeah, pepbill - that’s the video I started the thread with
 I guess the thread is long enough that it needed re-posting :smile:

1 Like

So
 it’s fairly easy to make an emulated Hue bridge using Node.js, and using that and a smart app that provides a OAuth web interface to your lights, you can fool the Echo into thinking your Smartthings dimmer switches are Hue bulbs. At least that’s what I hope. I’ve got to test it still with the echo, but if it works I will be able to control my lights with the echo.

The Hue emulator works great. I can turn off/on lights and change their brightness using the Hue API, and my emulator shows up as a Hue Bridge during upnp discovery.

Assuming the Echo is discovering the Hue hub via upnp, and then using the local web api for the hue, of course. If not, then this will just go into the “I learned how to do upnp servers in node” pile of useless knowledge :smile:

If it does work, I can post up some code.

3 Likes

[quote=“schettj, post:47, topic:14887”]
If it does work, I can post up some code.
[/quote]It doesn’t yet work. Echo doesn’t seem to like my upnp response to its discovery

Sorry to rain on your parade, buddy, but but this would be a direct violation of Philips Hue API licensing terms. SmartThings better be careful not to approve any such app or they may end up with a lawsuit on ther hands.

1 Like

“We want all your apps to work with our API to form a rich ecosystem of
interoperable applications, so it is a condition of access to our API
documentation that you do not use it to develop or distribute any
bridges or devices which interpret the hue API in order to control
physical devices. Emulators are allowed provided they only control
virtual bulbs”

So
 yeah. That’s kinda odd - guess I won’t put that code out since that’s what I had working today.

Turning attention to emulating the WeMo bulbs. They’re just upnp devices.

I guess Google and Oracle (Sun Microsystems) are still in court or appealing, to determine whether or not “copying an API” (i.e., the API to various Java libraries) is a copyright violation.

If you don’t use the documentation to build an emulator, then you’ve not agreed to any license
 technically. But that would be a difficult task.

Good news, I was able to get my Echo to see an emulated Hue bridge that has access to all my SmartThings devices! Luckily someone over on the Vera forums already had a similar idea and did all the heavy lifting, so I just did a few very minimal tweaks for it to work with SmartThings. This should work with Windows/Mac/or a Pi since it’s using Java.

Here’s the URL for the forum post:
http://forum.micasaverde.com/index.php/topic,31920.html

These are the steps I took to get it up and running on Windows 7:


Prerequisites

Setup a REST Endpoint Smartapp and select the devices you would like your Echo to be able to turn on/off (endpoint Smartapp from this tutorial)

  • Download and install Java 8

  • Download the JAR file (this is the Hue bridge emulator)

  • Make sure ports 8080, 1900, & 50000 are not in use on your machine. Run each of the following from CMD:

netstat -ano | find “8080”
netstat -ano | find “1900”
netstat -ano | find “50000”

All three of them should come back with no results. If it does come back with any PIDs kill the processes before continuing.

Run the Hue bridge emulator

From CMD, run the following (add the full path of the JAR and edit the IP)

java -jar -Djava.net.preferIPv4Stack=true C:\ENTER\THE]FULL\PATH\HERE\amazon-echo-bridge-0.1.1.jar --upnp.config.address=192.168.X.X

Add a new device to the Hue bridge emulator

  • Next you need to send an HTTP POST. You can either use the POSTMAN Chrome plugin or the I’m Only RESTing HTTP client (instructions are for the latter)

  • Open the I’m Only Resting app and set the method as POST

  • In the URL field enter in the following with your IP:

http://192.168.XX.XXX:8080/api/devices

  • Copy/paste the following text into the Headers box:

X-Application-Context: application:8080
Transfer-Encoding: chunked
Date: Sat, 09 May 2015 12:14:21 GMT
Server: Apache-Coyote/1.1
Content-Type: application/json; charset=UTF-8

  • Edit the name, onURL, & offURL below with the name you would like the Echo to discover the new device as, and the onURL & offURL from the REST Endpoint SmartApp:

{
“name” : “coffee maker”,
“deviceType” : “switch”,
“onUrl” : “http://graph.api.smartthings.com/api/smartapps/installations/XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXX/switches/XXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXX/on?access_token=XXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXX”,
“offUrl” : “http://graph.api.smartthings.com/api/smartapps/installations/XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXX/switches/XXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXX/off?access_token=XXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXX”
}

  • Copy/paste the edited text above into the Body section

  • This is what it should look like:

  • Hit Submit. You should see a response showing that the new device has been created.
  • LAST STEP! - Tell Alexa “Alexa, discover my devices” and you should now have the new device controllable by the Echo

Rinse & repeat the POST for any additional devices you want to be discoverable by the Echo.

13 Likes

So
 digging thru the code, they’re not emulating HUE, they’re emulating WeMo - or some odd combo of the two. They respond to the UPNP discovery as a WeMo bridge


HTTP/1.1 200 OK\r\n" +
"CACHE-CONTROL: max-age=86400\r\n" +
"EXT:\r\n" +
"LOCATION: http://%s:%s/upnp/amazon-ha-bridge/setup.xml\r\n" +
"OPT: \"http://schemas.upnp.org/upnp/1/0/\"; ns=01\r\n" +
"01-NLS: %s\r\n" +
"ST: urn:Belkin:device:**\r\n" +
"USN: uuid:Socket-1_0-221438K0100073::urn:Belkin:device:**\r\n\r\n"

But the setup.xml they act like a Hue bridge.

 "<friendlyName>Amazon-Echo-HA-Bridge (%s)</friendlyName>\n" +
 "<manufacturer>Royal Philips Electronics</manufacturer>\n" +
 "<manufacturerURL>http://www.armzilla..com</manufacturerURL>\n" +
 "<modelDescription>Hue Emulator for Amazon Echo bridge</modelDescription>\n" +
 "<modelName>Philips hue bridge 2012</modelName>\n" +
 "<modelNumber>929000226503</modelNumber>\n" +
 "<modelURL>http://www.armzilla.com/amazon-echo-ha-bridge</modelURL>\n" +

Most unusual.

2 Likes

Nice work, +nelemansc! I was able to get the emulator to work (sort of) with my Echo. The biggest challenge was killing the Windows UPnP services so that port 1900 was available.

After doing a device discover with Echo, I see the devices that I configured in the emulator in the Echo Web UI. Some of them worked for on/off commands and some just didn’t. I configured 7 devices to start.

All in all, it’s a great start.

1 Like

There’s a Web UI? I thought Echo’s only GUI was the mobile (iOS and Android) Apps
?

Yeah. I don’t think Amazon is doing a very good job of publicizing it, but if you have an Echo try browsing here: http://echo.amazon.com/#cards

I discovered this interface and have to use this to play my preferred itunes stations. I like a few stations from East Coast but Echo doesn’t find them because it only looks at local stations for some reason.
I have sent this in as an issue. When I ask for a Station I want to be able to add region the station exists for the search.

Funny part is once I set a east coast stations I can say “Alexa, play iheart radion” and it says “Playing last station played and works fine I just can’t change stations unless they are local”

1 Like

This is awesome!

Unfortunately I screwed it up. Anyone know if it’s possible to delete or modify added devices, I got this working on my iMac server got a few added, but screwed one up and to pile on top of my problems in my poor attempt to troubleshoot added some duplicate devices. If not delete devices, how can I start over? I removed the jar file and redownloaded it, also cleared the Connected Homes setting on the echo but the previously added ones are still showing up.

Obviously there is something silly that I’m missing here.

1 Like

I ran into the same issues as you did. I discovered that you can use the Echo Web UI to delete devices that you have configured through the emulator and start over. The connected home devices are listed under Settings->Connected Home. Here are the steps you need to go through to start over. I’m using Windows, so the steps may vary for another OS:

  1. Stop the emulator java app.
  2. The emulator creates a data directory in the same directory as the jar when you start it up. Delete that directory and the associated sub-directories. No need to delete or download the jar again.
  3. Delete your Connected Home settings from the Echo UI.
    4, You are now ready to start over.
3 Likes

Thank you tyuhl! I appreciate the detailed response :thumbsup: