Walk into any electronics store, and you'll find plenty of temperature sensors priced anywhere between $15 to $50. Even if you get past the price and buy a fancy one, you'll be disappointed to know that they often work in just one ecosystem. If you pick the wrong one or you want another option, you're looking at some very expensive paperweight.
But, there's a better way. Tiny ESP32 boards have already become my cheapest home network upgrade, and by just adding a sensor and some code, you can make your own temperature sensor. It's just as good as the ones you'll find on the market, and it works with most if not every, smart home app—meaning no compatibility issues whatsoever.
You need less hardware than you think
The handful of components behind a $4 smart sensor
The entire build revolves around two major components. The first is an ESP32 development board that crucially comes with native support for the Matter protocol. Now there are tons of these available on Amazon and AliExpress, in a lot of different variants. Thankfully, this project doesn't necessarily rely on buying the more expensive ESP32-S3 variants, so you can get away with just about any ESP32 board you can get your hands on.
Generally speaking, you can pick your board anywhere between $1 to $3 on AliExpress. Amazon offers faster delivery, but the board alone can cost $5 or higher. I've wasted money on the wrong ESP board before, but thankfully, this runs on my entire collection.
The next is a DHT22 temperature and humidity sensor. It's available on AliExpress for $0.99 (or even free on some listings) and can measure temperatures from -40°F to 176°F with ±0.9°F accuracy. Humidity is measured from 0 to 100% at ±2% accuracy. These usually come on a breakout board that exposes the power, ground, and data pins on the sensor, but if yours didn't, you'll also need a 4.7kΩ pull-up resistor. You can use a breadboard and jumper wires to connect the DHT22 sensor with the ESP32 board.
ESP32
- Brand
- Espressif
- Connectivity Features
- Wi-Fi, Bluetooth
ESP32 is a low-cost microcontroller with built-in Wi-Fi and Bluetooth, widely used for IoT projects and DIY electronics.
Matter is the real breakthrough
One standard that makes every ecosystem play nice
Matter is a smart home standard backed by Amazon, Apple, Comcast, Google, SmartThings, and the Connectivity Standards Alliance (previously known as the Zigbee Alliance). That means it'll show up natively in Google Home, Apple HomeKit, Amazon Alexa, and Home Assistant without any proprietary cloud, bridge, or subscription. You will, however, need a hub device such as a smart speaker or streaming device to use them.
Before Matter, getting a DIY sensor to talk to Google Home required API keys, cloud relays, or custom integrations—none of which are particularly stable or private. Matter, however, is an IP-based protocol that runs directly over your existing Wi-Fi (or Ethernet or Thread) network. When you add a Matter device to your smart home, communication stays entirely on your local network. It even supports cameras now, but there are some gotchas to watch out for.
Additionally, Espressif, the company behind the ESP32 chip family, is an active member of the Connectivity Standards Alliance and ships an open-source SDK for building Matter-compatible Wi-Fi devices. The Arduino ESP32 package includes a MatterTemperatureSensor class that handles all the Matter protocol compliance, including integration with Google Home, Amazon Alexa, Apple HomeKit, and more.
Putting it together takes minutes
Simple wiring with no custom PCB required
As mentioned before, the hardware side is quite simple and only needs three connections. Connect the DHT22's VCC or power pin to the 3.3V pin on the ESP32, its GND to any ESP32 ground pin, and the DATA pin to GPIO4. If you're using a resistor, place it between the DATA pin and the 3.3V line. This pull-up is required for the single-wire protocol that the DHT22 uses and prevents phony readings.
And that's it. You can experiment on a breadboard if you're only prototyping or solder everything directly if you're comfortable. Finding an enclosure should be easy enough, but you can simply use double-sided tape to mount the sensor anywhere, and it'll work just fine as long as the sensor pins maintain contact with the ESP32.
The software is surprisingly painless
Flashing firmware and getting the sensor online
The software side will feel a little tricky, and I did end up with a 125-line sketch to get everything to work, but it also includes a ton of debugging and information messages, which make troubleshooting and monitoring user-friendly. You will, however, need to set up your Arduino IDE correctly.
Specifically, you'll need to install both the ESP32 board support package and the Adafruit DHT sensor library. You will also have to change your partition scheme to Huge APP (3MB No OTA / 1MB SPIFFS) and make sure the IDE erases all flash memory before flashing the code. Both options are available in the Tools section of the Arduino IDE. You'll find the sketch on this GitHub repository along with the wiring diagram. Make sure to swap in your Wi-Fi credentials before flashing.
Some ESP32 models will require you to hardcode your Wi-Fi credentials in the sketch. If you don't want to do that, you can use BLE commissioning instead, where the home app provides Wi-Fi credentials over Bluetooth during the pairing process. Either way works, but in my opinion, hardcoding Wi-Fi credentials isn't an issue for a custom sensor that's not going to leave your home network.
Arduino IDE
- OS
- Windows, Linux, macOS, Web
- Developer
- Arduino
- Price model
- Free
Arduino IDE is a beginner-friendly development environment used to write, compile, and upload code to Arduino boards, ESP32s, and other microcontrollers.
It works everywhere that matters
Adding it to Home Assistant, Google Home, Apple Home, and more
The Matter commissioning flow is the same across every platform. Assuming your code is correctly flashed, you'll see a link for a QR code and a manual pairing mode appear in the serial monitor. You can use either to pair with the sensor.
In Google Home, tap the plus icon in the top right to add a new device, tap Matter-enabled device, and scan the QR code. In Apple HomeKit, go to Add Accessory and do the same. Home Assistant handles Matter devices via a custom integration that you'll find in the Devices and integrations section in the settings, although it should automatically detect the device and show you a prompt to add it.
You also get multi-admin support, meaning you can pair one device with multiple ecosystems at the same time. So if you pair your sensor with your Google Home but later decide you'd also want temperature data in your Home Assistant instance, you can add the same sensor in Home Assistant again without affecting how it works with Google Home. Both platforms will see the live temperature data from the same physical sensor, all without needing the cloud.
The results are better than expected
Accuracy and reliability in the real world
Once it's running, the DHT22 updates every two seconds at the sensor level; you can choose when to send that data over to the hub. Once every 30 seconds is reasonable for ambient temperature monitoring and keeps network chatter to a minimum. The readings are accurate enough to drive automations.
I turned my old phone into a wall-mounted presence sensor and automated my entire home
I automated my home with a dead phone.
The ESP32 also draws very little power at idle, and with a 5V charger feeding it, this sensor will run indefinitely before you notice even a cent on your power bill. Tuck the whole thing into a small enclosure with a ventilation slot, and you have a finished sensor that looks clean on a shelf-and costs less than a cup of coffee.