ESP8266 – HomeKit Temperature & Humidity Sensor

In my previous blog here I tested the ESP HomeKit Software Development Kit. I am so enthusiastic about this Software Development Kit, that I going to write a few blogs about this genius software. In each Blog I will address a other accessory that you can add to your HomeKit without the need of a bridge. Time to make a a HomeKit Temperature & Humidity Sensor.

HomeKit Temperature & Humidity Sensor

While observing current conditions is convenient, It’s makes life a little bit easier. The HomeKit Temperature & Humidity Sensor equips you to do it with elegance and precision. Inside or outside your home.

Create powerful rules to automate your accessories and connected appliances. Have your humidifier switch on automatically, but only if The HomeKit Temperature & Humidity Sensor registers a drop in humidity. Or have your fan swing into motion, provided that the temperature has exceeded your comfort level. So let’s start building!

Software preparation

We have to install esptool.py on our Mac in order to be able to flash our ESP module. To work with esptool.py, you’ll need either Python 2.7, Python 3.4 or a newer Python installation on your system. We recommend using the latest Python version, so go to Python’s website and install it in your computer.

With Python installed, open a Terminal window and install the latest stable esptool.py release with pip:

pip install esptool

Note: with some Python installations that command may not work and you’ll receive an error. If that’s the case, try to install esptool.py with:

pip3 install esptool
python -m pip install esptool
pip2 install esptool

After installing, you will have esptool.py installed into the default Python executables directory and you should be able to run it with the command esptool.py. In your Terminal window, run the following command:

esptool.py

With esptool.py installed in your computer, you can easily flash your ESP32 or ESP8266 boards with the firmeware.

Hardware preparation

To Install our firmware to our esp we make our “standard” setup. There are two versions both are supported.

DHT11

  • Ultra low cost
  • 3 to 5V power and I/O
  • 2.5mA max current use during conversion (while requesting data)
  • Good for 20-80% humidity readings with 5% accuracy
  • Good for 0-50°C temperature readings ±2°C accuracy
  • No more than 1 Hz sampling rate (once every second)
  • Body size 15.5mm x 12mm x 5.5mm
  • 4 pins with 0.1″ spacing

DHT22

  • Low cost
  • 3 to 5V power and I/O
  • 2.5mA max current use during conversion (while requesting data)
  • Good for 0-100% humidity readings with 2-5% accuracy
  • Good for -40 to 80°C temperature readings ±0.5°C accuracy
  • No more than 0.5 Hz sampling rate (once every 2 seconds)
  • Body size 15.1mm x 25mm x 7.7mm
  • 4 pins with 0.1″ spacing

As you can see, the DHT22 is a little more accurate and good over a slightly larger range. Both use a single digital pin and are ‘sluggish’ in that you can’t query them more than once every second or two.


Update: 20-03-2021 Lateste firmware:

  • Version DHT11 GPIO2 Sensor / GPIO4 LED (dht11_gpio2.bin)
  • Version DHT11 GPIO4 Sensor / GPIO2 LED (dht11_gpio4.bin)
  • Version DHT22 GPIO2 Sensor / GPIO4 LED (dht22_gpio2.bin)
  • Version DHT22 GPIO4 Sensor / GPIO2 LED (dht22_gpio4.bin)

ESP OS preparation

To run our ESP HomeKit device we need to install LCM And Open RTos.

Life-Cycle-Manager (LCM)

Initial install, WiFi settings and over the air firmware upgrades for any ESP-open-RTos repository on GitHub.

ESP-open-RTos

A community developed open source FreeRTOS-based framework for ESP8266 WiFi-enabled microcontrollers. Intended for use in both commercial and open source projects.Originally based on, but substantially different from, the Espressif IOT RTOS SDK.

Bin Files

At first you need to download three bin files otaboot.bin, rboot.bin and blank_config.bin. The OTAboot.bin contains the Lifce-Cycle-Manager part. The rboot.bin contains the bootloader for the ESP8266. The blank_config.bin in just a blank config file. Now connect your device to your FTDI adapter in flash-mode.

Latest Release

NEW RELEASE
LifeCycle Manager 2
Version: 2.1.2
otaboot.bin


Boot loader
Version: 1.4.2
rboot.bin


Prerequisite
Version: 1.4.2
blank_config.bin


Putting Device Into Flash Mode

To enable ESP8266 firmware flashing GPIO0 pin must be pulled low before the device is reset. Conversely, for a normal boot, GPIO0 must be pulled high or floating. Start in FLASH MODE – Press both buttons, release the RESET button and then release the PROGRAM button.

Go to the directory you made where you put the previously downloaded Root.bin, Blank_config.bin and Otaboot.bin files (e.g Downloads)

Open the Terminal app. Click the Finder icon in your dock. Click Go. Click Utilities. Double-click Terminal. Change to the downloads directory.

cd downloads

Use esptool.py to flash it in your device. First, erase flash:

esptool.py erase_flash

Normally, your ESPPort will be something like /dev/cu.usbserial-A50285BI. Then, set your device in flash-mode again, and flash the new firmware:

esptool.py -p /dev/cu.usbserial-A50285BI --baud 115200 write_flash -fs 1MB -fm dout -ff 40m 0x0 rboot.bin 0x1000 blank_config.bin 0x2000 otaboot.bin

Note: If you use an old version of esptool, you must change -fs 1MB to -fs 8m.


You must configure wifi network and OTA repository. To configure wifi settings, device generates its own Wifi in AP mode. You must connect to it in order to setup your wifi network. Simply take your iOS device, go to Setting -> Wi-Fi, and search a SSID with LCM- followed of last MAC address, connect to it, and wait a few seconds until a web appears showing you all wifi networks that the device has found. Select yours, and enter password. Don’t touch Join button yet!!

Software Installation

Now, you must configure OTA repository as well. It’s very important that you configure it right, because you can not change it in the future (If you make a mistake, you must erase and flash device again).

OTA repository:

AchimPieters/ESP8266-HomeKit-Temperature-Humidity-Sensor

OTA binary file:

Normally there is only one Bin file to select. but in this case there are more flavours. The DHT Sensor comes in two different flavours as describe in the hardeware preperation here above.. the DHT 11 and the DHT22. So the next step is to choos te correct DHT sensor you are using.

Update: 20-03-2021 Lateste firmware:

  • Version DHT11 GPIO2 Sensor / GPIO4 LED (dht11_gpio2.bin)
  • Version DHT11 GPIO4 Sensor / GPIO2 LED (dht11_gpio4.bin)
  • Version DHT22 GPIO2 Sensor / GPIO4 LED (dht22_gpio2.bin)
  • Version DHT22 GPIO4 Sensor / GPIO2 LED (dht22_gpio4.bin)

To finish initial setup, click Join button and wait about 7 minutes until process finish (While installation is working, device doesn’t show anything, and buttons don’t work). After that, LED turns on for a couple of seconds and you will be able to add your accessory to your HomeKit ecosystem using Home App. LCM will install your HomeKit device on your ESP.

Now you can add your HomeKit Temperature & Humidity Sensor by scanning the QR code below. To make the connection between your ESP and homekit takes a few seconds.

Testing the HomeKit Temperature & Humidity Sensor

 
 
DO YOU HAVE ANY QUESTIONS? LEAVE A COMMENT DOWN HERE.

Note: To produce and sell HomeKit compatible accessories, your company need to be certified for that (https://developer.apple.com/homekit/, If you’re interested in developing or manufacturing a HomeKit accessory that will be distributed or sold, your company must enroll in the MFi Program.) Espressif have their implementation of HomeKit framework, but it will give you it only if you have MFi certification (notice this text at the bottom of page you mentioned: Please note that the Espressif HomeKit SDK is available to MFi licensees only, and you need to provide the Account Number for verification purposes when requesting the SDK.).This project is a non-commercial implementation of HAP protocol, not meant for commercial use.


REFERENCE

Maxim Kulkin, esp-wifi-config (2019), Library to bootstrap WiFi-enabled accessories WiFi config, https://github.com/maximkulkin/esp-wifi-config Paul Sokolovsky, esp-open-sdk (2019), Free and open (as much as possible) integrated SDK for ESP8266/ESP8285 chips, https://github.com/pfalcon/esp-open-sdk Espressif Systems, esptool (2019), ESP8266 and ESP32 serial bootloader utility, https://github.com/espressif/esptool HomeACcessoryKid, life-cycle-manager (2019), Initial install, WiFi settings and over the air firmware upgrades for any esp-open-rtos repository on GitHub, https://github.com/HomeACcessoryKid/life-cycle-manager

Scroll to Top