cap:relative-humidity
- read humidity of air¶
This capability is used to mark sensors that report the relative humidity of the air.
if(thing.matches('cap:relative-humidity')) {
console.log('RH:', await thing.relativeHumidity());
}
API¶
-
relativeHumidity
()¶ Get the current relative humidity as a percentage.
Returns: Promise that resolves to the current relative humidity as a percentage. Example:
console.log('RH:', await thing.relativeHumidity());
Events¶
-
relativeHumidityChanged
¶ The relative humidity has changed. Payload is the new humidity as a percentage.
Example:
thing.on('relativeHumidityChanged', v => console.log('Changed to:', v));
Protected methods¶
-
updateRelativeHumidity
(value)¶ Update the relative humidity. Should be called whenever a change is detected.
Arguments: - value – The new relative humidity. Will be converted to a percentage.
Example:
this.updateRelativeHumidity(32);
Implementing capability¶
Implementors of this capability should call updateRelativeHumidity
whenever
the relative humidity changes.
const { Sensor, RelativeHumidity } = require('abstract-things/sensors');
class Example extends Sensor.with(RelativeHumidity) {
constructor() {
super();
this.updateRelativeHumidity(56);
}
}