cap:carbon-dioxide - read carbon dioxide level

This capability is used to mark sensors that report their carbon dioxide level as PPM (parts per million). The value is reported as a number.

if(thing.matches('cap:carbon-dioxide')) {
  console.log('Carbon dioxide:', await thing.carbonDioxide());
}

API

carbonDioxide()

Get the current carbon dioxide levels as PPM.

Returns:Promise that resolves to the current value as a number.

Example:

console.log('CO2 is:', await thing.carbonDioxide());
co2()

Get the current carbon dioxide levels as PPM. Reported as a number.

Returns:Promise that resolves to the current value as a number.

Example:

console.log('CO2 is:', await thing.co2());

Events

carbonDioxideChanged

The carbon dioxide level has changed. Payload is the new PPM as a number.

Example:

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

Protected methods

updateCarbonDioxide(value)

Update the current carbon dioxide level. Should be called whenever a change in PPM is detected.

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

Example:

this.updateCarbonDioxide(389);

Implementing capability

Implementors of this capability should call updateCarbonDioxide whenever the PPM of carbon dioxide changes.

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

class Example extends Sensor.with(CarbonDioxide) {

  constructor() {
    super();

    this.updateCarbonDioxide(390);
  }

}