Introduction: HRV Temperature to OpenHAB Via ESP8266 (Serial Code Example!)
HRV - Wireless to OpenHAB
This instructable is specifically for those who have an HRV (heating recirculation ventilation) system - although parts of the circuit board, openhab configuration or Arduino code (such as reading TTL serial data) could be handy to your own projects or serve well for learning. It does assume you have a reasonable knowledge of the Arduino IDE and what an ESP8266 chip is.
Introduction
The following outlines how to build an ESP8266 that connects to an HRV system and sends roof and house temperatures, control panel temperature and fan speed via MQTT messages to OpenHAB. This is designed to work with an ESP8266-01 board (although should work with any ESP8266 3.3V version) If you have a similar HRV type system from an alternate vendor, you will need to determine whether data is sent as TTL serial and if so, what structure the data is sent as.
OpenHAB and Mosquitto
The ESP8266 code has been written specifically to work with OpenHAB (open source home automation software) and an MQTT broker such as Mosquitto (a messaging subscribe/publish type protocol that is lightweight and great for communication between devices) Don't let the names or acronyms scare you, they are really quite simple to use once you get to know how they work. I utilise OpenHAB on a NTC C.H.I.P (US$9 computer) however many people use a Raspberry Pi or similar. This tutorial assumes you have implemented OpenHAB (if you need help setting up OpenHAB, follow this excellent article from the makeuseof web site) You also need to download and install Mosquitto (MQTT broker) and related OpenHAB binding. You can install this elsewhere on your network, however most people just install this on the same machine as OpenHAB to keep it simple.
To install Mosquitto, following this link then select the type of device you are using and follow the instructions. Because C.H.I.P runs Debian (Jessie), you can follow the Raspberry Pi instructions if you are using C.H.I.P for your Home Automation device (also note, its best to reconfigure CHIP to boot from the CLI. There are instructions for this here)
Once you have OpenHAB and Mosquitto running, you need to prepare the Arduino IDE for the ESP8266 and code. First, you need to add the "PubSubClient" library. In the Arduino IDE, from the menu's go to Sketch, Include Library, Manage Libraries In the filter search box, type PubSubClient then highlight the search result and click to Install (at time of writing, the latest version is 2.6.0) You will also need to add the ESP8266 board to the Arduino IDE which can be done by following instructions here
What does this give me?
As stated earlier, this project will allow you to view your HRV control panel roof, house, control panel temperatures and fan speed in the OpenHAB GUI (in real time!) The images show what it looks like from my iPhone, plus the graphs you will get by drilling down into the different temperatures.
To get the graphs, you will need to also install and configure the RRD4J binding (this is very straight forward) This will allow you to click on either 'House' or 'Roof' and get a history of HRV temperatures for each over the past hour, day or week (or longer, if you alter the configuration to suit) The images shown are in celsius, and clearly its winter in the southern hemisphere when I made this!
Additionally, I created an OpenHAB view that shows a comparison between Outside temperature (provided by the Weather binding add-on, in my case using Wunderground) versus the roof and house temperatures by clicking on the 'Control' option (picture shows the graph with house, roof and outside temperature plotted). I plan on using this data in rules to turn on heating appliances as required. Simply add the Weather item to your Image URL in the sitemap file and include this on the same graph (eg: ...items=houseTemp, roofTemp, weatherTemp...)
Step 1: Parts Needed / Assembly
You will need the following parts
- An RJ11 splitter (this splits the signal from the controller in the roof, to the control panel and the ESP8266)
- Some ribbon cable and an RJ11 plug (to run wires from splitter to ESP8266)
- ESP8266-01 (other 3.3V versions should work)
- TTL logic level converter (to change data from 5V -> 3.3V)
- AMS1117 3.3V voltage regulator (or similar, to change voltage from HRV 5V -> 3.3V to power ESP8266)
- 1N5817 schottky diode (for some reason this helped stop the HRV control panel resetting on ESP power on)
- 10K ohm resistor (pullup resistor between 3.3 Voltage Regulator and ESP CH_PD)
- 10V 10uF capacitor (or similar, to smooth out and stabelize inbound power from HRV)
- 10V 1uF capacitor (or similar, to smooth out and stabelize outbound power to ESP)
- Optional slide button to program the ESP (otherwise, need to pull GPIO0 to GND manually to program)
- An FTDI adapter (to program the ESP, converts USB to serial)
Assemble as per the Schematic
The breadboard image shows how the parts should be assembled. Note that there are 6 pins that come down the ribbon cable from the HRV controller unit in the ceiling:
Pins 1 and 6 are 5V VCC
Pins 2 and 5 are GND
Pins 3 and 4 are Data.
You only need to use pins 1,2,3 and 6 (1 and 6 VCC powers ESP8266 and the high side of TTL logic converter, 2 is a common ground and 3 is for reading TTL serial data)
The splitter you need will just be an RJ11 splitter, just make sure its a splitter where the pins are straight through (eg: pin 1 goes to pin 1, pin 2 to pin 2 and so on) Note that the extra female pins (as shown in the images) are for connecting an FTDI for reprogramming the ESP later, and the switch shown puts it in "programming" mode. These are optional, but recommended (eg: if you change your WiFi password as the WiFi AP and password are hard programmed into the code, which you will need to upload once your ESP8266 is built)
Step 2: Uploading Code and Testing
Code Changes
Alternate download link to Arduino code HERE
Open in the Arduino IDE, ensure the ESP board is installed as well as the PubSubClient and that you have selected the ESP8266 board (Tools, Board, Generic ESP8266 Board) Edit the code and change the WiFi AP name and password and the IP address of your MQTT broker (these are the only things you should need to change) as shown below. Click the 'Verify' button to ensure it compiles ok then ensure the correct COM port is selected (Tools, Port) and upload the code to your ESP8266. There are plenty of articles around on how to do this, I won't reinvent the wheel here.
// Wifi const char* ssid = "your_wifi_ssid_here"; const char* password = "your_wifi_password_here"; // MQTT Broker IPAddress MQTT_SERVER(192, 168, 222, 254);
MQTT Testing
For testing you can leave your FTDI adapter connected and open the Serial Monitor in the Arduino IDE, you should see messages printing the temperature information in the console. If you need to troubleshoot incoming MQTT messages from the ESP8266 to your MQTT broker, then on the Mosquitto server run one of the following commands to subscribe to the incoming messages:
mosquitto_sub -d -t openhab/hrv/status
You should see inbound PUBLISH messages coming in from the ESP8266 every 30 seconds or so with the number "1" (meaning "I'm alive") If you see constant "0's" (or nothing at all) then there is no communication. Once you see the number 1 coming in, then it means the ESP8266 is communicating with the MQTT broker (search "MQTT Last Will and Testament" for more information on how this works, or see this really good blog entry)
You can now track temperature and fan speed data, subscribe to one of the following. However, note that the code only sends the temperature data if any data has changed. It keeps track of the last temperature, fan speed etc data that was sent, so you may not see information coming in immediately.
mosquitto_sub -d -t openhab/hrv/rooftemp
mosquitto_sub -d -t openhab/hrv/housetemp
mosquitto_sub -d -t openhab/hrv/controltemp
mosquitto_sub -d -t openhab/hrv/fanspeed
Hint: subscribe to the control panel temperature above, then push the temperature button on the control panel itself you should see the new temperature setting come in.
When you get around to soldering this up, a 3cm x 7cm PCB fits nicely in the flush box behind the HRV Control Panel. I would recommend only doing this if it is a plastic flush box as a metal box may interfere with Wifi signals or possibly short out connections on the PCB board. Alternately, you could print out a plastic 3D case to mount the board in.
Attachments
Step 3: OpenHAB Changes
OpenHAB Configuration
OpenHAB changes required are as follows:
'items' file:
/* HRV
Number hrvStatus "HRV Status [MAP(status.map):%d]" (gHRV) { mqtt="<[mqttbroker:openhab/hrv/status:state:default]" }
Number houseTemp "House [%.1f C]" (gHRV) { mqtt="<[mqttbroker:openhab/hrv/housetemp:state:default]" }
Number houseTemp_Chart_Period "Chart Period"
Number roofTemp "Roof [%.1f C]" (gHRV) { mqtt="<[mqttbroker:openhab/hrv/rooftemp:state:default]" }
Number roofTemp_Chart_Period "Chart Period"
Number controlTemp "Control [%.1f C]" (gHRV) { mqtt="<[mqttbroker:openhab/hrv/controltemp:state:default]" }
String fanSpeed "Fan Speed [%s]" (gHRV) { mqtt="<[mqttbroker:openhab/hrv/fanspeed:state:default]" }
*/
'sitemap' file:
Frame label="HRV Temperature" {
Text item=roofTemp {
Frame {
Switch item=roofTemp_Chart_Period label="Period" mappings=[0="Hour", 1="Day", 2="Week"]
Image url="http://localhost:8080/rrdchart.png?items=roofTemp&period=h" refresh=6000 visibility=[roofTemp_Chart_Period==0, roofTemp_Chart_Period=="Uninitialized"]
Image url="http://localhost:8080/rrdchart.png?items=roofTemp&period=D" refresh=30000 visibility=[roofTemp_Chart_Period==1]
Image url="http://localhost:8080/rrdchart.png?items=roofTemp&period=W" refresh=30000 visibility=[roofTemp_Chart_Period==2]
}
}
Text item=houseTemp {
Frame {
Switch item=houseTemp_Chart_Period label="Period" mappings=[0="Hour", 1="Day", 2="Week"]
Image url="http://localhost:8080/rrdchart.png?items=houseTemp&period=h" refresh=6000 visibility=[houseTemp_Chart_Period==0, houseTemp_Chart_Period=="Uninitialized"]
Image url="http://localhost:8080/rrdchart.png?items=houseTemp&period=D" refresh=30000 visibility=[houseTemp_Chart_Period==1]
Image url="http://localhost:8080/rrdchart.png?items=houseTemp&period=W" refresh=30000 visibility=[houseTemp_Chart_Period==2]
}
}
Text item=controlTemp {
Frame {
Switch item=Combined_Chart_Period label="Period" mappings=[0="Hour", 1="Day", 2="Week"]
Image url="http://localhost:8080/rrdchart.png?items=houseTemp,roofTemp&period=h" refresh=6000 visibility=[Combined_Chart_Period==0, Combined_Chart_Period=="Uninitialized"]
Image url="http://localhost:8080/rrdchart.png?items=houseTemp,roofTemp&period=D" refresh=30000 visibility=[Combined_Chart_Period==1]
Image url="http://localhost:8080/rrdchart.png?items=houseTemp,roofTemp&period=W" refresh=30000 visibility=[Combined_Chart_Period==2]
}
}
Text item=fanSpeed
}
Extra icons for OpenHAB are included (right click and save images)
Save these files to the ..\OpenHAB Home\webapps\images folder on your OpenHAB server
To download the Arduino source code click HERE