cap:carbon-dioxide-level - 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-level')) {
        console.log('Carbon dioxide:', await thing.carbonDioxideLevel());

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

API

carbonDioxideLevel()

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.carbonDioxideLevel());
co2Level()

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.co2Level());

Events

carbonDioxideLevelChanged

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

Example:

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

Protected methods

updateCarbonDioxideLevel(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.updateCarbonDioxideLevel(389);

Implementing capability

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

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

class Example extends Sensor.with(CarbonDioxideLevel) {

        constructor() {
                super();

                this.updateCarbonDioxideLevel(390);
        }

}