# WAQI integration: Should we standardise on ug/m3 like other air quality sensors?

The WAQI integration reports air quality data by a custom metric - `AQI`. Instead, other sensors report particulate matter using the standard measurements in the air_quality component:

It would make it easier to use within the Home Assistant Lovelace UI:

Thoughts?

I agree this would be nice. In the meantime, I developed a template sensor based on the WAQI integration to pull the PM2.5 value and convert it from AQI to µg/m³ based on this formula: PM2.5 to AQI Conversion / Mike Bostock | Observable, which is hopefully correct. Perhaps this will help someone else!

``````- sensor:
- name: "My Location WAQI PM <2.5µm"
unique_id: waqi_my_location_pm_2_5um
state: >
{% macro lerp(ylo, yhi, xlo, xhi, x) -%}
{{ ((x - xlo) / (xhi - xlo)) * (yhi - ylo) + ylo }}
{%- endmacro %}

{% macro aqi_pm25(aqi) -%}
{% set a = (aqi | round) %}

{% if a < 0 %}
{# values below 0 are considered beyond AQI #}
{% set c = 0 %}
{% elif a <= 50 %}
{% set c = lerp(0.0, 12.0, 0, 50, a) %}
{% elif a <= 100 %}
{% set c = lerp(12.1, 35.4, 51, 100, a) %}
{% elif a <= 150 %}
{% set c = lerp(35.5,  55.4, 101, 150, a) %}
{% elif a <= 200 %}
{% set c = lerp(55.5, 150.4, 151, 200, a) %}
{% elif a <= 300 %}
{% set c = lerp(150.5, 250.4, 201, 300, a) %}
{% elif a <= 400 %}
{% set c = lerp(250.5, 350.4, 301, 400, a) %}
{% elif a <= 500 %}
{% set c = lerp(350.5, 500.4, 401, 500, a) %}
{% else %}
{# values above 500 are considered beyond AQI #}
{% set c = 500 %}
{% endif %}

{{ ((10 * float(c)) / 10) | round(2, 'floor') }}
{%- endmacro %}

{{ aqi_pm25(state_attr('sensor.waqi_my_location', 'pm_2_5') | int) }}
icon: mdi:chemical-weapon
unit_of_measurement: µg/m³
``````

The integration was not working at all on my setup.
So I gave up and created the sensors myself:

``````rest:
- scan_interval: 600
resource: https://api.waqi.info/feed/washington/?token=somerandomlettersandnumbers
sensor:
- name: "WAQI_Aqi"
value_template: "{{ value_json.data.aqi }}"
device_class: aqi

# - name: "WAQI_Dew"
#   device_class: temperature
#   unit_of_measurement: °C
#   value_template: "{{ value_json.data.iaqi.dew.v }}"

- name: "WAQI_humidity"
icon: mdi:water-percent
unit_of_measurement: "%"
device_class: humidity
value_template: "{{ value_json.data.iaqi.h.v }}"

- name: "WAQI_CO"
icon: mdi:molecule-co
unit_of_measurement: "ppm"
device_class: carbon_monoxide
value_template: "{{ value_json.data.iaqi.co.v }}"

- name: "WAQI_NO2"
value_template: "{{ value_json.data.iaqi.no2.v }}"
icon: mdi:molecule
unit_of_measurement: µg/m³
device_class: nitrogen_dioxide

- name: "WAQI_pressure"
icon: mdi:gauge
device_class: atmospheric_pressure
unit_of_measurement: hPa
value_template: "{{ value_json.data.iaqi.p.v }}"

- name: "WAQI_pm10"
unit_of_measurement: µg/m³
device_class: pm10
value_template: "{{ value_json.data.iaqi.pm10.v }}"

- name: "WAQI_pm25"
unit_of_measurement: µg/m³
device_class: pm25
value_template: "{{ value_json.data.iaqi.pm25.v }}"

- name: "WAQI_temperature"
icon: mdi:thermometer
device_class: temperature
unit_of_measurement: °C
value_template: "{{ value_json.data.iaqi.t.v }}"

- name: "WAQI_wind"
icon: mdi:windsock
device_class: wind_speed
unit_of_measurement: km/h
value_template: "{{ value_json.data.iaqi.w.v }}"

- name: "WAQI_O3_Min"
unit_of_measurement: µg/m³
device_class: ozone
value_template: "{{ value_json.data.forecast.daily.o3[0].min }}"
- name: "WAQI_O3_Max"
unit_of_measurement: µg/m³
device_class: ozone
value_template: "{{ value_json.data.forecast.daily.o3[0].max }}"
- name: "WAQI_O3_Avg"
unit_of_measurement: µg/m³
device_class: ozone
value_template: "{{ value_json.data.forecast.daily.o3[0].avg }}"
``````
1 Like