cap:power-load - read the current power load

This capability is used to mark sensors that report power load, that is the power currently being used.

if(thing.matches('cap:power-load')) {
  const powerLoad = await thing.powerLoad();
  console.log('Power load:', powerLoad.watts);
}

API

powerLoad()

Get the current amount of power being used.

Returns:Promise that resolves to the current amount of power used as a power.

Example:

const powerLoad = await thing.powerLoad();
console.log('Power load:', powerLoad.watts);

Events

powerLoadChanged

The amount of power being used has changed. Payload is the power load as power.

Example:

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

Protected methods

updatePowerLoad(value)

Update the power load. Should be called whenever a change is detected.

Arguments:
  • value – The new amount of power being used, as power. The default unit is watts.

Example:

this.updatePowerLoad(5);

Implementing capability

Implementors of this capability should call updatePowerLoad whenever the power load changes.

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

class Example extends Sensor.with(PowerLoad) {

  constructor() {
    super();

    this.updatePowerLoad(10);
  }

}