[ANNOUNCE] weewx-aqi: A Plugin for Air Quality Index Calculations

589 views
Skip to first unread message

jonathan koren

unread,
May 17, 2018, 2:48:16 AM5/17/18
to weewx-user

I'd like to announce a new plugin for WeeWx, weewx-aqi. weewx-aqi calculates various air quality indices using data from a linked air quality sensor, such as weewx-purpleair. An air quality index, is a government defined scaled that is meant to succinctly describe how safe the air is. weewx-aqi can currently calculate the following AQIs:


* Canada's Air Quality Health Index
* India's National Air Quality Index
* Mexico's Índice Metropolitano de la Calidad del Aire
* United Kingdom's Daily Air Quality Index
* United States's Air Quality Index
* United States's NowCast Air Quality Index


I personally use this plugin with my Purple Air sensor to calculate a PM 2.5 NowCast AQI. I hope others find this interesting and/or useful. I especially would like to hear from anyone that has an air quality sensor integrated into WeeWx that is not a Purple Air, as the plugin is written to be as sensor agnostic as possible. Finally, requests for additional AQIs are welcome. (Coming soon, the European Air Quality Index.)

Thanks.

--
jonathankoren

Hartmut Schweidler

unread,
May 30, 2019, 4:20:15 AM5/30/19
to weewx-user
Hallo,

I'm looking for an example in aqi.html.tmpl

like "AQIs have categorical labels associated with the AQI values. The index of the current category is available via $latest('aqi_binding').aqi_pm2_5_category. From this, the label and color category can be found via (hex_color, category_label) = service.aqi_standard.interpret_aqi_index(index)"

ich suche nach einem Beispiel für die Verwendung der Farben in einer AQI-Seite

Hartmut

jonathan koren

unread,
May 31, 2019, 4:00:36 AM5/31/19
to weewx-user

Honestly, that’s pretty hard to get that to work if I remember correctly. It’s not very cheetah template friendly. I haven’t looked at this in a while, but let me take a look at it this weekend.

jonathan koren

unread,
Jun 3, 2019, 2:06:46 AM6/3/19
to weewx-user

I had to push version but the solution is pretty easy. You can download the new version from https://github.com/jonathankoren/weewx-aqi/archive/v1.1.0.tar.gz

You can either reinstall the whole thing, but the two files that got modified were service.py and calculators.py, so you can just drop those in if you want. Nothing else changed beyond the README.md .

Inside your skin.conf you'll need to add a new SearchList:

[CheetahGenerator]
    search_list_extensions = user.aqi.service.AqiSearchList

Then, inside your index.html.tmpl. you can use the new $aqi template to get the color and description out.


The AQI value (e.g. "9"):
$current($data_binding='aqi_binding').aqi_pm2_5

The AQI category:
$aqi($current($data_binding='aqi_binding').aqi_pm2_5_category).category

The AQI category's color in hex:
$aqi($current($data_binding='aqi_binding').aqi_pm2_5_category).color;


Putting everything together, you can do something like:

<div style="text-align: center; background-color: #$aqi($current($data_binding='aqi_binding').aqi_pm2_5_category).color;" >
    $current($data_binding='aqi_binding').aqi_pm2_5 <br/>
    $aqi($current($data_binding='aqi_binding').aqi_pm2_5_category).category
</div>

Sorry this took a code change, but your email did give the motivation I needed to fix this.

I guess, I should wrap up the EU AQI calculator, even if I'm having trouble getting it to download CAMS data to fill in missing values.

jonathan koren

unread,
Jun 3, 2019, 3:07:12 AM6/3/19
to weewx-user

Hartmut Schweidler

unread,
Jun 3, 2019, 1:12:19 PM6/3/19
to weewx-user

thank you for the information.

I will test it on the weekend

Thank you
Hartmut

Hartmut Schweidler

unread,
Jun 9, 2019, 2:11:50 PM6/9/19
to weewx-user
Hallo Jonathan,

the test for the weekend
Der Wocheendtest, aber nur Fehler   bei aqi....Color und aqi....category

in my "indexAir.htmk.tmpl" the code

<div style="text-align: center; background-color: #$aqi($current($data_binding='aqi_binding').aqi_pm2_5_
category).color;" >
    $current($data_binding='aqi_binding').aqi_pm2_5 <br/>  ---> "Result is right 3,0 µg/m³"
    $aqi($current($data_binding='aqi_binding').aqi_pm2_5_category).category
</div>

<div style="text-align: center; background-color: #$aqi($current($data_binding='aqi_binding').aqi_pm10_0_category).color;" > $current($data_binding='aqi_binding').aqi_pm10_0 <br/> ----> "Result is right 21,0 µg/m³" $aqi($current($data_binding='aqi_binding').aqi_pm10_0_category).category </div>

it does not work right

The Errors

Jun 9 19:50:29 wetter weewx-cmon[7576]: copygenerator: copied 0 files to /home/weewx/public_html
Jun 9 19:50:33 wetter OWFS[14428]: cheetahgenerator: Generate failed with exception '<class 'NameMapper.NotFound'>'
Jun 9 19:50:33 wetter OWFS[14428]: cheetahgenerator: **** Ignoring template /home/weewx/skins/Standard/indexAir.html.tmpl
Jun 9 19:50:33 wetter OWFS[14428]: cheetahgenerator: **** Reason: cannot find 'color' while searching for 'color'
Jun 9 19:50:33 wetter OWFS[14428]: **** Traceback (most recent call last):
Jun 9 19:50:33 wetter OWFS[14428]: **** File "/home/weewx/bin/weewx/cheetahgenerator.py", line 331, in generate
Jun 9 19:50:33 wetter OWFS[14428]: **** unicode_string = compiled_template.respond()
Jun 9 19:50:33 wetter OWFS[14428]: **** File "cheetah__home_weewx_skins_Standard_indexAir_html_tmpl_1560102633_0441406_65394.py", line 1105, in respond
Jun 9 19:50:33 wetter OWFS[14428]: **** NameMapper.NotFound: cannot find 'color' while searching for 'color'
Jun 9 19:50:33 wetter OWFS[14428]: cheetahgenerator: Generated 9 files for report StandardReport in 7.64 seconds

or / and

Jun 9 19:55:33 wetter OWFS[14428]: cheetahgenerator: Generate failed with exception '<class 'NameMapper.NotFound'>'
Jun 9 19:55:33 wetter OWFS[14428]: cheetahgenerator: **** Ignoring template /home/weewx/skins/Standard/indexAir.html.tmpl
Jun 9 19:55:33 wetter OWFS[14428]: cheetahgenerator: **** Reason: cannot find 'category' while searching for 'category'
Jun 9 19:55:33 wetter OWFS[14428]: **** Traceback (most recent call last):
Jun 9 19:55:33 wetter OWFS[14428]: **** File "/home/weewx/bin/weewx/cheetahgenerator.py", line 331, in generate
Jun 9 19:55:33 wetter OWFS[14428]: **** unicode_string = compiled_template.respond()
Jun 9 19:55:33 wetter OWFS[14428]: **** File "cheetah__home_weewx_skins_Standard_indexAir_html_tmpl_1560102933_0067816_68569.py", line 1106, in respond
Jun 9 19:55:33 wetter OWFS[14428]: **** NameMapper.NotFound: cannot find 'category' while searching for 'category'
Jun 9 19:55:33 wetter OWFS[14428]: cheetahgenerator: Generated 9 files for report StandardReport in 7.19 seconds

i have in default weewx.conf :

[AqiService]
    [[air_sensor]]
        pm2_5 = pm_25
        temp = tempAir
        data_binding = air_binding
        dateTime = dateTime
        pressure = presAir
        pm10_0 = pm_10
        usUnits = usUnits
    [[standard]]
        data_binding = aqi_binding
        standard = user.aqi.us.NowCast

and  in skins

[CheetahGenerator]
    search_list_extensions = user.aqi.service.AqiSearchList

Result no color no category
 
Thank you
Hartmut

jonathan koren

unread,
Jun 10, 2019, 2:14:59 AM6/10/19
to weewx-user
Must have been a missed check in .

in standards.py, replace interpret_aqi_index() with

    def interpret_aqi_index(self, aqi_index):
        '''Returns the color and category name associated with the pollutant
        with the aqi_index (not aqi value).'''
        return {
            'color': self.colors[aqi_index],
            'category': self.categories[aqi_index]

Or just download the new version (v1.1.2)

Muireadach O Connor

unread,
Dec 22, 2019, 10:19:47 AM12/22/19
to weewx-user
Thanks very much for taking the time to write this.
Does the current version support the Luftdaten.info type sensors out of the box so to speak?, I had a read of the instructions on Github for using with other sensors and I'm not really sure i'd know where to start though I'd certainly give it a go once I see what the generated data looks like. 

Many thanks,

Muireadach.

jonathan koren

unread,
Dec 27, 2019, 11:32:16 PM12/27/19
to weewx-user
weewx-aqi actually doesn’t talk to sensors, it reads from databases that whatever sensor plugins walked to. So in that sense it should work with whatever. The configuration lets you define which column from which database corresponds to what reading. I’ve used this with Purple Air and helped someone with a bespoke sensor setup.  If you need help, let me know.

--
jonathan
Reply all
Reply to author
Forward
0 new messages