cap:carbon-monoxide-leve - read carbon monoxide level

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

if(thing.matches('cap:carbon-monoxide-level')) {
        console.log('Carbon monoxide:', await thing.carbonMonoxideLevel());

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

API

carbonMonoxideLevel()

Get the current carbon monoxide levels as PPM.

Returns:Promise that resolves to the current value as a number.
console.log('CO is:', await thing.carbonMonoxideLevel());
coLevel()

Get the current carbon monoxide levels as PPM.

Returns:Promise that resolves to the current value as a number.
console.log('CO is:', await thing.coLvel());

Events

carbonMonoxideChanged

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

Example:

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

Protected methods

updateCarbonMonoxideLevel(value)

Update the current carbon monoxide 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.updateCarbonMonoxideLevel(0);

Implementing capability

Implementors of this capability should call updateCarbonMonoxideLevel whenever the PPM of carbon monoxide changes.

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

class Example extends Sensor.with(CarbonMonoxideLevel) {

        constructor() {
                super();

                this.updateCarbonMonoxideLevel(0);
        }

}