Creating an Air Quality Sensor using an SDS011 and ESPHome

Cyan Automation
3 min readAug 31, 2020
Photo by Daria Rom on Unsplash

After measuring temperature and humidity, the next step in measuring and tracking the air in your home might be air quality. Air quality is broad - comprising dust, pollen, pollutants, VOCs and even gas, smoke and carbon monoxide. For this guide, we’re going to focus on the more general aspect of air quality, and tracking Small and Fine inhalable particulates, also know as particulate matter. At the end, you’ll have a working air quality sensor for ESPHome that you can track in your Home Automation Hub.

Getting Started

The SDS011 is a helpful sensor to track particulate matter (aka particular pollution) at 2.5 and 10 micrometers. The SDS011 is available widely on the internet – I got mine for a fair price from China, but had to wait patiently for it to arrive. To start, ensure that your ESP32 has been set up correctly in ESPHome and online. When connecting your SDS011, connect the Power and Ground, followed by the TX and RX pin.

As the communication is done via UART, you need to have an UART bus set in your configuration with the rx_pin connected to the TX pin of the SDS011 and optionally the tx_pin connected to the RX Pin of the SDS011. Additionally, you need to set the baud rate to 9600.

by Floris Wouterlood at https://bit.ly/2DgqCdL

Once this is done, you will need to create the SDS011 in the YAML configuration for your ESP32, by following the template on the ESPHome Site. In my case – I’ve gone for the PM 10 sensor only, but you can create the PM 2.5 sensor at the same time. Here is what it looks like in YAML:

Remember: If update_interval is equal to 0min, the SDS011 will be set to continuous measurement and will report new measurement values approximately every second. This will drastically reduce the life of your SDS011 and highly recommended against.

Making It Work

Now that you’ve defined the sensor, click SAVE then UPLOAD, and wait for your ESP32 to re-compile and re-upload successfully. Following a restart of Home Assistant, it would’ve imported the PM 10 sensor into your Entities list, and you should already be able to start seeing it report values.

Now, the particulate concentration values aren’t very meaningful unless you are continually looking at them each and committed them to memory. What’ll be more helpful is to create a Template sensor to define the tiers of concentration levels, and convert them into something intelligible. Thankfully, DEFRA’s Daily Air Quality Index has already done this for us – and you can see the bands at this page. By taking these, and creating a Template sensor – we will have a new sensor that will tell us if the air surrounding the SDS011 is Good, Concerning, Very Poor or Harmful.

And finally, here is what it looks like in YAML:

--

--

Cyan Automation

Marc’s tips on building your Smart Home with Home Assistant, Shelly and ESPHome.