>>> Join Us in the Fight Against Air Pollution

AirGradient Forum

New Firmware Versions for Beta Testing Available

I did something similar to get the logs I posted.

here’s he whole sequence when it boots:

Webserver init: airgradient_[[REDACTED]].local
mqtt init ‘[[REDACTED]]’
Other event id:7
MQTT client init success
Post payload: {“wifi”:-52,“boot”:0}
E (10777) esp-tls: [sock=49] delayed connect error: Connection reset by peer
E (10778) esp-tls: Failed to open new connection
E (10778) TRANSPORT_BASE: Failed to open a new connection
E (10838) MQTT_CLIENT: Error transport connect
MQTT_EVENT_ERROR
reported from esp-tls: 32772reported from tls stack: 0captured as transport’s socket errno: 104MQTT_EVENT_D
ISCONNECTED
Get server config: {“country”:“US”,“pmStandard”:“ugm3”,“co2CalibrationRequested”:false,"ledBarTestRequested
":false,“ledBarMode”:“off”,“displayMode”:“on”,“placeOpen”:false,“abcDays”:8,“model”:“I-9PSL”,“mqttBrokerUrl
“:”[[REDACTED]]”}

I reflashed the previous version of firmware, and the LED screen came back on,

I then reflashed the .5 firmware and it worked again! so perhaps some strangeness onmy side? I did reflash .5 multiple times, even erasing previously, and it didn’t work before. Who knows?

EDIT: The mqtt failing is fine, I took down my MQTT when i learned this had a local webserver for scraping. Setting up telegraf was much easier.

Yes this is known. Not all readings fail and this is why you still have temperature and humidity readings. We are looking into it.

1 Like

Suggestion: on the display, capitalize “tvoc:” as it is the only sensor heading that i not all caps

Also, is TVOC accurate, as it isn’t a total of anything but an Index, so maybe it should just be “VOC:”?

I wrote a script to push the configuration through mqtt. Not sure if this is a good way to go about it.

I think the generated config should be usable in configuration.yml from my reading of the mqtt integration docs. I added a sample of the generated config in a comment on the gist.

2 Likes

I think the “total” stands more for that it includes ALL volatile compounds (there are more than 10.000 different VOCs)

Thank you very much for sharing your setup.

On second thought, I’ve decided to take a different path and to make use of the ‘local polling’ feature introduced in version 3.0.4 beta. Inspired by this post from @Themis3000 , I used the REST integration in HASS which is built-in, so there’s no need to install any additional integrations.

# Requires AirGradient One firmware version 3.0.4 beta or newer
rest:
  - scan_interval: 30
    resource: http://192.168.30.107/measures/current
    sensor:
      - value_template: "{{ value_json.atmp }}"
        name: "Temperature AirGradient"
        unique_id: "tempAG"
        unit_of_measurement: "°C"
        device_class: "temperature"

      - value_template: "{{ value_json.rhum }}"
        name: "Humidity AirGradient"
        unique_id: "rhumAG"
        unit_of_measurement: "%"
        device_class: "humidity"

      - value_template: "{{ value_json.nox_index }}"
        name: "NOX AirGradient"
        unique_id: "noxAG"
        unit_of_measurement: "index level"

      - value_template: "{{ value_json.pm01 }}"
        name: "PM01 AirGradient"
        unique_id: "pm01AG"
        unit_of_measurement: "µg/m³"
        device_class: "pm1"

      - value_template: "{{ value_json.pm02 }}"
        name: "PM02 AirGradient"
        unique_id: "pm02AG"
        unit_of_measurement: "µg/m³"
        device_class: "pm25"

      - value_template: "{{ value_json.pm10 }}"
        name: "PM10 AirGradient"
        unique_id: "pm10AG"
        unit_of_measurement: "µg/m³"
        device_class: "pm10"

      - value_template: "{{ value_json.pm003_count }}"
        name: "PM003 AirGradient"
        unique_id: "pm003AG"
        unit_of_measurement: "/dL"

      - value_template: "{{ value_json.rco2 }}"
        name: "CO2 AirGradient"
        unique_id: "rco2AG"
        unit_of_measurement: "ppm"
        device_class: "carbon_dioxide"

      - value_template: "{{ value_json.tvoc_index }}"
        name: "TVOC AirGradient"
        unique_id: "tvocAG"
        unit_of_measurement: "index level"
        device_class: "volatile_organic_compounds"

I’ve modified the code of @Themis3000 to reflect the correct JSON values as of version 3.0.4. beta. All you need to do is update the IP address above to yours and copy/paste it into your HASS configuration.yaml. Afterwards, reload or restart HASS and the sensors should show up automagically:

That’s all there is to it

1 Like

We may have covered this already, but any reason to not try the ESPHome integration for the hardware? Then you don’t need any polling or special json config in HomeAssistant, it just adds the devices through the ESPHome integration and away it goes

The latest firmware also supports mDNS. So you dont need to know the local IP address and can also poll with this URL

http://airgradient_ecda3b1eaaaf.local/measures/current

“ecda3b1eaaaf” being the serial number of your monitor

1 Like

I know that people have used ESPHome in the past on this hardware. Frankly the reason why I went with a json/polling setup is because I didn’t understand what ESPHome was or how to properly set it up at the time. I still don’t really know the process for using ESPHome. I liked the idea of doing a json polling setup more then ESPHome because it allowed me to have more control over the firmware and work off of what the offical firmware did instead of totally scrapping it for ESPHome.

As far as I’m aware, the big disadvantage of using ESPHome is that you wouldn’t have the option to have your readings wouldn’t be reported to AirGradient’s offical service. Also, having everything on a json endpoint just makes things easy in the eyes of a programmer looking to make niche little scripts.

From what I’ve heard, MQTT sounds like a great improvement to the json/poll idea I implemented. As I understand, it could be a pretty easy modification to the existing firmware and it would allow for easy device adding in home assistant. In my opinion, things would be golden if the offical firmware shipped with both a json endpoint and MQTT out of the box. That would ensure pretty wide compatibility/developer flexibility it seems.

I’m pretty new to smart home stuff, so I’m fairly ignorant about the existing technologies/protocols that are used to facilitate device communication. Take my opinions and statements about it with a grain of salt.

1 Like

In the ESPHome configs that I maintain, it sends to both HomeAssistant and AirGradient’s Dashboard, you can disable the Dashboard part if desired.

As long as you are happy with what you have, go for it. To me, the ease of reading the YAML configs for ESPHome (along with that fact that I’m using ESPHome for multiple other devices already) and the huge community that is supporting it, it was well worth the investment of setting it up.

Cheers!

1 Like

Maybe just to add. Our latest beta firmware has already implemented MQTT as well as the local polling.

1 Like

As I’ve had the device for less than one day, I prefer to stay on the official firmware for now and get accommodated with how it works, before dipping my toes into the community based firmware. Once I feel more comfortable, I’ll probably switch over to the ESPHome based one. I’m particularly interested in enhancing the functionality of the LED bar, as it’s currently not utilized to it’s full potential imho.

Thank you. The REST code I posted above is already updated to make use of the recently introduced local polling feature.

That’s wonderful! I’ll have to crack my ag out of it’s case and give the new firmware a test run! Thank you for maintaining this wonderful project and continuing support of it.

So here’s what I’m using: mqtts://username:password@my HA IP:1883/dir

In the logs it’s connecting but disconnecting: 2024-03-01 20:49:30: New connection from 192.168.1.69:63618 on port 1883.
2024-03-01 20:49:30: Client closed its connection.
2024-03-01 20:49:45: New connection from 192.168.1.69:63620 on port 1883.
2024-03-01 20:49:46: Client closed its connection.

I’m trying to listen under topic :airgradient/readings/ but nothing is coming through. It appears that HA is closing the connection for some reason. Any ideas?

It could be that mqtts is not supported. Can you try with “mqtt”.

We just released version 3.0.6. It addressed the SHT issue. Updates through the browser can be made here and github repository is here.

The new version in the Arduino library should also be available in the next 24 hours.

2 Likes

Added support for OpenMetrics

Just to call this out (because that may not be clear to everyone), this does mean that, with the new firmware, the device is now queryable from Prometheus (or any other OpenMetrics-compatible ingestor) out-of-the-box - just add the AirGradient’s address in your Prometheus scrape config and you’re good to go. You don’t need to do stuff like this anymore.

(This only applies to AirGradient ONE though. It would be easy to add the same functionality to the other devices, but I only wrote the code for the ONE because that’s the device I have.)

1 Like

This did the trick. Now I have to figure out how to use the data in HA

Please share your findings afterwards :slight_smile: