Environment Monitor for Home Assistant With NodeMCU and DHT22

by taste_the_code in Circuits > Sensors

1857 Views, 6 Favorites, 0 Comments

Environment Monitor for Home Assistant With NodeMCU and DHT22

Environment Monitor with DHT22 and NodeMCU in less than one hour - Home Assistant Project

I started exploring Home Assistant and in order to be able to start creating some automation, I needed to have the current temperature and humidity values from my living room inside so I can act upon them.

There are commercial solutions available for this but I wanted to build my own so I can better learn how Home Assistant works and how to set up custom devices with it and ESPHome.

The entire project is built on a custom-made PCB that I designed as a project platform for NodeMCU and was then manufactured by my friends at PCBWay. You can order this board for yourself and have 10 pieces manufactured for just $5 at: https://www.pcbway.com/project/shareproject/NodeMCU_Project_Platform_ce3fb24a.html

Supplies

video.00_00_59_11.Still003.jpg

The Custom PCB

video.00_00_42_04.Still001.jpg
video.00_00_44_19.Still002.jpg

I designed this PCB to serve as a project platform after spending so much time soldering custom NodeMCU projects on prototyping PCBs.

The PCB has a position for NodeMCU, I2C devices, SPI devices, relays, a DHT22 sensor as well as UART and an HLK-PM01 power supply that can then power the project from AC mains.

You can check a video of the design and ordering process on my YT channel.

Solder the Components

MVI_0653.MP4.00_02_42_00.Still001.jpg
MVI_0654.MP4.00_01_53_11.Still001.jpg
MVI_0654.MP4.00_04_26_25.Still002.jpg
MVI_0655.MP4.00_00_08_04.Still001.jpg
MVI_0655.MP4.00_05_49_05.Still002.jpg
MVI_0656.MP4.00_00_30_22.Still001.jpg
MVI_0657.MP4.00_01_42_19.Still001.jpg

Since I don't want to solder the NodeMCU directly to the PCB, I used female pin headers and soldered them first so I can then plug the NodeMCU into them.

After the headers, I soldered the screw terminals for the AC input as well as for 5V and 3.3V outputs.

I also soldered a header for the DHT22 sensor and the HLK-PM01 power supply.

Test Out the Voltages and Sensor

MVI_0659.MP4.00_00_24_08.Still001.jpg
MVI_0661.MP4.00_02_44_29.Still001.jpg
MVI_0662.MP4.00_00_02_01.Still001.jpg
2022-11-23 06-16-11.mp4.00_00_04_15.Still001.jpg

Since this is the first time that I use this PCB for a project, I wanted to make sure that I haven't messed up something so before connecting the NodeMCU. I wanted to test out the board voltages that everything is OK. After first testing out the 5V rail without the NodeMCU plugged in, I plugged in the NodeMCU to make sure that it was getting the 5V and also that it was providing the 3.3V from its onboard regulator.

As a final test, I uploaded a sample sketch for the DHT22 sensor from the DHTStable library so I could verify that the DHT22 works properly and that I can successfully read out the temperature and humidity.

Add the Device to Home Assistant

2022-11-23 06-59-52.mp4.00_01_54_08.Still001.jpg
2022-11-23 06-59-52.mp4.00_09_05_02.Still002.jpg
2022-11-23 06-59-52.mp4.00_18_20_26.Still003.jpg
2022-11-23 06-59-52.mp4.00_24_40_15.Still004.jpg
2022-11-23 06-59-52.mp4.00_28_27_24.Still005.jpg
2022-11-24 09-04-50.mp4.00_01_47_07.Still001.jpg

Since everything worked as expected, I then proceeded to install ESPHome to my Home Assistant setup and I've used it to create a new device and upload the provided firmware to the NodeMCU. I had some trouble using the web upload from ESPHome to flash the provided firmware but in the end, I downloaded the ESPHome Flasher and I was able to upload the firmware using that.

Once the initial firmware was added to the device, I modified the .yaml file for it to add the DHT22 handling section and re-uploaded the firmware, now using the over-the-air update from ESPHome.

This went without a hitch and as soon as it was done, the device showed the temperature and humidity values in the dashboard.

Make a Permanent Enclosure

MVI_0663.MP4.00_00_10_06.Still001.jpg
MVI_0664.MP4.00_00_57_24.Still001.jpg
MVI_0665.MP4.00_02_28_16.Still001.jpg
MVI_0665.MP4.00_03_28_04.Still002.jpg
MVI_0665.MP4.00_04_09_16.Still003.jpg
MVI_0665.MP4.00_04_45_16.Still004.jpg
MVI_0666.MP4.00_00_24_15.Still001.jpg

I wanted this monitor to be mounted next to my current thermostat that I have in my home for the pellet stove so I used an electrical junction box to make an enclosure. The DHT22 sensor is mounted in a hole made in the electrical box so it can monitor the conditions on the outside of the box and not be affected by any heat coming out from the power supply.

To prevent any heat build-up in the box, I also made two holes on the bottom and top of the electrical box so air can circulate through it and release any heat.

Mount in My Living Room

MVI_0668.MP4.00_00_06_17.Still001.jpg

To mount the electrical box, I used double-sided tape to stick the box to the wall and to the thermostat next to it.

For now, this is only a test and I might decide that I want to change this location so I did not want to make any new holes in the wall.

Next Steps

If everything goes well, I might upgrade this project to act as a thermostat for my pellet stove so I could entirely ditch the commercial one. It all depends on how Home Assistant will work out for me in the long run but we'll have to wait to see that.

In the meantime, if you liked this project, be sure to also check my other ones on Instructables as well as my YouTube channel. I have many others coming in so please consider subscribing as well.