An open API service indexing awesome lists of open source software.

https://github.com/clebert/node-switch-bot

A Node.js API for the SwitchBot with native TypeScript support.
https://github.com/clebert/node-switch-bot

Last synced: 8 months ago
JSON representation

A Node.js API for the SwitchBot with native TypeScript support.

Awesome Lists containing this project

README

          

# Node.js SwitchBot

> A Node.js API for the
> [SwitchBot](https://www.switch-bot.com/products/switchbot-bot) with native
> TypeScript support.

This package runs only on Linux and uses BlueZ and D-Bus under the hood.

## Installation

```
npm install @clebert/node-switch-bot @clebert/node-bluez @clebert/node-d-bus
```

## Features

- Designed from the ground up with TypeScript.
- Supports reading and writing the `press`/`switch` mode.
- Supports reading and writing the `on`/`off` switch state.
- Supports reading the battery level.

## Usage example

```js
import {Adapter} from '@clebert/node-bluez';
import {SwitchBot} from '@clebert/node-switch-bot';

await Adapter.use(async (adapter) => {
const switchBot = new SwitchBot(adapter, `XX:XX:XX:XX:XX:XX`);
const properties = await switchBot.getProperties();

console.log(`Mode:`, properties.mode);

if (properties.mode === `switch`) {
console.log(`State:`, properties.state);
}

console.log(`Battery level (%):`, properties.batteryLevel);

await switchBot.press(); // mode: 'press'
await switchBot.switch(`on`); // mode: 'switch', state: 'on'
await switchBot.switch(`off`); // mode: 'switch', state: 'off'
});
```

## Configure D-Bus user permissions

Create the `/etc/dbus-1/system.d/node-bluez.conf` configuration file. The
username may need to be modified.

```xml








```