Malloc Array Airgradient ESP home Repository

Dear @MallocArray,

Are you willing to open de repo for pull requests / issues for other developers?
Really like your ESPhome configuration :).

MallocArray/airgradient_esphome: ESPHome definition for an AirGradient DIY device to send data to HomeAssistant and AirGradient servers (

Kind regards,


It is open already; did you try something and receive an error?

1 Like

I’ll certainly consider PRs. It should already be open for PRs, but I do need to write out more what my intended goals are with this repo so expectations can be understood

1 Like

Im following this. Just rebuild my complete config for the ONE. Im making most things modular so the main config will have includes for every sensor so you can easily mix and match. Added a nightmode for display and the leds and a boot screen with the current version. But no intelligence for using the leds, still thinking about it to make that state based so it can be used for any alarm or from HA. I will share my code coming days.
I think it would be interesting to have an unofficial esphome build repository so anyone can build on it. What do you think?

Example but far from release ready

  devicename: "ag-device"
  friendly_name: "Airgradient Device"
  comment: "Airgradient air measuring station including Temperature, Humidity, Pressure, Co2, Particles, VOC and NOx"
  area: ""

  ## Put in your wifi details or use the !secret file
  #wifi_ssid: !secret wifi_ssid
  #wifi_password: !secret wifi_password

  ## Use static ip to use fast_connect
  static_ip: ""

  ## Update interval of sensors
  update_interval: "10sec"
  update_interval_pms: "3min" # Default 3 min. Sensor will go into sleep mode for extended operation lifetime

  ## External temperature sensor to show on display. Please fill in sensor id from Home Assistant. You can use a weather service to provide it.
  temperature_outside: "sensor.temperature_outside"

## Any config below can be enabled by removing the #
  ## Airgradient platform
  ## Choose the right version so all connections are configured correctly
  airgradient: !include airgradient/airgradient_one_v9_0.yaml

  ## Airgradient Dashboard (This function requires internet access)
  #agdashboard: !include airgradient/ag_dashboard.yaml

  ## Wifi settings
  wifi: !include airgradient/components/wifi.yaml

  ## ESPHome board etc
  #esphome: !include common/esphome.yaml

  ## Components (Remove # to enable sensors)
  ## Every sensor can be stopped updating on runtime with a switch. For example when you dont want data to record when moving your device.
  #sht3x: !include airgradient/components/sht3x.yaml
  sht4x: !include airgradient/components/sht4x.yaml #default
  sgp4x: !include airgradient/components/sgp4x.yaml #default
  s8: !include airgradient/components/s8.yaml #default
  pmsx003: !include airgradient/components/pmsx003.yaml #default
  bmp388: !include airgradient/components/bmp388.yaml
  #bme280: !inculde airgadient/components/bme280.yaml

  ## Enable and add your own or make changes below configuration block
  ## Default common settings of your environment
  common: !include common/common.yaml

  ## Advanced config

  ## Specific common settings for your board, if applicable
  esp32: !include common/esp32.yaml
  external_button: !include 
    file: airgradient/components/button.yaml
      button_name: "External Button"
      button_gpio: 9
  #ble: !include common/ble-tracker.yaml
  #battery: !include airgradient/components/battery-backup.yaml

  ## Enable when experiencing problems like crashes or performance issues
  debug: !include common/debug.yaml


## Add here your own customizations for your device
## Or use extend/remove to change existing configuration


  id: haapi
  reboot_timeout: 0s #testing without HA

Would you be willing to share your full config?

I was exploring Packages in ESPHome but was having a hard time grasping all of it and am currently working through standalone includes

You can check out the branch named includes in my repo to see the current work, but if a single package yaml would let me add sensors, switches, and intervals in a single file, I would totally switch over to it.

Well that is totally possible and I have most things worked out.

I need to find a way to automagically upload my config to git in a dev branch and I will post it here. I also want to use the same style for all other devices so more testing is needed but it makes building out so much easier if this all works out.

I also use packages heavily in my configurations and will be happy to help review and/or provide suggestions, I’ll keep an eye out for PRs in the repo.

There are other things to consider too: most of the sensors should be using sliding-window-moving-average filters to smooth out their reports, and for the Open Air device the linear corrections posted on the AirGradient blog should be incorporated as well (although someone will need to determine whether the raw or corrected values should be reported to the dashboard).

1 Like

@kpfleming, are your packages shared anywhere currently?

I haven’t reviewed the Arduino code for the last month or two, but when the blog post about linear regression was published, there wasn’t a code change to reflect that actually being implemented at the time, so I’ve been waiting to add it to my ESPHome configs until I saw it actually put into the Arduino code base. I should do a review and see if they put it in since I last looked.

In my latest update from last week I switched the PMS5003 sensor from 2 minute intervals to the default in ESPHome which results in getting values whenever the sensor sends them, which is every second. I don’t want all of this filling up the HA database, so I added back sliding window average over 30 seconds. I hadn’t really considered doing it for other sensors, but interested to hear more thoughts.

I do want to keep similar accuracy and methodology of getting values from the sensors between the tested Arduino code that AirGradient is certifying and what ESPHome returns so they are interchangeable as far as numbers returned go, but want to take advantage of the benefits of ESPHome such as easily disabling/enabling ABC, starting an on-demand calibration of CO2, and ease of reporting to locations other than the AirGradient dashboard.


They weren’t, but after a bit of scrubbing they are now: km6g/esphome - KM6G Software Forge

Fair warning… there is zero documentation, and I make lots of changes on a regular basis, but they should be understandable and useful for learning a few advanced ESPHome features.

I’m also working on another feature for ESPHome that will make package usage even better.

Im looking at that feature but I think that works the same as already is in esphome with !extend or !remove what Im using for changes different from the default config. Is it not?

It’s quite a bit different and more capable, but that’s off-topic here… feel free to ask questions on the PR if you like!

Thank you. I’m knee deep in moving my stuff to packages now and working exactly how I was hoping.

Would it be possible to add Airgradient One as device like AirGradient-DIY |

Or is that only a wiki? Would like to have something native like a component inside the esphome repo. This would enable OTA updates for both the components and configurations.

Are there drawbacks for this approach?

The content on are not ‘components’, they are example configurations.

it’s not possible to have something “in the ESPHome repo” which represents a full device with many components; the ESPHome repo doesn’t host YAML config files, but there are ways to write YAML configs which reference ‘base’ configs hosted in public locations.

It’s quite a bit of work to setup, and I’m sure that @MallocArray would appreciate some assistance after the initial conversion to packages has been completed but a good example of doing this is the esphome-ratgdo repository.

1 Like

I updated my separate branch where I was testing the Includes and now am using Packages. I really like how it is coming together, although I still see some room for improvement in how I have it laid out, but it is working for all AG models (except the original Open Air)
MallocArray/airgradient_esphome at includes (

In this branch I also added the display page that another user created to match the Arduino code’s layout in the AG ONE model and I really like it, other than the fact it isn’t easy to read from across the room.
I also added Config switches to the config so you can enable any of the previous pages my configs had. By default it only shows the new single page, but you can enable or disable any of the pages so they are added to the rotation, including a blank page if you want to effectively disable the display.

Going to be looking at how that could be added to an automation to disable all of the other pages and enable only the Blank page overnight, but that is for the future

1 Like

Looks like a version based off your config was merged in to the official esphome-devices repo. I opened a PR to fix a yaml error: Fix invalid AirGradient-One yaml by clarkminor · Pull Request #615 · esphome/esphome-devices · GitHub

However, it also looks like it was based off an older version of your code. From what I can tell, it removes the upload_airgradient component completely, changes some naming conventions, adds api/ota encryption, and enables the web server by default.

Is it worth trying to unify these two configs going forward?

Thanks for letting me know. I was still working on ironing out a few more things from my ToDo list before I was going to look into what it takes to get a device added to that page. At least it was acknowledged it was based on my repo. (Edit: As you mentioned, I have already added several improvements since the version they grabbed, so will want to update it at some point)

I’ll play around a bit more with the Packages, as I’m trying to decide if the Config button should be part of the Board package, or leave it standalone.
I also want to try out using the same Open Sans that the single page layout is using to limit how many fonts are included
Then there is revisiting the display and font on the AG Basic since it has a different OLED display that needs different layouts.

Once I get those figured out, I’ll update the main branch and then see about adding all of the 4 major models to the ESPHome-devices repo


It’s a good strategy to include just a fairly basic configuration into, but on those pages provide links to locations where more complete configurations (or even more updated configurations) can be found.

Do any of you @kpfleming @MallocArray found a way to only showing the sensors enabled on the display? For example I also have a pressure sensor on one device but not on the other. With the same display lambda I cant use it on both because that ID is not found. A simple if statement doesnt work because the ID is not fond. I did not find a workaround for this. Any tips welcome.

I haven’t found a good way.

What if you still have the sensor for the pressure sensing device defined in the yaml even on the device that doesn’t physically have it? It will log errors since the device isn’t there, but then the config should still compile.

Might show ‘NaN’ for a value, but may be preferable to having to maintain 2 different configs