I recently acquired a dual PM2.5 sensor Air Station From World Air Quality Index Project, GAIA-A08, and although I can utilize the official integration to load my station data, I wanted to be able to localy fetch data - and the Open Source Firmware includes a real time web server that can be utilized to create sensor data from a JSON.
Here’s a Home Assistant configuration code that extracts and maps the sensor data for PM1, PM2.5, PM10, temperature, and humidity from the JSON structure. You can use this code to define the sensors in your configuration.yaml
or in a separate package configuration.
sensor:
- platform: rest
name: Air Quality Sensor
resource: http://your_sensor_local_ip/realtime
scan_interval: 30
json_attributes_path: "$.pms"
json_attributes:
- pms1
- pms2
- rolling
- met
value_template: "OK"
- platform: template
sensors:
# PMS1 Sensor Data
pms1_pm25:
friendly_name: "PMS1 PM2.5"
value_template: "{{ state_attr('sensor.air_quality_sensor', 'pms1')['pm25']['latest'] }}"
unit_of_measurement: "µg/m³"
pms1_pm1:
friendly_name: "PMS1 PM1"
value_template: "{{ state_attr('sensor.air_quality_sensor', 'pms1')['pm1']['latest'] }}"
unit_of_measurement: "µg/m³"
pms1_pm10:
friendly_name: "PMS1 PM10"
value_template: "{{ state_attr('sensor.air_quality_sensor', 'pms1')['pm10']['latest'] }}"
unit_of_measurement: "µg/m³"
# PMS2 Sensor Data
pms2_pm25:
friendly_name: "PMS2 PM2.5"
value_template: "{{ state_attr('sensor.air_quality_sensor', 'pms2')['pm25']['latest'] }}"
unit_of_measurement: "µg/m³"
pms2_pm1:
friendly_name: "PMS2 PM1"
value_template: "{{ state_attr('sensor.air_quality_sensor', 'pms2')['pm1']['latest'] }}"
unit_of_measurement: "µg/m³"
pms2_pm10:
friendly_name: "PMS2 PM10"
value_template: "{{ state_attr('sensor.air_quality_sensor', 'pms2')['pm10']['latest'] }}"
unit_of_measurement: "µg/m³"
# Rolling Sensor Data
rolling_pm25:
friendly_name: "Rolling PM2.5"
value_template: "{{ state_attr('sensor.air_quality_sensor', 'rolling')['pm25']['latest'] }}"
unit_of_measurement: "µg/m³"
rolling_pm1:
friendly_name: "Rolling PM1"
value_template: "{{ state_attr('sensor.air_quality_sensor', 'rolling')['pm1']['latest'] }}"
unit_of_measurement: "µg/m³"
rolling_pm10:
friendly_name: "Rolling PM10"
value_template: "{{ state_attr('sensor.air_quality_sensor', 'rolling')['pm10']['latest'] }}"
unit_of_measurement: "µg/m³"
# Temperature and Humidity
temperature:
friendly_name: "Temperature"
value_template: "{{ state_attr('sensor.air_quality_sensor', 'met')['temperature'] }}"
unit_of_measurement: "°C"
humidity:
friendly_name: "Humidity"
value_template: "{{ state_attr('sensor.air_quality_sensor', 'met')['humidity'] }}"
unit_of_measurement: "%"