Introduction: Temperature and Humidity Node for HomeKit (MQTT)

The goal of this Instructable is to create a sensing element node that can capture temperature and humidity readings and publish it to an MQTT topic to be used in a "smart home" instance.

I wanted to make over a cost-effective solution for creating my ain temperature and humidity detector that rear end be integrated into Apple HomeKit. The problem is that secure HomeKit devices and sensors can comprise expensive Beaver State difficult to obtain conditional your region. With some research, I stumbled upon an amazing project titled Homebridge. As cited from their Github, "Homebridge is a whippersnapper NodeJS host you can ply on your interior network that emulates the iOS HomeKit API". In that location is an abundance of information of mise en scene skyward Homebridge on their site, and I chose to run my Homebridge instance on a Raspberry PI model 3B.

I besides wanted to produce the detector so that it give the sack be used in other "smart dwelling house" solutions such A Home Assistant and thus made the decision to make use of the MQTT communicating protocol for the project.

Supplies

The pursual supplies are required to create the sensor lymph node:

  1. ESP-01 Module (or other ESP8266 variance)
  2. Whatsoever 5V 1A Great power supply
  3. ESP8266 Programmer or USB to TTL Consecutive convertor
  4. 3.3V voltage governor
  5. AM2301 (DHT22) board module
  6. Male / Female power adapters
  7. Any enclosure for your components
  8. Hot glue
  9. Solder / Solder iron
  10. An in operation MQTT server*
  11. An operating Homebridge instance

Optional supplies

  1. 3D Printer or 3D printing process service (for enclosure)
  2. Raspberry Principal investigator

Step 1: Downloading Required Software

The number one step of the project is to configure the WiF module (ESP8266) to transmit with your MQTT server

Before you bathroom start to program the ESP8266, you will have to download some software first.

  • Download and install the latest Tasmotizer .exe for Windows from this link. Tasmotizer is a tool that can buoy be used to flash the ESP8266 board with custom firmware. More than data about Tasmotizer throne be found here.
  • We will embody flashing the ESP8266 with firmware renowned as Tasmota. Tasmota is opensource firmware for ESP8266 devices with a wide rate of functions, including MQTT. Download the latest tasmota.bin file from this liaison. However, I choose to use build 8.5.0.

In the next step we will prepare the required hardware to flashy the ESP8266 with Tasmota.

Footstep 2: Prepare Hardware to Flash ESP8266

Ready to flash the ESP8266 with Tasmota using the Tasmotizer tool, the ESP8266 needs to be designed to allow microcode flashing. Luckily this is as easy atomic number 3 connecting pin GPIO_0 with Ground. An easy way to achieve this is to solder male and feminine header pins to the ESP8266 programmer. as shown in an attached photos.

Steps:

  1. Base the ESP8266 into the programmer
  2. Connect the cardinal wires that will at once connect GPIO_0 and Ground together.
  3. Before connecting the programmer to your Computer, keep to the next step.

Step 3: Bright Your ESP8266 With Tasmota

Therein step we will be flashing your ESP8266 with Tasmota.

  1. Surface Tasmotizer along your figurer.
  2. With your ESP8266 in the coder and GPIO_0 and Establish socially connected, plug the programmer into your computer.
  3. Click the brush up button in Tasmotizer to review the port, IT should update. Please note that your embrasure number will most likely comprise various.
  4. In the pick out image section of Tasmotizer click on open, and select the tasmota.bin file you downloaded in a old step.
  5. Snap on Tasmotize! and wait for the process to complete, You will be promted with a message when the process finished. Dawn on OK.
  6. Unplug the programmer from your information processing system
  7. Disconnect your GPIO_0 to Footing connection on the programmer and plug the programmer back into your computer.
  8. Voyage support to the Tasmotizer program
  9. Do sure the correct port is selected
  10. Penetrate the "Send config release"
  11. Enter your WiFi SSID and Password (please short letter this must live a 2.4 GHz WiF web due to an ESP8266 hardware limitation) and click spare
  12. Time lag about for 20 seconds
  13. Clink the "Get Information science" button.
  14. If everything worked, you should be presented with a valid IP address for your newly flashed ESP8266 module. Also if the module does not provide you with an IP come up to, log into your router and scan for whatever inexperient devices, operating theater use an application like FING to find network devices.

*Troubleshoot: make a point the sort out port was selected in Tasmotizer, and that your ESP8266 is in flash musical mode (GPIO_0 and Dry land attached for step 1-6. For footmark 8-14, GPIO_0 and ground should not be connected).

In the close step, we will comprise configuring the wifi mental faculty for MQTT and to accept the Temperature and humidity sensor

Step 4: Tasmota Configuration on ESP8266

In my model, the ESP8266 joined my WiFi network with an IP Address of 192.168.1.36. I will now enter upon this in my web browser.

  1. Come in the IP Address that Tasmotizer provided you into your browser and you testament equal connecting to your instance of Tasmota running on your ESP8266.
  2. Click on Configuration --> Configure Other and change your device name and friendly name to something appropriate, I will use "Demo1"
  3. Next we are loss to configure the MQTT server past clicking Configuration --> Configure MQTT (At this stage I am presumptuous you have a running MQTT broker.) You have to fill out in your MQTT information here.
    1. Enter your MQTT host address
    2. Enter your MQTT larboard
    3. For client I will be victimisation "Demo1"
    4. In my showcase, I have a local MQTT server that is not exposed over the internet no Username or Word, you should enter the appropriate Username and password.
    5. I will also update the Topic to "Demo1"
  4. Click on preserve and delay for the module to restart.
  5. Now I want to update the interval that the mental faculty will post readings via MQTT to 5 seconds for this demo
    1. Navigate to Shape --> Configure Logging and update telemetry scene to something appropriate to your inevitably. A practical value for a historical macrocosm conditions will be around 10 minutes.
  6. Finally we want to configure the module to accept values from the A2301 (DHT22) sensor module.
  7. Navigate to Configuration --> Configure mental faculty and set the type for GPIO_2 to be AM2301 (2). Click keep and expect a some seconds before navigating to the main menu.
    1. At this stage you will see the module presents you with Temperature and humidness readings of "cipher". In one of the adjacent steps we will connect the Detector to the ESP8266 to fix this.

In the next step we will be connecting the ESP8266 to a power supply and AM2301 sensor to provide USA with real sensing element readings.

Dance step 5: MQTT Frame-up Confirmation

Earlier finalizing the project and creating a nice enclosure, I'd suggest playing a quick test run using a breadboard and power add.

  1. Connect the ESP8266 and AM2301 room faculty to a 3.3V power supply. The ESP8266 gameboard will be damaged if you use a greater emf.
  2. Link up the data stick of the AM2301 board module to the GPIO_2 pin of the ESP8266
  3. Turn on the superpowe supply and hopefully no deceptio smoke escapes from the devices.
  4. After a few seconds, navigate to the IP address of your ESP8266 happening a browser along the same network. At this degree the AM2301 readings should embody telescopic and showing actual values and non NULL.
  5. To aver that your MQTT configuration works, download a free Windows app from the windows store known as MQTT Explorer
  6. Connect the coating to your MQTT server past entering your MQTT broker details and clicking "Get in touch"
  7. Your ESP8266 will follow broadcasting an MQTT message at the interval you configured earlier to the "tele/Demo1/SENSOR" topic.

The temperature and humidity message payload is a JSON targe with format:

              

{

"Time": "2020-12-26T12:54:33",

"AM2301": {

"Temperature": 27.1,

"Humidity": 57.3,

"DewPoint": 17.9

},

"TempUnit": "C"

}

This JSON message will later be parsed to be consumed the Homebridge software package to expose the sensor to Apple HomeKit

Step 6: Final exam Circuit

The closing circuit to be embedded in the enclosure (next step) is very simple.

The ESP8266 and AM2301 (DHT22) needs 3.3V to operate. For this reason a D.C. step-down converter (3.3V) was used. Please refer to the attached plot for citation.

Depending on your needs the king delivery can be altered, atomic number 3 long as the ESP8266 entirely gets 3.3V. For this reason the stone's throw-down convertor is not in the schematic.

Footmark 7: Enclosure

The final enclosure I went with was designed in Fusion 360 and exported to be 3D printed. The files to print can comprise downloaded from this connec.

If you do not bear entree to a 3D pressman, any electronics or twin enclosure should do the fast one.

Step out 8: Homebridge Setup

*This Instructable assumes that you have a track illustration of Homebridge on your topical network.

  1. To desegregate the MQTT temperature and humidity sensing element into your Homebridge case, navigate to the Homebridge plugin store and search "MQTT".
  2. Install the homebridge-mqttthing plugin an restart your Homebridge instance.
  3. Navigate to your Homebridge shape file and add two new accessory entries as shown below:
              

"accessories": [

{

"add-on": "mqttthing",

"eccentric": "temperatureSensor",

"name": "Demo1 Temperature",

"url": "http://192.168.1.98:1883",

"username": "",

"password": "",

"topics": {

"getCurrentTemperature": {

"topic": "tele/Demo1/Detector",

"apply": "give JSON.parse(substance).AM2301.Temperature;"

}

}

},

{

"accessory": "mqttthing",

"type": "humiditySensor",

"name": "Demo1 Humidity",

"url": "http://192.168.1.98:1883",

"username": "",

"watchword": "",

"topics": {

"getCurrentRelativeHumidity": {

"topic": "tele/Demo1/Detector",

"apply": "yield JSON.parse(message).AM2301.Humidity;"

}

}

}

],

As you hindquarters see the MQTT payload of the temperature and humidity needs to be formatted for Homebridge to understand it. You can now save your Homebridge configuration and re-start IT.

When you now navigate to your Homebridge accesories, you should see two new entries (Demo1 Temperature and Demo1 Humidity).

You can now besides navigate to your Home app along your apple device and the temperature and humidity sensor will appear there likewise.

Atomic number 4 the First to Share

Recommendations

  • Anything Goes Contend 2022

    Anything Goes Contest 2022