Skip to content

Switch Sensor

The Switch sensor class provides access to a switch sensor.

Creates a new Switch object instance.

Switch(options)

options

An object of properties used to construct the class.

sensor - The hardware connection definition.

interval (optional) - The sampling interval in milliseconds.

Returns a sample object containing the current switch state.

sample()

An object with the following property:

position - A number that represents the current state of the switch.

const sensor = new device.sensor.Switch({
sensor: {
io: device.io.Digital,
pin: 0
}
});
const sample = sensor.sample();
console.log(`Switch position: ${sample.position}`);

Switch