API Upload TVOX, NOx and PM reduction DIY Pro data with ESPHome

Hello,

I just received my DIY Pro (pre-soldered) with the SGP41 TVOC module and everything is working fine.

I wanted to use it with Home Assistant / ESPHome and used this configuration file:

To add the TVOX and NOx data, I added the code from this site:

No problem on the Home Assistant side, I can see all the data.
But on Airgradient site, I can see that some data are missing:

  • TVOC (Ind40)
  • NOx (Ind41)
  • PM Reduction

For TVOC, however the TVOC (Ind30) data is correctly populated.
What should I do to upload the missing data to Airgradient site ?

Here is what I currently have in my ESPHome config file:

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

  - interval: 5min
    # Send data to AirGradient API server
    # for more details have a look at sendToServer() function:
    # https://www.airgradient.com/open-airgradient/blog/airgradient-diy-pro-instructions/
    then:
      - http_request.post:
          # AirGradient URL with the last 3 bytes of the MAC address in Hex format all lower case
          url: !lambda |-
            return "http://hw.airgradient.com/sensors/airgradient:" + get_mac_address().substr(6,11) + "/measures";
          headers:
              Content-Type: application/json
          # "!lambda return to_string(id(pm2).state);" Converts sensor output from double to string
          json:
            wifi: id(airgradient_wifi_signal).state
            pm01: !lambda return to_string(id(pm_1_0).state);
            pm02: !lambda return to_string(id(pm_2_5).state);
            pm10: !lambda return to_string(id(pm_10_0).state);
            pm003_count: !lambda return to_string(id(pm_0_3um).state);
            rco2: !lambda return to_string(id(co2).state);
            atmp: !lambda return to_string(id(temp).state);
            rhum: !lambda return to_string(id(humidity).state);
            tvoc: !lambda return to_string(id(tvoc).state);
            nox: !lambda return to_string(id(nox).state);
          verify_ssl: false

I’ve seen in other yaml config files that the JSON fields are tvoc_index and nox_index so perhaps try that change?

tvoc_index:: !lambda return to_string(id(tvoc).state);
nox_index: !lambda return to_string(id(nox).state);

Untested on my side though as I’m not having any luck getting any of my data up to the Airgradient site after reconfiguring with ESPHome (Home Assistant is fine).

Edit: Realised I was missing a DNS entry for my static IP. After fixing that the values for TVOC and NOX have populated on the AirGradient Dashboard with JSON as suggested above.

Thanks @Andrew_Taylor , it works for “nox_index” which populates NOx (Ind41).
But it doesn’t work for “tvoc_index”.
However your “tvoc_index” was using the value tvoc behind, which was already captured by my “tvoc” which populates TVOC (Ind30):

tvoc: !lambda return to_string(id(tvoc).state);

So I didn’t really understand why I should send it again under the name “tvox_index”.

So @Achim_AirGradient , do you have perhaps an idea how I can upload values to TVOC (Ind40) and PM Reduction ?

Thanks !

tvoc_index should work. What error code do you get back?

Hello,
I don’t have any error, it is just that TVOC (Ind40) and PM Reduction are still empty on app.airgradient.com.
But what is the point of tvoc_index if we give it the same value as tvoc ?

tvoc: !lambda return to_string(id(tvoc).state);
tvoc_index:: !lambda return to_string(id(tvoc).state);

tvoc is for the SGP30 sensor that we used before. The SGP30 sends values as ppb.

tvoc_index is for the SGP41 sensor that sends values as an index.

Reduction is a calculated value between the outside pm and the location. It is not something you can post on the api.

Ok I have removed the tvoc line and only kept the tvox_index.
However I still only have TVOC (Ind30) which is diplaying values, what about TVOC (Ind41) ?
I am not even sure about the differences between the 2…
Thanks !

There is a formula for calculating the TVOC_index into the old TVOC value which we use so that customers who purchased our monitor with the old TVOC sensor can make comparisons.

So TVOC (Ind40) is of no use for new customers and I can ignore it ?
Edit: after correcting some error in my YAML file it seems to work now, TVOC (Ind30) and TVOC (Ind40) are correctly filled. Thanks !

Is there an API reference document anywhere?