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.
- Host: GitHub
- URL: https://github.com/clebert/node-switch-bot
- Owner: clebert
- License: mit
- Created: 2021-04-29T15:02:15.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2023-03-26T22:53:38.000Z (about 3 years ago)
- Last Synced: 2025-09-13T11:27:19.888Z (9 months ago)
- Language: TypeScript
- Homepage:
- Size: 78.1 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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
```