cap:carbon-monoxide - 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')) {
  console.log('Carbon monoxide:', thing.carbonMonoxide);
}

API

carbonMonoxide()

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

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

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

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

Implementing capability

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

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

class Example extends Sensor.with(CarbonMonoxide) {

  constructor() {
    super();

    this.updateCarbonMonoxide(0);
  }

}