Building a Matter air quality monitor

06/11/2026

The finished air quality monitor: a black 3D-printed case with an e-ink screen showing temperature, humidity, CO2, TVOC, PM2.5, PM10, HCHO and an A+ IAQI score

The idea

I wanted to have an air quality monitor that can be connected to HomeKit and Home Assistant at the same time. Of course I could buy one, and it would probably be cheaper, but it wouldn’t be mine.

If you just want the code and the case, everything is in the repo.

Update (November 2026): I finally ported it to the ESP-IDF Matter SDK, and it now runs on Matter over Thread. Read about it in the update at the end.

Planning

First, I decided to use Matter because I like the idea of a protocol compatible with everything. Sadly, it hasn’t been adopted as much as I was expecting, but it is still the best solution for multiplatform. I also chose to use the Arduino IDE because the Espressif Matter SDK is a pain to get working. I don’t know why, but there are a thousand ways to install it and all of them give problems. I lost some flexibility, and at some point I will probably migrate to it anyway, but for something simple just for myself it is great. For hardware, I used an ESP32-C6 that I already had, an e-ink screen because I always wanted to play with one, and an M702 sensor because it looked accurate and has a good array of measurements for an indoor setup. Besides that, I wanted to (finally) do something useful with my 3D printer, so I decided to design my own case for it.

I already had some experience playing around with Matter and I understood the basics of the protocol, so my first step was going to the Matter ESP32 library. Sadly, as you can see, there are examples for humidity and temperature, but for the rest I had to read the library and try to understand its internals to make it work. 90% of my work, software-wise, was bridging that gap; there isn’t much documentation.

Parts

Wiring

Screen pin ESP32-C6-Zero
VCC 3V3
GND GND
SDA (DIN / MOSI) GP21
SCL (CLK / SCK) GP22
CS GP20
D/C GP19
RES GP18
BUSY GP14
Sensor pin ESP32-C6-Zero
VCC 5V
GND GND
TX GP0

Be careful: the sensor needs 5V and the screen 3.3V. Don’t mix them up.

I picked the pins to avoid the strapping pins (4, 5, 8, 9, 15), the native USB (12, 13) and UART0 (16, 17), so the board still boots and flashes normally with everything connected.

The M702 sensor, the ESP32-C6-Zero and the back of the e-ink screen wired together on a desk
Everything wired together, before it had a case.

First steps

ESP32 + Matter

I started with one of the examples as a base and built from there. As you can see, the base is very simple: first you have a setup where you connect to Matter, and then the loop where you read the sensor and send the readings to the Matter network. To make this work I did one thing at a time. First, I made sure I could commission my ESP32 to the Matter network. That was fairly straightforward since the example already does it. Of course, I removed the SSID and the network password and used Bluetooth to get the credentials from my phone. On first boot the device advertises over BLE, the Home app sends the Wi-Fi credentials during pairing, and Matter stores them, so nothing is hardcoded. If you hold the BOOT button for 5 seconds, it decommissions itself and you can pair it again.

The M702 sensor

The second step for me was connecting the M702 and getting the readings. The sensor is powered by 5V because it has a fan to move the air through it, and then there is simply a TX cable that sends the digital signal. Finding documentation on how to read from this sensor was kind of painful; Scribd was the place where I found it. With that, it is just a matter of reading the bytes and then doing a checksum to see if the data is corrupted. The sensor sends a 17-byte frame at 9600 baud that starts with 0x3C 0x02, and the last byte is the sum of all the others:

while (m702Serial.available() >= 17) {
  if (m702Serial.read() == 0x3C && m702Serial.peek() == 0x02) {
    buffer[0] = 0x3C;
    uint16_t checksum = 0x3C;
    for (int i = 1; i < 17; i++) {
      buffer[i] = m702Serial.read();
      if (i < 16) checksum += buffer[i];
    }

    if ((checksum & 0xFF) == buffer[16]) {
      co2  = (buffer[2] << 8) | buffer[3];
      hcho = (buffer[4] << 8) | buffer[5];
      tvoc = (buffer[6] << 8) | buffer[7];
      pm25 = (buffer[8] << 8) | buffer[9];
      pm10 = (buffer[10] << 8) | buffer[11];
      temp = (buffer[12] & 0x7F) + (buffer[13] / 100.0);
      if (buffer[12] & 0x80) temp = -temp; // the top bit is the sign
      hum  = buffer[14] + (buffer[15] / 100.0);
    }
  }
}

One thing the datasheet doesn’t make obvious: the gas readings (CO2, TVOC and HCHO) are garbage for the first few minutes while the sensor warms up. So for the first 5 minutes the screen shows -- for those values and they are not sent to Matter at all. Temperature, humidity and PM are fine from the start.

First test: the e-ink screen showing the raw sensor readings as plain text
The first readings from the sensor on the screen, just plain text.

The screen

Again, I checked the base example given (link to the library) and worked from there. I used the GxEPD2 library as recommended by the example.

The e-ink screen with the final card layout, still outside the case and wired to the sensor
The final layout.

Putting it all together

So now it was just a matter of combining all the code to show the sensor readings on the screen and update the data through Matter.

The Matter sensor issue

Here I realized that most of the sensors didn’t have a class in the Arduino library. For humidity and temperature it is very simple: just add the class and use the method to update the value. For the rest, I had to go one level down and use the esp_matter API directly. There are a lot of things going on there, but basically in Matter a device is made of endpoints, and each endpoint has clusters that hold the actual values. So I had to create an Air Quality Sensor endpoint and add a concentration measurement cluster to it for each reading (CO2, TVOC, HCHO, PM2.5 and PM10), plus an Air Quality cluster for the overall rating. I am not a big C++ enjoyer, so it took me a while to understand it and make it work.

All the concentration clusters are configured the same way, so I ended up with a small helper. This is the part I couldn’t find documented anywhere:

void addConcentrationCluster(endpoint_t* ep, ConcentrationCreateFn createFn,
                             uint8_t unit, float minVal, float maxVal) {
  cluster::concentration_measurement::config_t cfg;
  cfg.measurement_medium = 0;  // Air
  cfg.feature_flags = cluster::concentration_measurement::feature::numeric_measurement::get_id();
  cfg.features.numeric_measurement.measurement_unit = unit;
  cfg.features.numeric_measurement.min_measured_value = nullable<float>(minVal);
  cfg.features.numeric_measurement.max_measured_value = nullable<float>(maxVal);
  cfg.delegate = nullptr;
  createFn(ep, &cfg, CLUSTER_FLAG_SERVER);
}

// CO2 is reported in ppm, everything else in µg/m³
addConcentrationCluster(aqEndpoint, cluster::carbon_dioxide_concentration_measurement::create,
                        MEAS_UNIT_PPM, 400.0f, 5000.0f);
addConcentrationCluster(aqEndpoint, cluster::pm25_concentration_measurement::create,
                        MEAS_UNIT_UGM3, 0.0f, 999.0f);
// ...same for TVOC, HCHO and PM10

Updating a value is then just a matter of writing to the MeasuredValue attribute of the right cluster with esp_matter::attribute::update.

A couple of small things I added along the way:

E-ink, the secret drawback

The biggest problem with the screen is that e-ink screens deteriorate really quickly with each redraw (I didn’t know about that). You can do partial redraws, but over time they generate shadowing effects that you can erase with a full redraw, which wears the screen more, so you have to balance it. In my case, I decided to only redraw when a value changed enough to be noticeable, to avoid the noise of the sensor itself and ruining the screen too quickly. On top of that, every 50 minutes it does a full redraw to avoid ghosting. Maybe I could fine-tune it in the future, but for me it is enough. Next time I will probably use another kind of screen, but I always wanted to play with one.

IAQI

There is this index that gives you a general idea of the condition of the air without having to check each specific value. The sensor itself doesn’t give you this value, and there are many ways to calculate it, but basically you check each value and divide it into categories from great to bad. The result is the worst value of all of them, because if one is bad for your health, the air itself is. I checked the general safe values for each parameter and created the categories from that. This isn’t very precise, but the IAQI isn’t either.

These are the thresholds I ended up with. For PM I used the bands from the European Air Quality Index:

Grade CO2 (ppm) PM2.5 (µg/m³) PM10 (µg/m³) TVOC (µg/m³) HCHO (µg/m³)
A+ ≤ 600 ≤ 10 ≤ 20 ≤ 300 ≤ 30
A ≤ 800 ≤ 20 ≤ 40 ≤ 500 ≤ 60
B ≤ 1000 ≤ 25 ≤ 50 ≤ 1000 ≤ 100
C ≤ 1500 ≤ 50 ≤ 100 ≤ 3000 ≤ 200
F > 1500 > 50 > 100 > 3000 > 200

Humidity also counts, but only as a comfort penalty, so it can never push the grade lower than B: under 30% or over 60% gives an A, and under 25% or over 70% gives a B.

The nice part is that Matter’s Air Quality cluster has its own scale (Good, Fair, Moderate, Poor, Very Poor), so I map my grade onto it, and HomeKit and Home Assistant show the same rating as the screen.

The case

I used FreeCAD, which took me a while to get used to. I had to print several prototypes that were too ugly even for me, but I got a good result. An engineer would probably see my CAD and want to cut off my hands, but it works: the things stay inside, it is stable, and it is enough for me. I am new to the world of 3D printing, so I had to learn a few tricks. To hold it all together, I opted for some M2 and M3 brass heat-set inserts that let me use normal screws. The 3MF file is in the repo if you want to print your own.

One of the early case prototypes held in hand
The first prototype.
The front part of the final case with brass heat-set inserts, next to the back of the screen
The front of the final case, with the brass inserts already in.
The case backplate with standoffs, the ESP32 holder and the sensor air grille
The backplate, where the sensor and the ESP32 are attach.

Update: ESP-IDF and Thread

In the end I didn’t wait for a V2. I ported the firmware to the ESP-IDF Matter SDK (ESP-IDF v5.5.6 with esp-matter 1.5, the same esp-matter version that the Arduino core uses). The Arduino version is still in the repo and still works over Wi-Fi; the new one lives in the idf/ folder.

This time the install wasn’t as bad as I remembered. Instead of installing esp-matter by hand, I pulled it from the ESP component registry, so the only thing I had to install was ESP-IDF itself. The hardware, pins, screen layout and Matter endpoints are the same, but without Arduino I had to replace GxEPD2 with a small e-ink driver of my own, reusing the same Adafruit GFX fonts.

Matter over Thread

The ESP32-C6 has an 802.15.4 radio, so it can join a Thread network instead of Wi-Fi. My Apple TV and HomePod already act as Thread border routers, so the device talks to them directly, and Wi-Fi is disabled completely. Bluetooth is still used, but only for pairing. Since it is always plugged in, it runs as a full Thread device, so it can also route traffic for other Thread devices in the house.

A real pairing code

The Arduino version uses the shared example credentials, so every device has the same pairing code. Now each device gets its own passcode, discriminator and device certificate, generated by a script and stored in a separate factory partition. The certificate is still signed by the public Matter test authority, so HomeKit keeps calling it uncertified, but at least the pairing code is mine.

The part I liked most: while the device isn’t paired, the e-ink screen shows the QR code and the manual code, so I don’t need the serial monitor anymore. To draw it, the device needs the passcode, but the factory data only stores a verifier derived from it, so the script also saves the passcode in the factory partition.

The e-ink screen showing a Matter pairing QR code, the manual pairing code and a hint to hold BOOT for 5 seconds to reset
The pairing screen, shown while the device isn’t paired.

Because the pairing data lives in its own partition, a factory reset (holding BOOT for 5 seconds, or removing the device from the last Home app it’s paired with) wipes the pairing but keeps the same QR code.

One HomeKit problem cost me some time: pairing failed with a “database save failed” error. The fix was deleting the empty leftover entries in iOS Settings > General > Matter Accessories from my earlier tests.

A small screen improvement

While I was at it, I added a small bar of squares under each value, shaded from black to white. Five squares means A+ and one square means F, so you can see which reading is pulling the IAQI down without remembering the thresholds. I added this to both the Arduino and the ESP-IDF versions.

The e-ink screen showing the eight reading cards, each with a row of shaded squares under the value indicating its grade
The new layout, with the grade bars under each value.

Conclusion

I am really happy with the device. It works well: my wife can ignore it on HomeKit, I can check it on Home Assistant, and I get to feel important for being early on a protocol that may never fully take off. It is not perfect, though: Home Assistant reads the TVOC value with the wrong unit (ppm instead of µg/m³) and ignores the HCHO completely. HomeKit doesn’t show it either, so the formaldehyde only shows up on the device’s own screen, a small point in favour of keeping it.

The sensor in the HomeKit app showing air quality Good, PM2.5, PM10, VOC density and CO2 level
HomeKit
The sensor in Home Assistant showing air quality, CO2, humidity, PM2.5, PM10, temperature and VOCs in ppm
Home Assistant

I learned a lot about how Matter works, how ESP32 programming works, and how annoying it is to design something in 3D. If I ever decide to do a V2, I probably won’t use an e-ink screen: it looks cool, but it is not the right technology for this because of the wear from redrawing. The other thing I wanted, moving to the ESP-IDF Matter SDK and Matter over Thread, is already done (see the update).

Feel free to check out the repo to build your own, or to point out my mistakes.