Ezviz Open Camera Config
萤石设备配置技能。支持 9 个设备配置 API,包括布防/撤防、镜头遮蔽、全天录像、移动侦测灵敏度等。 Use when: 需要远程配置萤石设备参数、修改设备布防状态、调整设备功能开关。 ⚠️ 安全要求:必须设置 EZVIZ_APP_KEY 和 EZVIZ_APP_SECRET 环境变量,使用最小权限凭证。
安装 / 下载方式
TotalClaw CLI推荐
totalclaw install skilldb:ezviz-open~ezviz-open-camera-configcURL直接下载,无需登录
curl -fsSL https://skills.taituai.com/api/skills/skilldb%3Aezviz-open~ezviz-open-camera-config/file -o ezviz-open-camera-config.mdGit 仓库获取源码
git clone https://github.com/openclaw/skills/commit/6365a0df77573c7ca8e79e43ced7117a4dec1b2a# Ezviz Device Config (萤石设备配置)
远程配置萤石设备参数,支持 9 个配置 API。
---
## ⚠️ 安全警告 (安装前必读)
**在使用此技能前,请完成以下安全检查:**
| # | 检查项 | 状态 | 说明 |
|---|--------|------|------|
| 1 | **凭证权限** | ⚠️ 必需 | 使用**最小权限**的 AppKey/AppSecret,不要用主账号凭证 |
| 2 | **配置文件读取** | ⚠️ 注意 | 技能会读取 `~/.openclaw/*.json` 文件(**但环境变量优先级更高**) |
| 3 | **Token 缓存** | ⚠️ 注意 | Token 缓存在 `/tmp/ezviz_global_token_cache/` (权限 600) |
| 4 | **API 域名** | ✅ 已验证 | `openai.ys7.com` 是萤石官方 API 端点(`openai` = Open API,不是 AI) |
| 5 | **代码审查** | ✅ 推荐 | 审查 `scripts/device_config.py` 和 `lib/token_manager.py` |
### 🔒 配置文件读取详细说明
**凭证获取优先级**(从高到低):
```
┌─────────────────────────────────────────────────────────────┐
│ 1. 环境变量 (最高优先级 - 推荐) │
│ ├─ EZVIZ_APP_KEY │
│ ├─ EZVIZ_APP_SECRET │
│ └─ EZVIZ_DEVICE_SERIAL │
│ ✅ 优点:不读取配置文件,完全隔离 │
├─────────────────────────────────────────────────────────────┤
│ 2. OpenClaw 配置文件 (仅当环境变量未设置时使用) │
│ ├─ ~/.openclaw/config.json │
│ ├─ ~/.openclaw/gateway/config.json │
│ └─ ~/.openclaw/channels.json │
│ ⚠️ 注意:只读取 channels.ezviz 字段,不读取其他服务凭证 │
├─────────────────────────────────────────────────────────────┤
│ 3. 命令行参数 (最低优先级) │
│ python3 device_config.py appKey appSecret deviceSerial │
└─────────────────────────────────────────────────────────────┘
```
**安全建议**:
- ✅ **最佳实践**: 使用环境变量,完全避免配置文件读取
- ✅ **隔离配置**: 在专用配置文件只存放萤石凭证,不混用其他服务
- ⚠️ **风险缓解**: 设置环境变量覆盖配置文件(即使配置文件存在也会被忽略)
### 快速安全配置
```bash
# 1. 使用环境变量(优先级最高,避免配置文件意外使用)
export EZVIZ_APP_KEY="your_dedicated_app_key"
export EZVIZ_APP_SECRET="your_dedicated_app_secret"
export EZVIZ_DEVICE_SERIAL="dev1"
# 2. 高安全环境:禁用 Token 缓存
export EZVIZ_TOKEN_CACHE=0
# 3. 测试凭证(推荐先用测试账号)
# 登录 https://openai.ys7.com/ 创建专用应用,仅开通设备配置相关权限
```
### 凭证优先级
技能按以下顺序获取凭证(**优先级从高到低**):
1. **环境变量** (`EZVIZ_APP_KEY`, `EZVIZ_APP_SECRET`) ← 推荐
2. **Channels 配置** (`~/.openclaw/config.json` 等)
3. **命令行参数** (直接传入)
---
## 快速开始
### 安装依赖
```bash
pip install requests
```
### 设置环境变量
```bash
export EZVIZ_APP_KEY="your_app_key"
export EZVIZ_APP_SECRET="your_app_secret"
export EZVIZ_DEVICE_SERIAL="dev1"
```
可选环境变量:
```bash
export EZVIZ_CHANNEL_NO="1" # 通道号,默认 1
export EZVIZ_TOKEN_CACHE="1" # Token 缓存:1=启用 (默认), 0=禁用
```
**Token 缓存说明**:
- ✅ **默认启用**: 技能默认使用 Token 缓存,提升效率
- ⚠️ **禁用缓存**: 设置 `EZVIZ_TOKEN_CACHE=0` 每次重新获取 Token
- 📁 **缓存位置**: `/tmp/ezviz_global_token_cache/global_token_cache.json`
- 🔒 **文件权限**: 600 (仅所有者可读写)
- ⏰ **有效期**: 7 天,到期前 5 分钟自动刷新
**注意**:
- 不需要设置 `EZVIZ_ACCESS_TOKEN`!技能会自动获取 Token
- Token 有效期 7 天
### 运行
```bash
python3 {baseDir}/scripts/device_config.py
```
命令行参数:
```bash
# 设置布防 (isDefence=1)
python3 {baseDir}/scripts/device_config.py appKey appSecret dev1 defence_set 1
# 设置撤防 (isDefence=0)
python3 {baseDir}/scripts/device_config.py appKey appSecret dev1 defence_set 0
# 获取布防计划
python3 {baseDir}/scripts/device_config.py appKey appSecret dev1 defence_plan_get
# 设置布防计划
python3 {baseDir}/scripts/device_config.py appKey appSecret dev1 defence_plan_set '{"startTime":"23:00","stopTime":"07:00","period":"0,1,2,3,4,5,6","enable":1}'
# 设置镜头遮蔽 (enable=1)
python3 {baseDir}/scripts/device_config.py appKey appSecret dev1 shelter_set 1
# 获取镜头遮蔽状态
python3 {baseDir}/scripts/device_config.py appKey appSecret dev1 shelter_get
# 设置移动侦测灵敏度 (0-6)
python3 {baseDir}/scripts/device_config.py appKey appSecret dev1 motion_detect_sensitivity_set 5
```
## Channels 配置(推荐)
技能支持从 OpenClaw 的 channels 配置中自动读取萤石凭证,无需单独设置环境变量。
### 配置方式
在 `~/.openclaw/config.json` 或 `~/.openclaw/channels.json` 中添加:
```json
{
"channels": {
"ezviz": {
"appId": "your_app_id",
"appSecret": "your_app_secret",
"domain": "https://openai.ys7.com",
"enabled": true
}
}
}
```
### 配置搜索顺序
技能会按以下顺序查找配置文件:
1. `~/.openclaw/config.json`
2. `~/.openclaw/gateway/config.json`
3. `~/.openclaw/channels.json`
### 优先级
凭证获取优先级:
1. **环境变量** (最高优先级)
- `EZVIZ_APP_KEY`
- `EZVIZ_APP_SECRET`
2. **Channels 配置** (中等优先级)
- `channels.ezviz.appId`
- `channels.ezviz.appSecret`
3. **命令行参数** (最低优先级)
### 优势
- ✅ 集中管理凭证
- ✅ 无需每次设置环境变量
- ✅ 多个技能共享同一配置
- ✅ 更符合 OpenClaw 最佳实践
---
## 工作流程
```
1. 获取 Token (appKey + appSecret → accessToken)
↓
2. 执行配置 (根据 configType 调用对应 API)
↓
3. 输出结果 (JSON + 控制台)
```
## Token 自动获取说明
**你不需要手动获取或配置 `EZVIZ_ACCESS_TOKEN`!**
技能会自动处理 Token 的获取:
```
首次运行:
appKey + appSecret → 调用萤石 API → 获取 accessToken (有效期 7 天)
↓
保存到缓存文件(系统临时目录)
↓
后续运行:
检查缓存 Token 是否过期
├─ 未过期 → 直接使用缓存 Token ✅
└─ 已过期 → 重新获取新 Token
```
**Token 管理特性**:
- ✅ **自动获取**: 首次运行自动调用萤石 API 获取
- ✅ **有效期 7 天**: 获取的 Token 7 天内有效
- ✅ **智能缓存**: Token 有效期内不重复获取,提升效率
- ✅ **安全缓冲**: 到期前 5 分钟自动刷新,避免边界问题
- ✅ **无需配置**: 不需要手动设置 `EZVIZ_ACCESS_TOKEN` 环境变量
- ✅ **安全存储**: 缓存文件存储在系统临时目录,权限 600
- ⚠️ **可选禁用**: 设置 `EZVIZ_TOKEN_CACHE=0` 可禁用缓存(每次运行重新获取)
## 输出示例
```
======================================================================
Ezviz Device Config (萤石设备配置)
======================================================================
[Time] 2026-03-18 21:00:00
[INFO] Device: dev1
[INFO] Config Type: defence_set
[INFO] Value: 1
======================================================================
SECURITY VALIDATION
======================================================================
[OK] Device serial format validated
[OK] Using credentials from environment variables
======================================================================
[Step 1] Getting access token...
======================================================================
[INFO] Using cached global token, expires: 2026-03-25 19:21:16
[SUCCESS] Using cached token, expires: 2026-03-25 19:21:16
======================================================================
[Step 2] Executing config...
======================================================================
[INFO] Calling API: https://openai.ys7.com/api/lapp/device/defence/set
[INFO] Device: dev1, Type: defence_set
[INFO] Value: 1
[SUCCESS] Config executed successfully!
======================================================================
CONFIG RESULT
======================================================================
Device: dev1
Type: defence_set
Value: 1 (armed)
Status: success
======================================================================
```
## 支持的配置类型 (9 个 API)
| 配置类型 | 功能 | 文档 ID | API 路径 | 参数 |
|----------|------|--------|----------|------|
| `defence_set` | 设置布撤防 | 701 | `/api/lapp/device/defence/set` | isDefence: 0/1/8/16 |
| `defence_plan_get` | 获取布撤防时间计划 | 702 | `/api/lapp/device/defence/plan/get` | channelNo(可选) |
| `defence_plan_set` | 设置布撤防计划 | 703 | `/api/lapp/device/defence/plan/set` | startTime,stopTime,period,enable |
| `shelter_get` | 获取镜头遮蔽开关状态 | 706 | `/api/lapp/device/scene/switch/status` | - |
| `shelter_set` | 设置镜头遮蔽开关 | 707 | `/api/lapp/device/scene/switch/set` | enable: 0/1 |
| `fullday_record_get` | 获取全天录像开关状态 | 712 | `/api/lapp/device/fullday/record/switch/status` | - |
| `fullday_record_set` | 设置全天录像开关状态 | 713 | `/api/lapp/device/fullday/record/switch/set` | enable: 0/1 |
| `motion_detect_sensitivity_get` | 获取移动侦测灵敏度配置 | 714 | `/api/lapp/device/algorithm/config/get` | - |
| `motion_detect_sensitivity_set` | 设置移动侦测灵敏度配置 | 715 | `/api/lapp/device/algorithm/config/set` | value: 0-6 |
## API 接口
| 接口 | URL | 文档 |
|------|-----|------|
| 获取 Token | `POST /api/lapp/token/get` | https://openai.ys7.com/help/81 |
| 设置布防 | `POST /api/lapp/device/defence/set` | https://openai.ys7.com/help/701 |
| 获取布防计划 | `POST /api/lapp/device/defence/plan/get` | https://openai.ys7.com/help/702 |
| 镜头遮蔽 | `POST /api/lapp/device/scene/switch/set` | https://openai.ys7.com/help/707 |
| 全天录像 | `POST /api/lapp/device/fullday/record/switch/set` | https://openai.ys7.com/help/713 |
|