OpenClaw 的 Garmin Connect 集成:通过 OAuth 同步健身数据(步数、心率、卡路里、训练、睡眠),支持中国(garmin.cn)和全球(garmin.com)平台。
同步你的佳明手表数据到 OpenClaw,支持中国大陆和全球账号。
核心变化:
text
佳明服务器 → 统一同步脚本 → SQLite数据库
├─ 龙虾skill(读取)
└─ 网页前端(读取)
用户发现身体电量显示不一致(服务器79 vs 手表28),发现数据库同步不完整。
1. 数据库Schema升级
body_battery_current 从存最高值改为存最新值2. 同步策略优化
3. 数据完整度提升
python
# 旧逻辑(错误)
body_battery_current = bodyBatteryHighestValue # 79
# 新逻辑(正确)
body_battery_current = bodyBatteryMostRecentValue # 29
中国大陆账号:
bash
cd ~/openclaw/skills/garmin-connect
python3 scripts/garmin-auth.py your-email@qq.com password --cn
全球账号:
bash
python3 scripts/garmin-auth.py your-email@gmail.com password
认证成功后,凭证会加密保存到 ~/.garth/session.json。
systemd timer(推荐):
bash
# 已自动配置,每1小时同步一次
sudo systemctl status garmin-sync.timer
手动触发:
bash
python3 ~/.clawdbot/garmin/sync_all.py --source=manual
从数据库读取(快速):
bash
python3 scripts/garmin_db_reader.py
从API读取(慢速,用于测试):
bash
python3 scripts/garmin-sync.py
text
/home/roots/.clawdbot/garmin/data.db
每日健康指标 (daily_metrics):
睡眠数据 (sleep_data):
运动记录 (workouts):
每1小时自动同步一次(systemd timer):
bash
sudo systemctl start garmin-sync.timer
sudo systemctl enable garmin-sync.timer
查看下次同步时间:
bash
systemctl list-timers | grep garmin
当你问"我刚才跑的咋样?"时:
python
from scripts.garmin_db_reader import trigger_sync_if_needed
# 如果数据超过5分钟,自动触发同步
trigger_sync_if_needed(max_age_minutes=5)
然后读取数据库回答。
bash
# 从命令行
python3 ~/.clawdbot/garmin/sync_all.py --source=manual
# 从网页(前端API)
POST /api/sync
方式1:从数据库读取(推荐)
python
import sys
sys.path.insert(0, '~/openclaw/skills/garmin-connect/scripts')
from garmin_db_reader import GarminDataReader, trigger_sync_if_needed
# 检查数据新鲜度,必要时触发同步
trigger_sync_if_needed(max_age_minutes=5)
# 读取数据
reader = GarminDataReader()
today = reader.get_today_metrics()
print(f"今日步数: {today['steps']}")
print(f"身体电量: {today['body_battery_current']}")
方式2:直接API调用(兼容旧代码)
python
from garmin_db_reader import get_daily_summary, get_workouts
# garmin_client 参数会被忽略,直接读数据库
data = get_daily_summary(None, '2026-03-13')
python
reader = GarminDataReader()
status = reader.get_sync_status()
print(f"最后同步: {status['last_sync_time']}")
print(f"每日记录: {status['daily_metrics_count']} 条")
print(f"运动记录: {status['workouts_count']} 条")
bash
# 手动运行一次同步
python3 ~/.clawdbot/garmin/sync_all.py --source=manual
检查凭证:
bash
cat ~/.garth/session.json
重新认证:
bash
cd ~/openclaw/skills/garmin-connect
python3 scripts/garmin-auth.py your-email password
bash
# systemd日志
sudo journalctl -u garmin-sync.service -f
# 数据库同步日志
sqlite3 ~/.clawdbot/garmin/data.db "SELECT * FROM sync_log ORDER BY sync_time DESC LIMIT 10"
text
~/.clawdbot/garmin/
├── data.db # SQLite数据库
├── sync_daemon.py # 数据库管理
└── sync_all.py # 完整同步脚本
~/openclaw/skills/garmin-connect/
├── scripts/
│ ├── garmin_db_reader.py # 数据库读取(新增)
│ ├── garmin-auth.py # 认证
│ ├── garmin-sync.py # API获取(兼容)
│ └── ...
└── SKILL.md # 本文件
特性旧版本新版本数据存储无SQLite数据库响应速度API调用(慢)数据库读取(快)同步触发cron(5分钟)timer(1小时)+ 按需数据完整性基础指标完整(含Body Battery等)消费者仅skillskill + 网页前端
/home/roots/garmin-dashboard/~/.clawdbot/garmin/data.db