Playing around with Amazon Echo (technical interface discussion)

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:

Wow, so I got my version to work - indeed the Echo discovery is looking for belkin/wemo but once discovered will use the Hue API (bizzarro!) so if your emulator can map your lights/switches to hue lights, the Echo discovers them all and you can do on/off/dimming - sweet.

2 Likes

I hope ST and Amazon don’t consider this a final solution :slight_smile:

Not likely.

But the bigger question is whether or not Amazon and SmartThings want and decide to directly partner up, or if both would rather let the developer community just integrate through the open platform features.

Clearly Philips Hue has a “premiere” status, so some partnership was arranged. Amazon and ST could totally ignore this option for a long time.

That’s perhaps “good news” for independent developers for both fun and a slight possibility of profit, but, not optimal for end-users.

The smoothness of the premier integration is hard to beat. But would be impossible with the V1 hub, assuming the Echo is doing all this in the local network space - we all fool it into working by running servers on the local network that then bridge out to the ST cloud.

Anyway - open is good. I still want to do more than the basic stuff this can do. I want to ask Echo about the status of the house. It’s not able to comply using the current device integration.

OK I got this working on my Macbook Pro.

I made a mistake the first time and had to delete the data folder.

The problem is the amazon echo now has both sets of devices. Two are offline and two are online.
One is named the same “AC” so when I say “Alexa turn on my AC” it replies "You have two devices named “AC”

How can I clear the device list from the echo and re-discover ?

UPDATE: Never mind, found it. The echo api has a “FORGET” button which clears all settings.

1 Like

I have one question.
What is this part really doing “Setup a REST Endpoint Smartapp8 and select the devices you would like your Echo to be able to turn on/off”

Why does it reference an ip address http://107.20.127.54/smartthings

Are we granting access to our devices to a public website ?
I think we are ?
Is this the echo site or are we using some third parties interface ?

Also I noticed this creates something called “Endpoint Example” but can not figure out how to rename that, edit it, or look at it’s config. Where is this in the IDE ?