obniz Parts Library

Switchbot_ContactSensor

GitHub
Switchbot_ContactSensor
Usable Devices :
obniz_board
m5stickc
obnizble
esp32
esp32gateway
m5stackbasic
ak-030
obnizble_lte
obniz_plc

Switchbot_ContactSensor

Switchbot Contact Sensor (WoContact) module

getData()

  • scopeTested: boolean;
  • someoneIsMoving: boolean;
  • battery: number;
  • pir: number;
  • hal: number;
  • halState: 'close' | 'open' | 'timeoutNotClose';
  • lightLevel: 'light' | 'dark';
  • numberOfEntrances: number;
  • numberOfGoOutCounter: number;
  • buttonPushCounter: number;

Example

// Javascript
const Switchbot_ContactSensor = Obniz.getPartsClass("Switchbot_ContactSensor");
await obniz.ble.initWait();
obniz.ble.scan.onfind = async (peripheral) => {
  if (Switchbot_ContactSensor.isDevice(peripheral)) {
    console.log(Switchbot_ContactSensor.getData(peripheral));
  }
};
await obniz.ble.scan.startWait(null, {duplicate: true, duration: null});

Supported from: obniz.js 3.30.0