London Air Quality


The london_air component queries the London air quality data feed provided by Kings College London. A single sensor will be added for each location (local authority district or borough) specified in the configuration file. The state of each sensor is the overall air quality in that borough. Note that only 28 of the 32 boroughs have data available.

Boroughs can have multiple monitoring sites at different geographical positions within the borough, and each of those sites can monitor up to six different kinds of pollutant. The pollutants are described here and are Carbon Monoxide (CO2), Nitrogen Dioxide (NO2), Ozone (O3), Sulphur Dioxide (SO2), PM2.5 & PM10 particulates. The latitude and longitude of each site is accessible through a data attribute of the sensor, as are details about the pollutants monitored at that site. The sites attribute of a sensor displays how many monitoring sites that sensor covers. The updated attribute of a sensor states when the data was last published. Nominally data is published hourly, but in my experience this can vary. To limit the number of requests made by the sensor, a single API request is made every 30 minutes.

To add sensors to Home-assistant for all possible areas/boroughs add the following to your configuration.yaml file:

# Example configuration.yaml entry for a single sensor
sensor:
  - platform: london_air
    locations:
      - Barking and Dagenham
      - Bexley
      - Brent
      - Camden
      - City of London
      - Croydon
      - Ealing
      - Enfield
      - Greenwich
      - Hackney
      - Haringey
      - Harrow
      - Havering
      - Hillingdon
      - Islington
      - Kensington and Chelsea
      - Kingston
      - Lambeth
      - Lewisham
      - Merton
      - Redbridge
      - Richmond
      - Southwark
      - Sutton
      - Tower Hamlets
      - Wandsworth
      - Westminster

Configuration variables:

  • locations array (Required): At least one entry required.

To explore the data available within the data attribute of a sensor use the dev-template tool on the Home-assistant frontend. data contains a list of monitored sites, where the number of monitored sites are given by the sites attribute. If a sensor has four sites, access the fourth site by indexing the list of sites using data[3]. Each site is a dictionary with multiple fields, with entries for the latitude and longitude of that site, a pollution_status, site_code, site_name and site_type. The field number_of_pollutants states how many pollutants are monitored (of the possible six) and the field pollutants returns a list with data for each pollutant. To access the first pollutant in the list for site zero use attributes.data[0].pollutants[0]. Each entry in pollutants is a dictionary with fields for the pollutant code, description, index, quality and a summary. Template sensors can then be added to display these attributes, for example:

# Example template sensors
- platform: template
  sensors:
    updated:
      friendly_name: 'Updated'
      value_template: '{{states.sensor.merton.attributes.updated}}'
    merton_pm10:
      friendly_name: 'Merton PM10'
      value_template: '{{states.sensor.merton.attributes.data[0].pollutants[0].summary}}'
    westminster_s02:
      friendly_name: 'Westminster S02'
      value_template: '{{states.sensor.westminster.attributes.data[0].pollutants[3].summary}}'