cap:pm2.5 - read PM2.5 density (air quality)

This capability is used to mark sensors that monitor fine particulate matter (PM) of up to 2.5 micrometers (μm).

if(thing.matches('cap:pm2.5')) {
  console.log('PM2.5:', await thing.pm2_5());
}

API

pm2_5()

Get the current PM2.5 as micrograms per cubic meter (μg/m³). Value is a number.

Returns:The current value as micrograms per cubic meter (μg/m³). Value is a number.

Example:

console.log('PM2.5:', await thing.pm2_5());
'pm2.5'()

Get the current PM2.5 as micrograms per cubic meter (μg/m³). Value is a number.

Returns:The current value as micrograms per cubic meter (μg/m³). Value is a number.

Example:

console.log('PM2.5:', await thing['pm2.5']());

Events

pm2.5Changed

The PM2.5 has changed. Payload is a number with the new PM2.5 as micrograms per cubic meter (μg/m³).

Example:

thing.on('pm2.5Changed', v => console.log('Changed to:', v));

Protected methods

updatePM2_5(value)

Update the current PM2.5 as micrograms per cubic meter (μg/m³). Should be called whenever a change is detected.

Arguments:
  • value – The new PM2.5 value. Will be converted to a number.

Example:

this.updatePM2_5(10);

Implementing capability

Implementors of this capability should call updatePM2_5 whenever the detected PM2.5 changes.

const { Sensor, PM2_5 } = require('abstract-things/sensors');

class Example extends Sensor.with(PM2_5) {

  constructor() {
    super();

    this.updatePM2_5(10);
  }

}