cap:illuminance - read illuminance

This capability is used to mark sensors that report illuminance. This is commonly used for sensors that read light levels.

if(thing.matches('cap:illuminance')) {
        console.log('Light level:', await thing.illuminance());
}

API

illuminance()

Get the current illuminance.

Returns:Promise that resolves to the current illuminance.

Example:

const lightLevel = await thing.illuminance();
console.log('Light level:', lightLevel.lux);

Events

illuminanceChanged

The illuminance has changed. Payload is the new illuminance.

Example:

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

Protected methods

updateIlluminance(value)

Update the current illuminance level. Should be called whenever a change in is detected.

Arguments:
  • value – The new illuminance. Will be converted to illuminance, the default conversion uses lux.

Example:

this.updateIlluminance(20);

Implementing capability

Implementors of this capability should call updateIlluminance whenever the detected light level changes.

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

class Example extends Sensor.with(Illuminance) {

        constructor() {
                super();

                this.updateIlluminance(10);
        }

}