Air Gradient integration with Maker API

Air Gradient Direct Integration with HE

This integration will allow you to run a virtual driver in HE that can be upgraded by the Air Gradient DIY Air quality Sensor.

What will you need to complete this:

  1. A computer with a usb cable and the Adruino IDE to flash updates to the Air Gradient Kit
  2. The Air Gradient virtual Driver driver from the provided link
  3. A instance of Maker API that can share the device.

To start with install the virtual driver, Create a virtual device with that driver, and then share it through your instance of Maker API.

Collect your Maker API instance API Token from the Maker API configuration page. Retrieve your Device ID number by browsing into the device and documenting it's number that is displayed in your browsers address bar. Also copy the "Send Device Command" Url provided in the lower part of the screen

For my purposes I am using the Air Gradient DIY Pro Kit Presoldered version. This integration may need to be slightly modified depending on weather you get the basic kit or the Pro kit. You may also need to tweak this if you add sensors to your setup.

The brains of the Air Quality Monitor is a Wemos D1 Min. This device can be tweaked from the Adriuno IDE. At this point you should reference the appropriate documentation from Air Gradient to download and install the Adruino IDE and be prepared to flash your DIY Kit. The directions from Air Gradient can be found here. You will want to go through the setup of the IDE and get prepped to flash your Wemos d1 Mini through the USB port. When you are prepared you will want to make the following adjustments to you adruino sketch.

Near the top of the sketch provided by Air Gradient there is a configuration section. Update the endpoint configuration to point to your Maker API instance that your sensor will work from. The easiest way to do this would be to past in the URL you copied out earlier for the "Send Device Command", then delete everything following /device/. The last slash needs to be there. Now add right below that the vlaues for the API Token and the Device id.

It should look something like this:
image

Now scroll down towards the bottom until you find the section for "sendToServer"

void sendToServer() {
   if (currentMillis - previoussendToServer >= sendToServerInterval) {
     previoussendToServer += sendToServerInterval;
      String values = String(Co2)
      + "," + String(pm25)
      + "," + String(TVOC)
      + "," + String(temp)
      + "," + String(hum);

      if(WiFi.status()== WL_CONNECTED){
//        Serial.println(payload);
        String POSTURL = APIROOT + DEVID + "/update/" + values + "?access_token=" + APITOKEN;
        Serial.println(POSTURL);
        WiFiClient client;
        HTTPClient http;
        http.begin(client,POSTURL);
//        http.addHeader("content-type", "application/json");
        int httpCode = http.GET();
        String response = http.getString();
        Serial.println(httpCode);
        Serial.println(response);
        http.end();
      }
      else {
        Serial.println("WiFi Disconnected");
      }
   }
} 

Once this is done save the sketch and then upload it to the device.

Once it comes back up you will want to go through the setup on the Air Gradient and associate the sensor to the same network your Hub is on. If you have more then one Sensor all you need to do is adjust the device id the next time you flash

2 Likes

I have updated the Sketch to only publish updates to Hubitat once a minute. the default setting in the sketch is every 10 seconds and this can be a bit much. Both are still published on Github.

The whole sketch has also been updated to use the latest code from Air Gradient as there have been many stability improvements in the sketch.

@mavrrick58 Thank you for posting and sharing that, it has helped me a lot.

I've used a simplified version of your driver and elements from the Air Gradient sketch to pull data from an ESP32 wired directly to a Plantower PMS7003.
It's a low-tech variant that now captures PM1.0, PM2.5 and PM10 readings and sends them to the hub every 30-seconds.

1 Like

Any plans to update the driver to the newest V9 AirGradient ONE?

It is still a work in progress, and needs to have CO2 calibration and LED indicator controls implemented.

My suggestion would be to simply take the DIY Driver and to add in what you need. The driver is rather generic on the Hubitat side.

I don't have the new unit to create a driver and validate the device talk properly.