Local integration of airRohr in Home Assistant

Posted on 20. November 2022

Air pollution is the single largest environmental health risk in Europe and is a major cause of premature death and disease1. The International Agency for Research on Cancer has classified air pollution, in particular PM2.5, as a leading cause of cancer.

I have decided to join the Sensor.Community, a global sensor network that creates Open Environmental Data, by adding my own outdoor sensor to monitor the air pollutant fine particulate matter (PM2.5 and PM10) in my neighborhood.

The API for sending the data directly from the sensor works perfect but the community integration for Home Assistant does not, so I have added the sensor locally with the help of the Scrape Integration which absolutely makes more sense.

1. Install file editor

Since the Scrape Integration is only available by manual configuration, you will need a file editor. Go to the Settings/Add-ons and install the File editor. Then click on OPEN WEB UI.

2. Add folder for sensors

If you read my last post about adding an external API to Home Assistant, you already know that I like a modular approach instead of putting all sensors in a single file in compliance with the Single Responsibility Principle.
In the config folder, create a new folder called sensor and append the following configuration to the configuration.yaml.

# file: configuration.yaml
sensor: !include_dir_merge_list sensor/

Each sensor which have to be configured manually by a file can now be configured by a separate configuration.

3. Add PM2.5 and PM10 sensor

Go to the folder config/sensor and create a new file called airrohr.yaml.

In this file, add the following content which defines the configuration for the Scrape integration.

Do not forget to replace http://airrohr-XXXXXX with the local hostname of your airRohr.

# replace http://airrohr-XXXXXX with the local hostname of your airRohr
- platform: scrape
  resource: http://airrohr-XXXXXX.local/values
  name: "PM 2.5 Outdoor"
  select: ".r"
  index: 0
  value_template: '{{ value | regex_findall_index("([0-9]+.[0-9]*)", 0) | float }}'
  device_class: pm25
  state_class: measurement
  unit_of_measurement: "µg/m³"
  scan_interval: 60

- platform: scrape
  resource: http://airrohr-XXXXXX.local/values
  name: "PM 10 Outdoor"
  select: ".r"
  index: 1
  value_template: '{{ value | regex_findall_index("([0-9]+.[0-9]*)", 0) | float }}'
  device_class: pm10
  state_class: measurement
  unit_of_measurement: "µg/m³"
  scan_interval: 60

Afterwards, go to the Developer Tools where you can check the configuration before you initiate a restart. Both entities will now be available by its name configured in the yaml configuration.

home-assistant-particular-matter-history-screenshot

  1. European Environment Agency. (2022, November 20). Air pollution: how it affects our health. https://www.eea.europa.eu/themes/air/health-impacts-of-air-pollution
Made with ♥️ and Gatsby © 2024