cap:motion
- motion sensing¶
This capability is used to mark sensors that monitor movement.
if(thing.matches('cap:motion')) {
console.log('Detected motion:', await thing.motion());
thing.on('movement', () => console.log('Motion detected'));
thing.on('inactivity', () => console.log('Inactivity detected'));
}
API¶
Events¶
-
motionChanged
¶ The current motion status has changed.
thing.on('motionChanged', value => console.log('Motion changed to:', value));
-
movement
¶ Emitted when movement has been detected and
motion
changes totrue
.thing.on('movement', () => console.log('Movement detected'));
-
inactivity
¶ Emitted when movement is no longer detected and
motion
changes tofalse
.thing.on('inactivity', () => console.log('Movement no longer detected'));
Protected methods¶
-
updateMotion
(value[, autoIdleTimeout])¶ Update the current motion status.
Arguments: - value (boolean) – The motion status,
true
if motion detected otherwisefalse
. - autoIdleTimeout (duration) – Optional duration to switch back the motion status to
false
.
Example:
this.updateMotion(false); // Set motion to true and automatically switch back after 20 seconds this.updateMotion(true, '20s');
- value (boolean) – The motion status,
Implementing capability¶
Implementors of this capability should call updateMotion
if motion is
detected. Implementations may choose between using automatic timeouts for
switching motion back to false
or managing the switchin on their own.
const { Sensor, Motion } = require('abstract-things/sensors');
class Example extends Sensor.with(Motion) {
constructor() {
super();
this.updateMotion(true, '1m');
}
}