AirGradient DIY and HomeAssistant

I recently ordered and assembled a kit from AirGradient for a CO2 and PM2.5 sensor for around $82
DIY Air Quality Sensor (airgradient.com)

By default it sends data to their API, but all of the code is fully open source so I can modify it to send anywhere. I have no idea of the best way to send it to HomeAssistant though. It want to post to an API endpoint with a JSON payload. Is there an easy way to have HomeAssistant listen for this or other suggestions? Someone on JeffGeerling’s blog mentioned they modified it to use MQTT and got it reporting to HA but didn’t link to any code.
Monitoring my home’s air quality (CO2, PM2.5, Temp/Humidity) with AirGradient’s DIY sensor | Jeff Geerling
Note: Jeff recently replied about using ESPHome to get the data in to HA. I haven’t travelled down that road either, but I’m open to trying

3 Likes

I’d personally do ESPHome. Esphome-devices.com has a sample configuration. ESPHome has a Native Home Assistant API that doesn’t need MQTT. MQTT should work, too, though. You might also be interested in Getting Started with ESPHome.

1 Like

Having just seen Jeff’s video, I’m going to build three of them and also wondering how it can be integrated. :slight_smile:

2 Likes

I have an AirGradient running with ESPHome and have created a little GitHub repo as a tutorial for other folks:

I also want to write something up on my blog in a few days on how I use this and which values are important.

For now, just open your window when the CO2 level is above 1000ppm. That is the threshold when you say: “It smells like someone died in here”.
Tested and verified with my girlfriend’s nose :wink:

6 Likes

Finally got around to soldering my kit together and the PM sensor is reading 0’s across the board. I’m unsure if I soldered it wrong, but the fan is spinning up so it’s definitely got something. I still need to 3D print the case, anyways.

[21:59:18][D][pmsx003:169]: Got PM1.0 Concentration: 0 µg/m^3, PM2.5 Concentration 0 µg/m^3, PM10.0 Concentration: 0 µg/m^3
[21:59:18][D][sensor:113]: 'Particulate Matter <1.0µm Concentration': Sending state 0.00000 µg/m³ with 0 decimals of accuracy
[21:59:18][D][sensor:113]: 'Particulate Matter <2.5µm Concentration': Sending state 0.00000 µg/m³ with 0 decimals of accuracy
[21:59:18][D][sensor:113]: 'Particulate Matter <10.0µm Concentration': Sending state 0.00000 µg/m³ with 0 decimals of accuracy

Here’s my ESPHome config for AirGradient:

esphome:
  name: air-gradient
  platform: ESP8266
  board: d1_mini

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:

wifi:
  networks:
  - ssid: 'ssid'
    password: 'pasword'
  reboot_timeout: 15min

captive_portal:

i2c:
  sda: D2
  scl: D1

font:
  - file: "font/helvetica.ttf"
    id: helvetica
    size: 10

display:
  - platform: ssd1306_i2c
    id: oled
    model: "SSD1306 64x48"
    pages:
      - id: page1
        lambda: |-
          it.printf(0, 0, id(helvetica), "CO2: %.0fppm", id(co2).state);
          it.printf(0, 10, id(helvetica), "PM25: %.0f", id(pm25).state);
          it.printf(0, 20, id(helvetica), "Hmdty: %.0f", id(humidity).state);
          it.printf(0, 30, id(helvetica), "Temp: %.0fC", id(temp).state);
# Maybe add a page later

interval:
  - interval: 5s
    then:
      - display.page.show_next: oled
      - component.update: oled

uart:
  - rx_pin: D5
    tx_pin: D6
    baud_rate: 9600
    id: uart1
    
  - rx_pin: D4
    tx_pin: D3
    baud_rate: 9600
    id: uart2

sensor:
  - platform: sht3xd
    temperature:
      id: temp
      name: "Temperature"
    humidity:
      id: humidity
      name: "Humidity"
    address: 0x44
    update_interval: 5s

  - platform: pmsx003
    type: PMSX003
    uart_id: uart1
    pm_1_0:
      name: "Particulate Matter <1.0µm Concentration"
      id: pm1
    pm_2_5:
      name: "Particulate Matter <2.5µm Concentration"
      id: pm25
    pm_10_0:
      name: "Particulate Matter <10.0µm Concentration"
      id: pm10

  - platform: senseair
    uart_id: uart2
    co2:
      id: co2
      name: "SenseAir CO2 Value"
    update_interval: 60s

Using these

to assist building my config file.

I’m gonna keep taking a look to see if I can fix it. I just hope I don’t need to order another PM sensor.

You could ask for help on the air gradient forum.
Achim from air gradient is really helpful!

Definitely double check the soldering order/connections. I did that wrong.

I would also recommend double checking the model number of the PM2.5 sensor you ordered. ESP Home has support for different models. When I had the wrong model in my config, I was getting all zeroes. Pretty sure pmsx003 is the correct value for the default sensor linked on AirGradient, but there could have been a mix up somewhere.

Finally, my sensors do read 0 at times. Get some particulates flowing and let it run for a few minutes!

Thanks for the responses! I think it looks like it’s working. I made this post at the AirGradient forums with a screenshot: Realistic values for PM 2.5? - Components - AirGradient

My parts have been ordered, just found another project via Google:

Adding my version of a ESPHome file to replicate the functionality of AirGradient, including reporting to the AirGradient API for this website in addition to HomeAssistant

2 Likes

Thanx for your code @ajfriesen. One thing I was wondering. Is there any way to have a some kind of slider (or similar) to set brightness of the display as it’s possible for NSPanel, see picture

I do not think that the display I am using is capable of adjusting brightness.

I’ve recently purchased the AirGradient DIY Pro kit which has a 128x64 display ilo original 64x48.

The display model in the yaml definition code should be updated to:

 model: "SH1106 128x64"  

& then above definitions work.

1 Like

Seems the link is dead?

https://github.com/ajfriesen/ESPHome-AirGradient/blob/b29d4ca229830bd35496d9e4654dc923209ff343/air-gradient.yaml

You can still find the YAML here:

1 Like

Thanks! Finally got my package (AirGradient DIY Pro kit with the additional SGP41 TVOC Module), and have set-up the first one! Made some additions/changes to the configuration found on your page.

1 Like

Getting errors after last ESPHome update, any clues on what to do? It is posted as a breaking change, but no clues there on what to use instead.

INFO Detected timezone 'America/Chicago'
Failed config

uart: [source /config/esphome/airgradient-pro-upstairs.yaml:83]
  - rx_pin: D5
    tx_pin: D6
    baud_rate: 9600
    
    ID 'uart1' is reserved internally and cannot be used.
    id: uart1
  - rx_pin: D4
    tx_pin: D3
    baud_rate: 9600
    
    ID 'uart2' is reserved internally and cannot be used.
    id: uart2
sensor.pmsx003: [source /config/esphome/airgradient-pro-upstairs.yaml:112]
  platform: pmsx003
  type: PMSX003
  
  ID 'uart1' is reserved internally and cannot be used.
  uart_id: uart1
  pm_1_0: 
    id: pm10
    name: Part. Matter <1.0µm Conc.
  pm_2_5: 
    id: pm25
    name: Part. Matter <2.5µm Conc.
  pm_10_0: 
    id: pm100
    name: Part. Matter <10.0µm Conc.
sensor.senseair: [source /config/esphome/airgradient-pro-upstairs.yaml:139]
  platform: senseair
  
  ID 'uart2' is reserved internally and cannot be used.
  uart_id: uart2
  co2: 
    id: co2
    name: SenseAir CO2 Value
  update_interval: 60s

Changed uart1 to uart_1 and uart2 to uart_2.
This per comment here: ESPHome 2023.4.0 - 19th April 2023 — ESPHome
This seems to have fixed it!

2 Likes

Need some help in adding SGP41 sensor as well
I added config like this

- platform: sgp4x
    i2c_id: bus_a
    address: 0x58
    update_interval: 60s
    voc:
      name: "VOC Index"
    nox:
      name: "NOx Index"
    compensation:
      humidity_source: humidity
      temperature_source: temp

and its not working. any help is appreciated

Did you check the config in my github? The sensor is working for me.