Monday, January 1, 2018

Control Filtrete Wifi Thermostat with Alexa  -  Part 1 of 3

I got an Echo Dot for Christmas and I was eager to use it to control my two Filtrete Wifi Thermostats (model 3M-50) in the house. Turns out it’s harder than I thought. Unlike Nest or Honeywell thermostats, Filtrete doesn’t have an official Alexa skill. Fortunately, after several hours of googling and tinkering, I was able to put together a way to do that using open-source software (kudos to Ben Hardill’s work which is a major piece to the puzzle). Ready for the details? Here we go!
The Filtrete thermostat I have at home

What you will need

  • an Echo device
  • a Raspberry Pi running Raspbian Jessie or above
  • a Filtrete Wifi Thermostat (from what I could tell, the following models are supported: CT-80 Rev A v2.18, CT-30e v1.75, 3M-50 v1.09, and CT-80 Rev B v1.00 and later versions)

TL;DR

Install Node-RED on Raspberry Pi. Install Node-RED module node-red-contrib-alexa-home-skill. Create an account on this module’s companion website and define thermostats there. Install Node-RED Alexa skill and account-link using the account created above, and have Alexa discover the thermostats. Study the thermostat’s API here. Write a Node-RED flow to control the thermostat. Now, ask Alexa to control the thermostat!

Setting up Node-RED on Raspberry Pi

First, install Node-RED on a Raspberry Pi. Node-RED is a platform that allows you to write work flows to control IoTs devices using a Scratch-like interface. This is actually the first time I came across the Node-RED project and I must say, after a few days of working on this project, I’m quite impressed by how polished and powerful it is.
Follow the official instruction here to install Node-RED on Raspberry Pi. Apparently, Raspbian Wheezy is not supported. I still had Wheezy on my Pi, but couldn’t seem to find a way to reliably upgrade it Jessie, so I just did a clean install of the latest version called Stretch. Other than that, the installation process is pretty straight-forward. Make sure you set it to auto-start on boot (details in the same instruction page).
Once finished, start Node-RED server like this:

pi@pi-2:~ $ node-red-start
Start Node-RED
 
Once Node-RED has started, point a browser at http://192.168.1.15:1880
On Pi Node-RED works better with the Firefox or Chrome browser
 
Use   node-red-stop                          to stop Node-RED
Use   node-red-start                         to start Node-RED again
Use   node-red-log                           to view the recent log output
Use   sudo systemctl enable nodered.service  to autostart Node-RED at every boot
Use   sudo systemctl disable nodered.service to disable autostart on boot
 
To find more nodes and example flows - go to http://flows.nodered.org
 
Starting as a systemd service.
Started Node-RED graphical event wiring tool..
26 Dec 06:14:30 - [info]
Welcome to Node-RED
===================
26 Dec 06:14:30 - [info] Node-RED version: v0.17.5
26 Dec 06:14:30 - [info] Node.js  version: v6.12.2
26 Dec 06:14:30 - [info] Linux 4.9.59+ arm LE
26 Dec 06:14:36 - [info] Loading palette nodes
26 Dec 06:15:07 - [info] Settings file  : /home/pi/.node-red/settings.js
26 Dec 06:15:07 - [info] User directory : /home/pi/.node-red
26 Dec 06:15:07 - [info] Flows file     : /home/pi/.node-red/flows_pi-2.json
26 Dec 06:15:07 - [info] Creating new flow file
26 Dec 06:15:07 - [info] Server now running at http://127.0.0.1:1880/

Now, point your browser to http://[YOUR-RASPBERRY-PI-IP-ADDRESS]:1880/ and you should see a nice-looking GUI like this:
The Node-RED GUI
Now, install the node-red-contrib-alexa-home-skill module. You can do this directly in the GUI: in the drop-down menu on the top right corner (next to the red Deploy button), click on ‘Manage palette’, and then click on the ‘Install’ tab in the popup window. Search for node-red-contrib-alexa-home-skill and install it, like this:
Installing the node-red-contrib-alexa-home-skill module
Now you should have two Alexa nodes at the bottom of the palette on the left-hand side, like this:
New Alexa nodes

Setting up Alexa

You need to describe the thermostats you’d like to control. At the minimum, you should give them names, and specify the types of commands to be used. You do this on the Node-RED module’s companion website here. It has a documentation page which provides very detailed instructions on what to do. My setup looks like this:
Defining the thermostats
Now, enable the Node-RED Alexa skill for your Echo device (do this on your phone or tablet’s Amazon Alexa app, like you would any other skills). After enabling, the skill would prompt you to link the account you just created on the companion website. Once account is linked, ask Alexa to discover the thermostats you defined above, by saying Alexa, discover devices. You should see the thermostats now listed under the ‘Smart Home’ section of the app.
The Node-RED Alexa skill

Setting up the Thermostats

The main goal here is to make sure your home router assigns static IP addresses to the thermostats, aka giving them a DHCP Static Lease. In my Verizon router, this is done in the “Advanced” - “IP address distribution” page. This ensures that the IP addresses of the thermostats do not change over time. Take note of the IP addresses so we can use them in the next section.
One of my thermostats’ IP address and DHCP Static Lease configuration
To confirm if you’ve got the correct IP address, point your browser to http://[YOUR-THERMOSTAT-IP]/tstat. You should see the thermostat returning its current status in the form of a JSON object, like this:
JSON object returned from one of the thermostats
Read the API documentation here to see what other functionalities are available.

Writing the Node-RED flow (FUN begins!)

All the plumbing work is completed at this point, and now we need to write the brain that controls the thermostats, in the form of a Node-RED flow.
Here is the top-level sequence of events after you tell Alexa to set a thermostat’s temperature: Echo forwards the voice command to Amazon cloud where it is processed and recognized as a request to change (a particular) thermostat’s temperature -> Amazon recognizes that this thermostat was discovered from the Node-RED skill -> Amazon sends the request to the companion website, along with your ID -> companion website forwards the request to the Node-RED server running on your Raspberry Pi (via MQTT?). What should happen next, but is currently missing, is that the Node-RED server would then instruct the thermostat to change its target temperature, and send back the result of the change, which would traverse the above route in reverse to reach your Echo device. This is what we need to write next.
Ben Hardill, the person behind most of the work that links Alexa to Node-RED, has provided detailed instructions on how to write flows using the Alexa nodes installed above. His instructions were very helpful in getting me started, but I had to add/change things quite a bit due to the idiosyncrasies of the Filtrete thermostat.
In the second and third part, I will show you my Node-RED flow/code that queries the current temperature, and then the code that sets a target temperature.
To be continued ...

Link to Part 2/3 of this tutorial

5 comments:

  1. Is there a specific Pi model requirement? Will a Pi Zero work?

    ReplyDelete


  2. Many autos repair and replace ABS Sensor,Abs pump, Abs Ring for all makes and models in Reading,United Kingdom. We also provide free collection and Delivery service from your home or place of work.

    ReplyDelete
  3. I absolutely love your blog and find almost all of your post's to be precisely what I'm looking for. Would you offer guest writers to write content for yourself? I wouldn't mind composing a post or elaborating on a few of the subjects you write with regards to here. Again, awesome website!
    reina electric radiators

    ReplyDelete
  4. These tips are kinda useful. Some people tends to call technicians just before watching for themselves.
    http://www.cosmopolitanmechanical.ca/

    ReplyDelete

Using Google App Script and Google Sheets to create a class sign-up system

G Suite and Google App Script I've been learning to use G Suite and Google Apps Script lately. G Suite is a neat little platform that, a...