Air Visual main pollutant (V 0.95.4)

With this configuration,

############# Air Visual Index USA ##############################
  - platform: airvisual
    api_key: secret
      - us
    show_on_map: false
    scan_interval: 210
    latitude: 4x.xxxxx
    longitude: -y.yyyy

up to version 0.95, it obtained three different data: index, level and main pollutant.
Since the update, the main pollutant data has disappeared.
This is the error message that appears

Sat Jun 29 2019 16:02:23 GMT+0200 (hora de verano de Europa central)
airvisual: Error on device update!
Traceback (most recent call last):
File “/usr/src/homeassistant/homeassistant/helpers/”, line 261, in _async_add_entity
await entity.async_device_update(warning=False)
File “/usr/src/homeassistant/homeassistant/helpers/”, line 375, in async_device_update
await self.async_update()
File “/usr/src/homeassistant/homeassistant/components/airvisual/”, line 244, in async_update
symbol = data[‘main{0}’.format(self._locale)]
KeyError: ‘mainus’

I’d like that information back. Any ideas?

Same here …

I had a look into it and found, that airvisual has removed data from the public api. Among other things “mainus” has been removed from the “pollution” element, which causes the error you have found.

Have a look here: Just the AQI-values are available in the public api.

For now we have to wait for someone to fix it in the code, either by removing the sub-sensor or by make it configurable (which is the better choice).

Thanks for the information.
This change in airvisual policies steals good information from us.
We will have to wait for the developers to change the configuration.

The developers can fix the error but cannot bring back the sensor (as the data are not available any more)
You have to remove the sensor from the UI.

Went ahead and opened a ticket w/ the author on this

In addition to updating the Air Visual integration, World Air Quality Index could be improved.
Its installation only adds one sensor, the Air Quality Index. However, you get a lot of other data, including the main pollutant.
It would be very interesting to have the option to add all those sensors in the configuration.

Appears this might have been a mistaken on their end, I opened a ticket and they said it has been corrected

Has anyone created a template sensor with the state of the sensor.us_main_pollutant as an attribute. Templating could be used to pick what sensor to use for the state the new sensor has based on the value of sensor sensor.us_main_pollutant…

Ok, did a quick hack with a template sensor:

  - platform: template
        unit_of_measurement: 'µg/m3'
        value_template: "{{ states('sensor.pm_2_5um') | round(1) }}"
          pollutant_symbol: p2
          pollutant_unit: µg/m3
          lati: -10.5647
          long: 135.98975

The sensor.pm_2_5um needs to already be in your config either via one of your own sensor or any other data provider. I use my own sensor, which is great for local pollution (plastic burning where i live). You then use the sensor.main_pollutant in the lovelace card.
Here is what it looks like in the frontend:

I may template to pick which sensor value should be used when I find time. At the same time, looking around the world in Air Visual, the main pollutant always seems to be PM2.5… Interested to know what others think on this?