Fitbit Tracker
Effortless health monitoring powered by the official Fitbit API. No apps, no dashboards — just ask and get your health stats instantly.
Features
Smart Sleep Tracking
- - Automatically separates naps from main sleep
- Reports duration, efficiency, and all sleep stages (Deep, Light, REM, Wake)
- Nap detection with separate reporting
Complete Activity Picture
- - Steps, calories, distance, active minutes
- Resting heart rate
- Heart rate zones (Out of Range, Fat Burn, Cardio, Peak)
Adaptive Reporting
Only shows what you ask for — no unnecessary data.
| You say... | Reports... |
|---|
| "how did I sleep" / "sleep" | Duration, efficiency, all stages, nap |
| "just my steps" |
Steps only |
| "activity today" | Steps, calories, distance, active mins, HR zones |
| "full report" / "everything" / "summary" | All available data |
| "fitbit" / "health" | Complete daily summary |
Clean Formatting
- - Numbers formatted for readability (e.g., "8,234 steps")
- Stages grouped logically
- No raw data dumps
Data Available
Sleep:
- - Duration (total sleep time)
- Sleep efficiency %
- Sleep score (when available)
- Sleep stages: Deep, Light, REM, Wake
- Nap duration (when taken)
Activity:
- - Steps
- Calories (total + BMR)
- Distance (km)
- Resting heart rate
- Active minutes (Very Active, Fairly, Lightly, Sedentary)
- Heart rate zones
Setup
1. Create Fitbit Developer App
- 1. Go to dev.fitbit.com
- Log in and click Register an App
- Fill in:
-
Application Name: OpenClaw Fitbit (or any name)
-
Description: Fitbit integration for OpenClaw
-
Application Website:
https://github.com/yourusername/openclaw
-
OAuth 2.0 Application Type: Choose
Personal
-
Callback URL:
http://localhost:8080 (for local) or your redirect URI
- 4. Accept the terms and register
- Copy your Client ID and Client Secret
2. Configure Environment Variables
CODEBLOCK0
Or add to ~/.openclaw/.env:
CODEBLOCK1
3. Authenticate
Run the OAuth login script:
CODEBLOCK2
This will:
- - Open Fitbit authorization page in your browser
- Ask you to approve access
- Exchange the code for tokens
- Save tokens to INLINECODE3
Tokens are automatically refreshed when they expire.
Commands
The skill uses a 3-step pipeline:
CODEBLOCK3
For a specific date (YYYY-MM-DD format):
CODEBLOCK4
For sleep section only:
CODEBLOCK5
Critical date rule: When user asks about sleep in the morning (e.g., "how did I sleep"), use --date today. Fitbit's sleep API associates sleep with the date you woke up, so last night's sleep (Mar 25 11pm → Mar 26 7am) appears under date "today" (Mar 26). Only use --date yesterday for activity-only queries when you specifically want the previous full day's activity data.
Important: Always run the full pipeline (fetch → normalize → render). Never use raw API duration field directly — it includes wake periods inside the sleep window. The normalized duration_minutes field (which maps to Fitbit's minutesAsleep) is the actual sleep time.
Usage Examples
Sleep report:
CODEBLOCK6
Full daily summary:
CODEBLOCK7
Steps only:
CODEBLOCK8
Python Dependencies
No third-party dependencies required. Uses Python standard library:
- -
urllib.request - HTTP requests - INLINECODE10 - JSON parsing
- INLINECODE11 - Date handling
- INLINECODE12 - Timezone support (Python 3.9+)
Troubleshooting
"Missing env var: FITBITCLIENTID"
Environment variables not loaded. Source your
.env file or ensure variables are set in the gateway environment:
CODEBLOCK9
"Token expired" error
Tokens auto-refresh. If you see this error repeatedly:
- 1. Delete INLINECODE14
- Re-run INLINECODE15
"No data found for this day"
- - Check
FITBIT_TZ matches your timezone - Try
--date yesterday to confirm data exists - Verify Fitbit account has data for the date
Nap not separating from main sleep
This may indicate
isMainSleep flag isn't set correctly on your Fitbit account. The skill filters records by this flag — some older Fitbit devices don't set it properly.
Sleep score not showing
Not all Fitbit accounts/devices provide sleep scores. This is a Fitbit API limitation, not the skill. Efficiency and stages are always reported when available.
API Endpoints Used
- -
GET /1/user/-/activities/date/{date}.json - Daily activity summary - INLINECODE20 - Sleep records
References
- - API details: INLINECODE21
- Output schema: INLINECODE22
Fitbit Tracker
由官方Fitbit API驱动的便捷健康监测。无需应用,无需仪表盘——只需提问,即刻获取健康数据。
功能特性
智能睡眠追踪
- - 自动区分小睡与主睡眠
- 报告时长、效率及所有睡眠阶段(深睡、浅睡、快速眼动、清醒)
- 小睡检测并单独报告
完整活动数据
- - 步数、卡路里、距离、活跃分钟数
- 静息心率
- 心率区间(区间外、燃脂、心肺、峰值)
自适应报告
仅显示您询问的内容——无冗余数据。
| 您说... | 报告内容... |
|---|
| 我睡得怎么样 / 睡眠 | 时长、效率、所有阶段、小睡 |
| 只看步数 |
仅步数 |
| 今天的活动 | 步数、卡路里、距离、活跃分钟、心率区间 |
| 完整报告 / 全部 / 摘要 | 所有可用数据 |
| fitbit / 健康 | 完整每日摘要 |
整洁格式化
- - 数字格式便于阅读(例如8,234步)
- 阶段按逻辑分组
- 无原始数据堆砌
可用数据
睡眠:
- - 时长(总睡眠时间)
- 睡眠效率百分比
- 睡眠评分(可用时)
- 睡眠阶段:深睡、浅睡、快速眼动、清醒
- 小睡时长(有记录时)
活动:
- - 步数
- 卡路里(总计 + 基础代谢率)
- 距离(公里)
- 静息心率
- 活跃分钟数(非常活跃、较活跃、轻度活跃、久坐)
- 心率区间
设置
1. 创建Fitbit开发者应用
- 1. 访问 dev.fitbit.com
- 登录并点击 注册应用
- 填写:
-
应用名称:OpenClaw Fitbit(或任意名称)
-
描述:OpenClaw的Fitbit集成
-
应用网站:https://github.com/yourusername/openclaw
-
OAuth 2.0应用类型:选择
个人
-
回调URL:http://localhost:8080(本地使用)或您的重定向URI
- 4. 接受条款并注册
- 复制您的 客户端ID 和 客户端密钥
2. 配置环境变量
bash
export FITBITCLIENTID=yourclientid
export FITBITCLIENTSECRET=yourclientsecret
export FITBITREDIRECTURI=http://localhost:8080
export FITBIT_TZ=Europe/London # 您的时区
或添加到 ~/.openclaw/.env:
FITBITCLIENTID=yourclientid
FITBITCLIENTSECRET=yourclientsecret
FITBITREDIRECTURI=http://localhost:8080
FITBIT_TZ=Europe/London
3. 身份验证
运行OAuth登录脚本:
bash
python3 scripts/fitbitoauthlogin.py
此操作将:
- - 在浏览器中打开Fitbit授权页面
- 请求您批准访问
- 将授权码交换为令牌
- 将令牌保存到 ~/.config/openclaw/fitbit/token.json
令牌过期时会自动刷新。
命令
该技能使用三步流水线:
bash
步骤1:从Fitbit API获取原始数据
重要提示:对于睡眠查询(早晨),使用 --date today 而非 yesterday!
Fitbit将昨晚的睡眠归入今天的日期。
python3 scripts/fitbit
fetchdaily.py --date today --out /tmp/fitbit_raw.json
步骤2:规范化为整洁格式(提取实际睡眠时间、阶段、活动)
python3 scripts/fitbit
normalizedaily.py /tmp/fitbit
raw.json --out /tmp/fitbitday.json
步骤3:渲染显示(使用 --channel discord、telegram 或 generic)
python3 scripts/fitbit
render.py /tmp/fitbitday.json --channel discord
指定日期(YYYY-MM-DD格式):
bash
python3 scripts/fitbitfetchdaily.py --date 2026-03-25 --out /tmp/fitbit_raw.json
仅睡眠部分:
bash
python3 scripts/fitbitrender.py /tmp/fitbitday.json --channel discord --section sleep
关键日期规则: 当用户在早晨询问睡眠情况时(例如我睡得怎么样),使用 --date today。Fitbit的睡眠API将睡眠关联到您醒来的日期,因此昨晚的睡眠(3月25日晚上11点→3月26日早上7点)会出现在日期today(3月26日)下。仅在您明确需要前一天完整活动数据的活动查询时,才使用 --date yesterday。
重要提示: 始终运行完整流水线(获取→规范化→渲染)。切勿直接使用原始API的 duration 字段——它包含睡眠窗口内的清醒时段。规范化后的 duration_minutes 字段(映射到Fitbit的 minutesAsleep)才是实际睡眠时间。
使用示例
睡眠报告:
Fitbit — 2026-03-21
- - 睡眠:7小时32分钟(评分85)| 93%效率
- 阶段:深睡:1小时42分钟,浅睡:3小时20分钟,快速眼动:1小时45分钟,清醒:45分钟
完整每日摘要:
Fitbit — 2026-03-21
- - 睡眠:7小时32分钟(评分85)| 93%效率
- 阶段:深睡:1小时42分钟,浅睡:3小时20分钟,快速眼动:1小时45分钟,清醒:45分钟
- - 小睡:1小时6分钟
- 步数:8,234
- 卡路里:1,892(基础代谢率1,048)
- 距离:6.2公里
- 静息心率:58次/分钟
- 活跃分钟:非常活跃:45分钟,较活跃:23分钟,轻度活跃:1小时24分钟,久坐:8小时12分钟
- 心率区间:区间外:12小时,燃脂:1小时30分钟,心肺:32分钟,峰值:8分钟
仅步数:
Python依赖
无需第三方依赖。使用Python标准库:
- - urllib.request - HTTP请求
- json - JSON解析
- datetime - 日期处理
- zoneinfo - 时区支持(Python 3.9+)
故障排除
缺少环境变量:FITBITCLIENTID
环境变量未加载。加载您的 .env 文件或确保变量已在网关环境中设置:
bash
source ~/.openclaw/.env
令牌过期错误
令牌会自动刷新。如果反复出现此错误:
- 1. 删除 ~/.config/openclaw/fitbit/token.json
- 重新运行 python3 scripts/fitbitoauthlogin.py
未找到该日期的数据
- - 检查 FITBIT_TZ 是否与您的时区匹配
- 尝试 --date yesterday 确认数据是否存在
- 验证Fitbit账户中该日期是否有数据
小睡未与主睡眠分离
这可能表明您的Fitbit账户上 isMainSleep 标志未正确设置。该技能通过此标志过滤记录——某些较旧的Fitbit设备无法正确设置该标志。
睡眠评分未显示
并非所有Fitbit账户/设备都提供睡眠评分。这是Fitbit API的限制,而非技能问题。效率和阶段在可用时始终会报告。
使用的API端点
- - GET /1/user/-/activities/date/{date}.json - 每日活动摘要
- GET /1.2/user/-/sleep/date/{date}.json - 睡眠记录
参考资料
- - API详情:references/fitbitapi.md
- 输出模式:references/outputschema.md