cap:voltage - read voltage of something

This capability is used to mark sensors that report the voltage of something.

if(thing.matches('cap:voltage')) {
        const voltage = await thing.voltage();
        console.log('Voltage:', voltage.volts);
}

API

voltage

Get the current voltage.

Returns:Promise that resolves to the current voltage.

Example:

const voltage = await thing.voltage();
console.log('Voltage:', voltage.volts);

Events

voltageChanged

The voltage has changed. Payload is the new voltage as a voltage.

Example:

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

Protected methods

updateVoltage(value)

Update the voltage. Should be called whenever a change is detected.

Arguments:
  • value – The new voltage. Will be converted to a voltage with the default unit being volts.

Example:

this.updateVoltage(12);

Implementing capability

Implementors of this capability should call updateRelativeHumidity whenever the relative humidity changes.

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

class Example extends Sensor.with(Voltage) {

        constructor() {
                super();

                this.updateVoltage(230);
        }

}