Playing around with Amazon Echo (technical interface discussion)

I know someone else mentioned this on another post, but this can be done with bluetooth pairing a computer to the Echo, along with VLC Thing. Say you’re playing a Pandora station on the Echo with the computer paired via bluetooth, the natively integrated Pandora music will cut out temporarily while the bluetooth audio plays then will turn back on Pandora.

1 Like

@mattjfrank,

Thanks for the Code.

I am curious, since I do not have this running yet. If you turn on a light via Alexa, can you specify the text of her response or does she just say “Light A is on”?

No when you tell Alexa to turn something on or off she just responds with OK once it’s done. If she “thinks” she found a match she asks you to confirm. If she doesn’t understand or find a match she doesn’t respond.

1 Like

Ya I’m familiar with that. I use vlc thing to play me other messages, it’s just not 100% affective. I use it via some airplay speakers.

FWIW: I had similar issues detecting the node.js emulator as UPnP. After restarting my PC, doing a netstat -ano | find “1900” and killing the task that was taking up 1900, then starting up the emulator, everything was right as rain.

I also needed to add firewall rules for 1900 TCP & UDP allowing connections and out. This might’ve been overkill but I was troubleshooting.

1 Like

You could just do the “spoof” with a mapping in the Endpoint SmartApp, instead of a Virtual Device, no??

If you have an Internet line and can use any of the free DDNS, you can have your own cloud without paying for any hosting services. A static IP would be good too. If SmartThings start supporting WIFI communication in its next version, it would probably become Alexa Cloud to Your Router to Your Home Server to SmartThings.

Paying for hosting services is not a problem. The real problem is the lag time while your command have to travel through so many cloud servers before arriving at your light switches. Waiting 5 seconds for the lights to turn on after asking them to is not a cool thing after all.

Another possibility, when Alexa Voice Service is out, is to build a mobile app to capture your command then, through Alexa, translate it into API calls to the SmartThings Custom SmartApps API. For this we don’t even need to buy an Echo device nor to release any Echo Apps. Correct me if my assumption is wrong somewhere. Apparently SmartThings can also adapt this idea into their existing app like how Wink and Scout Alarm are doing.

Wow, what a bunch of smart people we have on this forum! Smarter than me for sure. I am loving my home automation and my new Echo. I’ve been successful setting up several things with code from other ST’s forum threads. Would anyone be willing to create a step-by-step Echo for Dummies - I would like to control all of SmartThings lights, garage door, and Nest using Echo. I see so many bits of awesome info, but I always get hung up somewhere in the details. Thanks!

1 Like

I attempted to document my version of the server. Checkout the readme on my raspberry branch here

This is to setup the version of the bridge I modified. It talks directly to the smart app so you don’t have to do “Post” calls anymore. It also updates correctly when devices are added or removed.

My instructions are raspberry specific but should work on most unix systems. On windows you have to do a little work on your own.

Also one suggestion I would not put Garage on my echo because some outside could shout “Alexa open garage” and it would open :slight_smile: Of course you could name the garage something secret and then this would help secure it…Hmmmmm name it sesame …“Alexa Open Sesame” LOL

9 Likes

I’d like to set up a hue bridge emulator but wonder if it will play nicely with a real hue bridge also running. I’ve been unable to find anything specifically addressing this.

Yes … in my experience so far, there has been no confirmed interference between my Hue Bridge Emulator and my real Hue Bridge.

The disclaimer is that I have always had some inconsistent behavior related to Hue – i.e., I am not a scientifically controlled test environment.

1 Like

Thanks Ron! I may try to use the Raspberry setup, as I have been wanting one, and I think keep it running as the server instead of a PC makes the most sense. Any tips on buying a Rasp Pi and specific kit pieces?

I just bought

  • Raspberry Pi 2 Model B (1GB ram 900Mhz Quad Core CPU)
  • plastic case
  • 32GB Micro SDHC memory card (more than needed but only $15 so why not)

You also need

  • usb charger
  • micro usb cable
  • network cable

If you want wireless you need the wireless card but I didn’t do that so not sure what to recommend.

Are you on windows ?? "did you start the command prompt by using the “run as administrator” option ?? Using this method my problem was resolved, hope this helps !!

I had this working last night and then it stopped working. I admit, I am new coding/RestAPI/Oauth. I am able to successfully post the device commands via PostMan and I know my Oauth tokens and url’s are working properly (I tested in a browser). However, when I go to do a discovery via Echo, it doesn’t find any of the devices I was posted. I deleted the data directory and tried to start fresh, but it doesn’t fix it. I am running the .jar file on my Mac and it’s listening properly.

Any ideas?

To further expand on my issues, here is what I did. It’s driving me nuts that I had this working and now it’s not:

  1. Created a SmartApp with oAuth enabled with the following code: https://gist.github.com/aurman/9813279. Published it, selected my devices, recorded the oAuth Client and Secret Tokens. This smartapp I called “RestAPISmartApp”
  2. Clicked on this link - http://107.20.127.54/smartthings/exampleOauth.php. Authorized that same device my first SmartApp and copied the Authorization URL Token. I now have 2 smartapps under my account as this one also created one called “Endpoint Example”.
  3. Started the Amazon Jar File on my Mac OSX and it’s running in a terminal.
  4. Opened up PostMan, for Authorization, I put OAuth2, and for the Authorization URL I put http://107.20.127.54/smartthings/exampleOauth.php, for the AccessTokenURL, I put the URL that the “Endpoint Example” provided for me (http://107.20.127.54/smartthings/exampleOauth.php?access_token=LEAVINGBLANKFORSECURITYPURPOSES). I tested this in a browser and the On and Off for my device works as expexted. I put the proper Header and for Body, I put the correct syntax with the on and off URL’s for the device. I then posted and I got “201 Created” which appears that I did this part successfully. I do notice an error in Postman though that says “COULD NOT INITIATE OAUTH2 FLOW, CHECK DEBUG URL”. Not sure what this means, but I am able to GetAccessToken within Postman successfully.
  5. I then open up my Alexa app on iOS and perform a discovery and it’s not finding the device I enabled in both smartapps.

Any ideas?

Make sure there aren’t any other applications or services running on port 1900 which is used as part of the discovery process.

On Windows the command to find other applications using port 1900:

netstat -ano | find "1900"
//note that the SSDP service should be disabled on Windows as it uses this port

On a Mac, it should be something like (reference):

lsof -n -i4TCP:1900 | grep LISTEN

I got this working. All I did was added logging to my jar command and now it works. Go figure.

java -jar -Djava.net.preferIPv4Stack=true /Users/username/Documents/amazon-echo-bridge-0.1.1.jar --logging.vel.com.armzilla.ha.upnp=DEBUG --logging.file=ha.log --upnp.config.address=192.168.1.X>log.txt

Hey @Ron, thanks for the SmartThings-modified bridge!

I’m trying to make it work in a rather “unique” setup, and having some issues – was hoping you might have some insights into what could be going wrong.

Basically, while I don’t have a spare computer to run as a server, I do have a Nexus 7. Since that doesn’t run java, I set up an AWS instance and am running your code on it. I set up the nexus to forward TCP port 8081 (and changed the bridge config accordingly), and UDP ports 1900 and 50000. I can access the “Echo SmartThings Hue Emulator Bridge” page by hitting my tablet’s IP using a browser on my local network computer – this works great, and I am able to authorize with SmartThings and click the link to see the connected devices.

However, when I ask the Echo to discover devices, it finds nothing. I don’t think the issue is with the AWS security group, since I tried just allowing all access, and that didn’t help. Do you have any idea what I could be doing wrong? are there any settings or ports I missed?

My config is as follows:
export LOCAL_IP=my tablet’s local IP

export UPNP_PORT=50000
export SERVER_PORT=8081
export SMART_APP_CLIENTID=my smartapp’s client id
export SMART_APP_SECRET=my smartapp’s client secret

export ROUTER_EXTERNAL_IP=the AWS instance’s public IP

Hmm… not sure I understand. The Hue needs to be on your local network. Once configured with ST the port forwarding can be turned off since that is only needed for the ST servers to be able to see your local instance. The Amazon Echo just looks for upnp ports I think 1900 and 50000 should do the trick but not sure how that should work.

If I understand you are running the hue bridge on AWS cloud. That is outside your network. So how can Amazon echo detect it ? I didn’t write the amazon echo interface part since that was done by armzilla’s original code. just added the OAuth handshake with ST and the ability for the Smart App to configure the hub. With armzill’s version you had to do that manually.

That said I think I understand the Hue side. It is basically searching your network for Universal Plug and Play UPNP hue bridge which this code emulates. I am not sure how port forwarding could work with that. Looking at the UpnpListener code it looks like it needs port 1900 which you say you are forwarding. So the Nexus 7 is on your local network and forwarding port 1900 and 50000 requests to the AWS server ? Seems like it should work… Maybe that is too slow ? Does the Nexus 7 actively listen to incoming port ? I would think it would not when it is sleeping. My MacBook Pro would shut down when closed so I moved my server to a raspberry so I could just leave it running.

Do you see anything in the AWS logs ?

I have no experience with AWS so not sure how that needs to be set up.

Maybe easier to pickup a raspberry pi for $40, LOL

1 Like