Tuesday, June 30, 2015

Controlling the Honeywell WiFi Thermostat using Amazon Echo

In my previous article I reviewed the Amazon Echo. In further integrating it with my home automation setup, I want the Echo to control my Honeywell RTH9580WF WiFi thermostat through voice commands. Honeywell does not have any plans to allow its My Total Connect Comfort system to integrate with the Amazon Echo, and I have little hope that they will. But by creating our own Amazon Echo app, and using my previously discussed python script to control the thermostat, we can make it happen. Let's get started!



Preparing your webserver


While you are capable of using Amazon's AWS Lambda free tier for this, I will be covering how to do it with your own server. You need to have a web server that is accessible online and is configured to use HTTPS SSL encrypted connections. Amazon enforces HTTPS for the Echo. But you can create your own self-signed certificate and supply it to Amazon as a temporary development solution. For a cheap SSL certificate, I use Comodo Positive SSL.

Python script for My Total Comfort


Make sure you have configured my python script, as mentioned on my previously article, and that it is working correctly. Also verify that it is executable by the same user that runs your web server (http,  www-data, wwwuser, etc...).

PHP file to interface with the Amazon Echo


You will need my PHP file that the Amazon services will send the request from your Echo to. The one I created is a modified version thanks to OurAce.com. Their version is available here. I am not very experienced with web-based programming, so I am glad they provided that 'Hello World' example that I can hack.

Link to my PHP file


Place the PHP file in a directory that will be accessible by Amazon through the web. Make sure to edit the variable $cmd to correctly point to where you have the thermostat python script!

I have added comments and set configurations as variables so you can copy my PHP file and use it for any other projects that would like to interact with Alexa. The section of interest would be Responses. You set two things: 1. The speech Alexa will respond with. 2. The little web card that appears on your Echo homepage.

Create an Alexa Skill


If you do not have one already, create an Amazon developer account. We will create a new "Alexa Skills," which is what Amazon calls the scripts/applications that the Amazon Echo can use.

When ready, go to your Developer Console. At the top menu go to App & Services, and then select Alexa in the submenu.

Skill Information

  1. Click on the Add a New Skill button. 
  2. Set the Name to be any name you want to call this Skill (for reference).
  3. The Invocation Name will be the name you tell Alexa to let it know it is your application. I set it to thermostat.
  4. Set the Endpoint to the address you have the PHP file on your web server.
  5. Press Next.

Interaction Model

  1. The Intent Schema is the JSON data structure that our PHP file will be parsing. You pair a name with a data type. Data type options are available here. The structure I am using is below:

  2. {
        "intents": [
     {
         "intent":  "SetTemp",
         "slots": [
      {
          "name":"action",
          "type":"LITERAL"
      },
      {
          "name":"temp",
          "type":"NUMBER"
      },
      {
          "name":"duration",
          "type":"NUMBER"
      }
         ]
     }
        ]
    }
    

  3. The Sample Utterances is very important! This is essentially how the Echo will understand what you are saying. You should place every type of voice combination that you think you will say. The first word, in this case SetTemp, references the data structure in the Intent Schema. The rest are words that are to be said after "Ask Invocation_Name." So for my setup with the Invocation Name thermostat, I will not be writing the "Ask thermostat" part here. I will add any words that follow it. Do not use any numbers- spell everything out. My structure is below:

  4. SetTemp {eighty|temp} degrees
    SetTemp {eighty one|temp} degrees
    SetTemp {eighty two|temp} degrees
    SetTemp {eighty three|temp} degrees for {one|duration} hour
    SetTemp {eighty four|temp} degrees for {two|duration} hours
    
    SetTemp set my temperature to {eighty |temp}
    SetTemp set my temperature to {eighty one|temp} degrees
    SetTemp set my temperature to {eighty two|temp} fahrenheit 
    
    SetTemp set my temperature to {eighty |temp} for {one|duration} hour
    SetTemp set my temperature to {eighty one|temp} degrees for {two|duration} hour
    SetTemp set my temperature to {eighty two|temp} fahrenheit  for {three|duration} hour
    

  5. Press Save to check for errors. Then press Next.

SSL Certificate


Select the corresponding certificate setup that you are using. If you are using a purchased SSL certificate that is correctly set up, keep the first option. The other options are self-explanitory. 

Testing


You are now ready to begin testing your script. Go to your Echo homepage. On the left side you should see Skills under Alarm. Go in there and make sure the Skill we created is enabled. If you are using my setup, you can now ask Alexa to control your thermostat. Some examples are:
  • Alexa, ask thermostat for status.
  • Alexa, ask thermostat for settings.
  • Alexa, ask thermostat for 78 degrees.
  • Alexa, ask thermostat for 78 degrees for two hours.
  • Alexa, ask thermostat to cancel.

If Alexa does not respond with anything after you ask it, check the Sample UtteIrances you have set. It is very picky. For example, I had "eighty one" as an invocation. So when I said "eighty," it did not understand and I had to add it.

If Alexa responds that there was an error, check the Echo homepage for more information such as an issue with your SSL certificate. Use your web card to debug as well as PHP error_log functions to get more information.

Success!


I would prefer to say "Alexa, set thermostat..." but it seems to be a keyword reserved for other devices. Alexa will reply that there are no devices set up with that name. Hopefully my steps have been successful for you and you are now dangerous with the Amazon Echo. I found the Echo to be a great additional to my home automation setup! I'm excited to see more creative applications people can come up with.

53 comments:

  1. I was hoping that this was possible so thanks for putting it up here!
    I did have a question about using this on Lambda. I have everything set up on Lambda and have the trigger set to Alexa. When asked, Alexa says that it can't communicate with my Honeywell app. I have limited programming knowledge but my thought was that since I don't have your PHP code anywhere (on a web server), then this isn't going to work. So my question is can your python code work alone with Lambda or do I need to have the PHP used (for triggering, etc.).
    I'm not looking for tech support so if this is more than a brief answer, I'll just set up the web server per your instructions and go from there. I thought using Lambda might be an easier solution for me.
    Thanks!

    ReplyDelete
    Replies
    1. Hi Mark! Thanks for checking out my article.

      You are correct. The Python script does not have the ability to talk directly with the Echo service. When Amazon does not receive a reply, it will say it could not communicate. The PHP code acts like the middle-man between Amazon and the Python script. It will capture the request from Amazon and then give it the reply Amazon is looking for.

      I am not too familiar with Lambda, but it seems it could handle the Python part but not the PHP part.

      Delete
  2. Your sample utterances doesn't include status or settings. How can you say "Alexa, ask thermostat for status." if it's not in the sample utterances?

    ReplyDelete
    Replies
    1. You are correct that it is required. My example did not fully include everything. My complete set is:

      SetTemp {cancel|action}
      SetTemp {status|action}
      SetTemp {settings|action}

      SetTemp {eighty|temp}
      SetTemp {eighty one|temp}
      SetTemp {eighty two|temp}
      SetTemp {eighty three|temp}

      SetTemp {eighty|temp} degrees
      SetTemp {eighty one|temp} degrees
      SetTemp {eighty two|temp} degrees

      SetTemp {eighty|temp} degrees for {one|duration} hour
      SetTemp {eighty three|temp} degrees for {two|duration} hours
      SetTemp {eighty four|temp} degrees for {three|duration} hours

      SetTemp set my temperature to {eighty |temp}
      SetTemp set my temperature to {eighty one|temp} degrees
      SetTemp set my temperature to {eighty two|temp} fahrenheit

      SetTemp set my temperature to {eighty |temp} for {one|duration} hour
      SetTemp set my temperature to {eighty one|temp} degrees for {two|duration} hour
      SetTemp set my temperature to {eighty two|temp} fahrenheit for {three|duration} hour

      Delete
  3. This comment has been removed by the author.

    ReplyDelete
  4. I tried this step by step, and as it is my first time to ever attempt something like this, Alexa says there was a providence with the requested skills response. Any pointers?

    ReplyDelete
    Replies
    1. Does Amazon ever reach your server? It could be an issue with the SSL certificate. If Amazon doesn't like it, it kills the connection immediately.

      When debugging, I would put error_log() statements in the php file to know where exactly the session would die.

      Delete
  5. I am using a Mac and have set up the Python script with no problem as I have done it with Smartthings and plan to host it on the Amazon's AWS Lambda free tier. But from there on I am lost, is there any more details or an easier step by step? I hate being a pain in the butt, but I am really confused with this.

    ReplyDelete
    Replies
    1. I would like to get it working with AWS Lambda too, but since they only allow JavaScript the entire script would need to be converted from python. I would like to eventually take a shot at trying to port it though.

      Delete
  6. I just got it working on a Debian box after trying first on Raspberry Pi and then Ubuntu. My biggest obstacle was the SSL stuff but finally got that fixed this morning after 6 hours the day before.

    Now I'm trying to find the API so I can expand on what it does. I would like to turn the fan from Auto to Circulate to Off and a few other things but your program doesn't really tell me what the other stuff requires.

    I do want to thank you for the excellent documentation though.

    ReplyDelete
    Replies
    1. Another user seems to have commented on adding the fan on the bottom of the github page:

      https://gist.github.com/ghostbitmeta/694934062c0814680d52

      I will take a look at it and merge it in when I get the chance.

      Delete
  7. The python script works great on my server. But no matter what I try Echo tells me it has a problem communicating with requested skill. I have my own self signed certificate on apache server running on Ubuntu. Getting skills to work with the echo is very frustrating.
    I know my server is open as I can reach it via https so that is not the issue. I have the python and php files both in my var/www/html folder and have the $cmd line in php pointing to /var/www/html/echo.php also tried just echo.php. I suspect the issue is somewhere in the certificate but no idea where to start.

    ReplyDelete
    Replies
    1. Have you taken a look yet at Amazon's documentation for using self-signed certs?

      https://developer.amazon.com/public/solutions/alexa/alexa-skills-kit/docs/testing-an-alexa-skill#Configuring%20Your%20Web%20Service%20to%20Use%20a%20Self-Signed%20Certificate

      Delete
  8. What do you have your echo.php and therm.py chmoded to?

    ReplyDelete
    Replies
    1. Never looked at that. What should it be? I do not do much Linux so bare with me.

      Delete
    2. Hi,

      My echp.php is set to 644: RW for owner and read for others. therm.py is set to 755, allowing anyone to execute it.

      Delete
  9. This comment has been removed by the author.

    ReplyDelete
  10. Hi

    What to do, if I have more than one Honeywell RTH9580WF WiFi thermostat?
    I have three for three zones. Any idea appreciated.

    Thanks

    Jozsef

    ReplyDelete
  11. I just got my Echo for Christmas and I've been scouring the internet to learn more about providing custom programmed tech for it. Thank you for providing a wonderful post on setting up a thermostat with this.

    I wanted to note that now LetsEncrypt.org is live and out of beta, so getting Free SSL certs is easy :)

    ReplyDelete
  12. Echo skill to control Honeywell WiFi is now available.

    ReplyDelete
  13. Hi. It was very interesting to read. Thanks for sharing. Smart home is very popular now. I've tried to make my air conditioning system a part of general controling device, but I failed. I've asked this guys http://myairmatics.com/ for help and they helped me out. I decided to get an AC controll over my phone for now.

    ReplyDelete
  14. Dan, my name is Scott. I have some questions I'd like to ask you about the Honeywell script (I wish to have the thermostat set as a result of data coming from my solar array). How can I reach you by email? Perhaps email me, and I can reply? My address is my name, sterlingservices is the domain, and it is the original commercial TLD. Sorry, but spam, y'know! :)

    ReplyDelete
  15. Hi, I hacked your PHP code about to do something slightly different for my own purposes: https://gist.github.com/Westlad/d6c72a0e6597e9723dcc974018e9eae0
    I just wanted to check you are ok with that, as the original author.

    ReplyDelete
  16. I was reading some of your content on this website and I conceive this internet site is really informative ! Keep on putting up. Unique wifi names

    ReplyDelete
  17. I am come here first time, i find the perfect article. Thanks for sharing interesting and informative post. lemigliorivpn.com

    ReplyDelete
  18. I couldn't locate the ideal words to value this. This is genuinely one in a millions.
    clicca qui

    ReplyDelete
  19. Replies
    1. I am glad that I saw this post. It is informative blog for us and we need this type of blog thanks for share this blog, Keep posting such instructional blogs and I am looking forward for your future posts.
      Cyber Security Projects for Final Year

      JavaScript Training in Chennai

      Project Centers in Chennai

      JavaScript Training in Chennai

      Delete
  20. Thanks for a very interesting blog. What else may I get that kind of info written in such a perfect approach? I’ve a undertaking that I am simply now operating on, and I have been at the look out for such info. 192.168.0.254

    ReplyDelete
  21. These points are to be noted. These services must be under taken before winter. In order to safe yours HVAC unit. Heating and Cooling Ottawa

    ReplyDelete
  22. Excited by the writer's ability to write in this magnificent way.
    Alexa.Amazon.com

    ReplyDelete
  23. Yes, usually and yet as many companies attempted to streamline their distribution systems, inventory warehouses and cut costs, check over here

    ReplyDelete
  24. The counter radiation WiFi modem recieving wire boxes can retain the electromagnetic radiation and afterward convert it into heat vitality expend, which would not cause the subsequent contamination. wifi router

    ReplyDelete
  25. Good job! Fruitful article. I like this very much. It is very useful for my research. It shows your interest in this topic very well. I hope you will post some more information about the software. Please keep sharing!!
    SEO Training in Chennai
    SEO Training in Bangalore
    SEO Training in Coimbatore
    SEO Training in Madurai
    SEO Course in Chennai
    SEO Course in Chennai
    SEO Course in Bangalore
    SEO Course in Coimbatore

    ReplyDelete
  26. Rather than put off repairs to your major home appliances, you should deal with appliance problems right away. Sears Appliance Repair

    ReplyDelete
  27. https://memorialdaydeal.com Wonderful blog! I found it while surfing around on Yahoo News. Do you have any suggestions on how to get listed in Yahoo News? I’ve been trying for a while but I never seem to get there! Appreciate it.

    ReplyDelete
  28. What's more, practically most families would interface an additional WiFi router regardless of whether they as of now have a wired web so they can utilize their cell phones anyplace in the house. modem router

    ReplyDelete
  29. Really awesome blog!!! I finally found great post here.I really enjoyed reading this article. It's really a nice experience to read your post. Thanks for sharing your innovative ideas. Excellent work!
    Digital Marketing Training Course in Chennai | Digital Marketing Training Course in Anna Nagar | Digital Marketing Training Course in OMR | Digital Marketing Training Course in Porur | Digital Marketing Training Course in Tambaram | Digital Marketing Training Course in Velachery

    ReplyDelete
  30. Selecting a promotional product that suits the likings and temperament of customers or clients Technology

    ReplyDelete
  31. If there is a Power Save mode option, it is better the user turns it off completely from the drop down list. As it is found that the laptop saves power by tuning down the wireless adapter, which may cause less performance due to decreased WiFi signal. Funny WiFi Names

    ReplyDelete
  32. I appreciate this article for the well-researched content and excellent wording. I got so interested in this material that I couldn’t stop reading. Your blog is really impressive. https://wifibooster.link/

    ReplyDelete
  33. This blog was really good formatting, thanks for sharing with us. Visit Ogen Infosystem for professional website designing and digital marketing services at good price.
    Website Designing Company in Delhi

    ReplyDelete
  34. wonderful article contains lot of valuable information. Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article. . AWS Training in Chennai Velachery OMR

    ReplyDelete
  35. Appreciate it! An abundance of posts.

    Here's my website : --대구오피

    ReplyDelete
  36. List with Confidence Real Estate Company all of our agents are long time locals and experts in the local real estate market. Find out about them here.

    real estate marketing agency toronto
    real estate marketing companies canada

    ReplyDelete
  37. Grammarly Crack Free Download that is number one software in the whole world people. The program for Windows PC will make user messages, it's provides the .! Grammarly Crack

    ReplyDelete