Skip to content

Commit 7957320

Browse files
author
linchengyu
committed
feat: initial release
0 parents  commit 7957320

File tree

17 files changed

+17462
-0
lines changed

17 files changed

+17462
-0
lines changed

.github/workflows/ci.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: CI
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
push:
8+
branches:
9+
- main
10+
11+
jobs:
12+
build-and-test:
13+
runs-on: ubuntu-latest
14+
15+
strategy:
16+
matrix:
17+
node-version: [18, 20]
18+
19+
steps:
20+
- name: Checkout code
21+
uses: actions/checkout@v4
22+
23+
- name: Setup Node.js ${{ matrix.node-version }}
24+
uses: actions/setup-node@v4
25+
with:
26+
node-version: ${{ matrix.node-version }}
27+
cache: 'npm'
28+
29+
- name: Install dependencies
30+
run: npm ci
31+
32+
- name: Build
33+
run: npm run build
34+
35+
- name: Run tests
36+
run: npm test
37+
continue-on-error: true
38+
39+
- name: Check dist exists
40+
run: |
41+
if [ ! -d "dist" ]; then
42+
echo "Error: dist directory not found after build"
43+
exit 1
44+
fi
45+
echo "✅ Build output verified"
46+
47+
- name: Verify package files
48+
run: |
49+
if [ ! -f "dist/index.js" ]; then
50+
echo "Error: dist/index.js not found"
51+
exit 1
52+
fi
53+
if [ ! -f "dist/index.d.ts" ]; then
54+
echo "Error: dist/index.d.ts not found"
55+
exit 1
56+
fi
57+
echo "✅ Package files verified"

.github/workflows/release.yml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Publish to npm (on tag)
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*.*.*'
7+
8+
jobs:
9+
publish:
10+
runs-on: ubuntu-latest
11+
12+
permissions:
13+
contents: read
14+
id-token: write
15+
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v4
19+
20+
- name: Setup Node.js
21+
uses: actions/setup-node@v4
22+
with:
23+
node-version: '20'
24+
registry-url: 'https://registry.npmjs.org'
25+
26+
- name: Install dependencies
27+
run: npm ci
28+
29+
- name: Build
30+
run: npm run build
31+
32+
- name: Run tests
33+
run: npm test
34+
continue-on-error: true
35+
36+
- name: Verify package.json version matches tag
37+
run: |
38+
TAG_VERSION=${GITHUB_REF#refs/tags/v}
39+
PACKAGE_VERSION=$(node -p "require('./package.json').version")
40+
if [ "$TAG_VERSION" != "$PACKAGE_VERSION" ]; then
41+
echo "Error: Tag version ($TAG_VERSION) does not match package.json version ($PACKAGE_VERSION)"
42+
exit 1
43+
fi
44+
echo "Version check passed: $TAG_VERSION"
45+
46+
- name: Publish to npm
47+
run: npm publish --access public
48+
env:
49+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
50+
51+
- name: Create GitHub Release
52+
uses: actions/create-release@v1
53+
env:
54+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
55+
with:
56+
tag_name: ${{ github.ref }}
57+
release_name: Release ${{ github.ref }}
58+
draft: false
59+
prerelease: false

.gitignore

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Dependencies
2+
node_modules/
3+
npm-debug.log*
4+
yarn-debug.log*
5+
yarn-error.log*
6+
7+
# Production builds
8+
dist/
9+
build/
10+
11+
# Environment variables
12+
.env
13+
.env.local
14+
.env.development.local
15+
.env.test.local
16+
.env.production.local
17+
18+
# IDE
19+
.vscode/
20+
.idea/
21+
*.swp
22+
*.swo
23+
24+
# OS
25+
.DS_Store
26+
Thumbs.db
27+
28+
# Test coverage
29+
coverage/
30+
*.lcov
31+
32+
# Logs
33+
logs/
34+
*.log
35+
36+
# Runtime data
37+
pids/
38+
*.pid
39+
*.seed
40+
*.pid.lock
41+
42+
# TypeScript
43+
*.tsbuildinfo
44+
45+
# Optional npm cache directory
46+
.npm
47+
48+
# Optional REPL history
49+
.node_repl_history
50+
51+
# Output of 'npm pack'
52+
*.tgz
53+
54+
# Yarn Integrity file
55+
.yarn-integrity
56+
57+
# dotenv environment variables file
58+
.env
59+
60+
# Jest coverage
61+
coverage/
62+
63+
# ESLint cache
64+
.eslintcache
65+
66+
# Temporary folders
67+
tmp/
68+
temp/

README.md

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
# SwitchBot Channel for OpenClaw
2+
3+
> Connect your SwitchBot smart home devices to OpenClaw platform for real-time device status monitoring
4+
5+
## 📖 Project Overview
6+
7+
SwitchBot Channel is an official channel plugin for the OpenClaw platform that receives real-time SwitchBot device status changes via MQTT protocol. Whether it's contact sensors, temperature/humidity meters, or smart plugs, you can monitor device status in real-time through OpenClaw and set up intelligent notifications.
8+
9+
## ✨ Features
10+
11+
- 🔄 **Real-time Sync**: Receive device status via MQTT in real-time
12+
- 🏠 **Device Compatibility**: Support for all mainstream SwitchBot devices
13+
- 🔑 **Auto Authentication**: Intelligent credential management with auto-renewal
14+
- 🚨 **Smart Notifications**: Send notifications only for important events to avoid interruptions
15+
- 🔧 **Zero Configuration**: Out-of-the-box functionality with just SwitchBot Token and Secret
16+
- 📊 **History Records**: Local storage of device status history
17+
- 🛡️ **High Availability**: Auto-reconnection with automatic recovery after network interruptions
18+
19+
## 🚀 Quick Start
20+
21+
### System Requirements
22+
23+
- **OpenClaw**: >= 2026.1.0
24+
- **Node.js**: >= 18.0.0
25+
- **SwitchBot App**: Latest version
26+
27+
### Step 1: Install Plugin
28+
29+
#### Prerequisites
30+
31+
Before installing the plugin, ensure your OpenClaw environment has the required dependencies:
32+
33+
```bash
34+
# Install pnpm if not already installed
35+
npm install -g pnpm
36+
37+
# Install dependencies in your OpenClaw installation
38+
pnpm install
39+
```
40+
41+
#### Installation
42+
43+
```bash
44+
# Install plugin from npm
45+
openclaw plugins install @switchbot/openclaw-channel-switchbot
46+
47+
# Verify installation
48+
openclaw plugins list
49+
```
50+
51+
### Step 2: Get SwitchBot Credentials
52+
53+
1. **Open SwitchBot App**
54+
2. **Enter Developer Options**:
55+
- Tap "Settings" in bottom right
56+
- Find and tap "Developer Options"
57+
- If this option doesn't exist, ensure the App is updated to the latest version
58+
59+
3. **Get Credentials**:
60+
- Record the **Token** (64-character string)
61+
- Record the **Secret** (32-character string)
62+
63+
> ⚠️ **Important**: Keep your Token and Secret secure and don't share them with others
64+
65+
### Step 3: Configure OpenClaw
66+
67+
Edit OpenClaw configuration file `~/.openclaw/openclaw.json`:
68+
69+
```json
70+
{
71+
"plugins": {
72+
"entries": {
73+
"openclaw-channel-switchbot": {
74+
"enabled": true
75+
}
76+
}
77+
},
78+
"channels": {
79+
"switchbot": {
80+
"enabled": true,
81+
"token": "your_switchbot_token_here",
82+
"secret": "your_switchbot_secret_here"
83+
}
84+
}
85+
}
86+
```
87+
88+
### Step 4: Start Service
89+
90+
```bash
91+
# Restart OpenClaw Gateway
92+
openclaw gateway restart
93+
94+
# Check plugin status
95+
openclaw status
96+
```
97+
98+
## ⚙️ Configuration Details
99+
100+
### Basic Configuration
101+
102+
```json
103+
{
104+
"channels": {
105+
"switchbot": {
106+
"enabled": true,
107+
"token": "xxxx",
108+
"secret": "xxxx"
109+
}
110+
}
111+
}
112+
```
113+
114+
## 📱 Usage Guide
115+
116+
### Device Status Monitoring
117+
118+
After the plugin starts, it will automatically receive status changes from all devices. You can view them using:
119+
120+
```bash
121+
# View device status
122+
openclaw devices list switchbot
123+
124+
# View specific device
125+
openclaw devices show <device_id>
126+
```
127+
128+
## 🔍 Troubleshooting
129+
130+
### Common Issues
131+
132+
#### Q: Plugin fails to start
133+
**A**: Check configuration
134+
135+
```bash
136+
# Check configuration syntax
137+
openclaw config validate
138+
139+
# View detailed errors
140+
openclaw gateway logs --follow
141+
```
142+
143+
### Debug Mode
144+
145+
Enable detailed logging for troubleshooting:
146+
147+
```json
148+
{
149+
"logging": {
150+
"level": "debug",
151+
"channels": {
152+
"switchbot": "debug"
153+
}
154+
}
155+
}
156+
```
157+
158+
View logs:
159+
```bash
160+
# View real-time logs
161+
tail -f ~/.openclaw/logs/gateway.log | grep "SwitchBot"
162+
163+
# View error logs
164+
openclaw gateway logs --level error
165+
```
166+
167+
### Reset Plugin
168+
169+
If you encounter serious issues, you can reset the plugin:
170+
171+
```bash
172+
# Stop service
173+
openclaw gateway stop
174+
175+
# Clear plugin cache
176+
rm -rf ~/.openclaw/cache/plugins/switchbot
177+
178+
# Restart
179+
openclaw gateway start
180+
```
181+
182+
**Made with ❤️ by the SwitchBot Team**

0 commit comments

Comments
 (0)