Fitbit Analytics
Quick Start
CODEBLOCK0
When to Use
Use this skill when:
- - Fetching Fitbit metrics (steps, calories, heart rate, sleep)
- Analyzing activity trends over time
- Setting up alerts for inactivity or abnormal heart rate
- Generating daily/weekly health reports
Core Workflows
1. Daily Briefing
CODEBLOCK1
Example JSON output:
CODEBLOCK2
Note: Cardio Load is NOT available via Fitbit API - it's a Fitbit Premium feature only visible in the mobile app.
2. Data Fetching (CLI)
CODEBLOCK3
3. Data Fetching (Python API)
CODEBLOCK4
4. Analysis
CODEBLOCK5
5. Alerts
CODEBLOCK6
Scripts
- -
scripts/fitbit_api.py - Fitbit Web API wrapper, CLI, and analysis - INLINECODE1 - Morning briefing CLI (text/brief/json output)
- INLINECODE2 - Threshold-based notifications
Available API Methods
| Method | Description |
|---|
| INLINECODE3 | Daily step counts |
| INLINECODE4 |
Daily calories burned |
|
get_distance(start, end) | Daily distance |
|
get_activity_summary(start, end) | Activity summary |
|
get_heartrate(start, end) | Heart rate data |
|
get_sleep(start, end) | Sleep data |
|
get_sleep_stages(start, end) | Detailed sleep stages |
|
get_spo2(start, end) | Blood oxygen levels |
|
get_weight(start, end) | Weight measurements |
|
get_active_zone_minutes(start, end) | Active Zone Minutes (AZM) breakdown |
References
- -
references/api.md - Fitbit Web API documentation - INLINECODE14 - Metric definitions and interpretations
Authentication
Fitbit API requires OAuth 2.0 authentication:
- 1. Create app at: https://dev.fitbit.com/apps
- Get clientid and clientsecret
- Complete OAuth flow to get accesstoken and refreshtoken
- Set environment variables or pass to scripts
Environment
Required:
- - INLINECODE15
- INLINECODE16
- INLINECODE17
- INLINECODE18
Automation (Cron Jobs)
Cron jobs are configured in OpenClaw's gateway, not in this repo. Add these to your OpenClaw setup:
Daily Morning Briefing (8:00 AM)
CODEBLOCK7
Note: Replace /path/to/your/ with your actual path and <YOUR_TELEGRAM_CHAT_ID> with your Telegram channel/group ID.
Fitbit 分析
快速开始
bash
设置 Fitbit API 凭证
export FITBIT
CLIENTID=your
clientid
export FITBIT
CLIENTSECRET=your
clientsecret
export FITBIT
ACCESSTOKEN=your
accesstoken
export FITBIT
REFRESHTOKEN=your
refreshtoken
生成包含活跃区间分钟数的晨间简报
python scripts/fitbit_briefing.py
获取每日步数
python scripts/fitbit_api.py steps --days 7
获取心率数据
python scripts/fitbit_api.py heartrate --days 7
睡眠摘要
python scripts/fitbit_api.py sleep --days 7
生成每周健康报告
python scripts/fitbit_api.py report --type weekly
获取活动摘要
python scripts/fitbit_api.py summary --days 7
使用场景
在以下情况下使用此技能:
- - 获取 Fitbit 指标(步数、卡路里、心率、睡眠)
- 分析一段时间内的活动趋势
- 设置久坐或心率异常提醒
- 生成每日/每周健康报告
核心工作流程
1. 每日简报
bash
生成晨间健康简报(包含活跃区间分钟数)
python scripts/fitbit_briefing.py # 今日简报
python scripts/fitbit_briefing.py --date 2026-01-20 # 指定日期
python scripts/fitbit_briefing.py --format brief # 三行摘要
python scripts/fitbit_briefing.py --format json # JSON 输出
示例输出包含:
- 昨日活动(记录的运动)
- 昨日活跃区间分钟数(总计、燃脂、心肺、峰值)
- 今日活动摘要(步数、卡路里、楼层、距离)
- 心率(静息、平均、区间分布)
- 睡眠(时长、效率、清醒次数)
- 与7天平均值的趋势对比
示例 JSON 输出:
json
{
date: 2026-01-21,
steps_today: 8543,
calories_today: 2340,
distance_today: 6.8,
floors_today: 12,
active_minutes: 47,
resting_hr: 58,
avg_hr: 72,
sleep_hours: 7.2,
sleep_efficiency: 89,
awake_minutes: 12,
yesterday_activities: [
{name: 跑步, duration: 35, calories: 320}
],
yesterday_azm: {
activeZoneMinutes: 61,
fatBurnActiveZoneMinutes: 39,
cardioActiveZoneMinutes: 22
}
}
注意: 心肺负荷数据无法通过 Fitbit API 获取——这是 Fitbit Premium 专属功能,仅在手机应用中可见。
2. 数据获取(命令行界面)
bash
可用命令:
python scripts/fitbit_api.py steps --days 7
python scripts/fitbit_api.py calories --days 7
python scripts/fitbit_api.py heartrate --days 7
python scripts/fitbit_api.py sleep --days 7
python scripts/fitbit_api.py summary --days 7
python scripts/fitbit_api.py report --type weekly
3. 数据获取(Python API)
bash
export PYTHONPATH={baseDir}/scripts
python - <
client = FitbitClient() # 使用环境变量获取凭证
获取数据(需要 startdate 和 enddate)
stepsdata = client.getsteps(startdate=2026-01-01, enddate=2026-01-16)
hrdata = client.getheartrate(startdate=2026-01-01, enddate=2026-01-16)
sleepdata = client.getsleep(startdate=2026-01-01, enddate=2026-01-16)
activitysummary = client.getactivitysummary(startdate=2026-01-01, end_date=2026-01-16)
PY
4. 分析
bash
export PYTHONPATH={baseDir}/scripts
python - <analyzer = FitbitAnalyzer(stepsdata, hrdata)
summary = analyzer.summary()
print(summary) # 返回:avgsteps, avgrestinghr, steptrend
PY
5. 提醒
bash
python {baseDir}/scripts/alerts.py --days 7 --steps 8000 --sleep 7
脚本
- - scripts/fitbitapi.py - Fitbit Web API 封装、命令行界面和分析
- scripts/fitbitbriefing.py - 晨间简报命令行界面(文本/简要/JSON 输出)
- scripts/alerts.py - 基于阈值的通知
可用 API 方法
| 方法 | 描述 |
|---|
| getsteps(start, end) | 每日步数 |
| getcalories(start, end) |
每日消耗卡路里 |
| get_distance(start, end) | 每日距离 |
| getactivitysummary(start, end) | 活动摘要 |
| get_heartrate(start, end) | 心率数据 |
| get_sleep(start, end) | 睡眠数据 |
| getsleepstages(start, end) | 详细睡眠阶段 |
| get_spo2(start, end) | 血氧水平 |
| get_weight(start, end) | 体重测量 |
| getactivezone_minutes(start, end) | 活跃区间分钟数(AZM)细分 |
参考资料
- - references/api.md - Fitbit Web API 文档
- references/metrics.md - 指标定义和解读
认证
Fitbit API 需要 OAuth 2.0 认证:
- 1. 在 https://dev.fitbit.com/apps 创建应用
- 获取 clientid 和 clientsecret
- 完成 OAuth 流程获取 accesstoken 和 refreshtoken
- 设置环境变量或传递给脚本
环境变量
必需:
- - FITBITCLIENTID
- FITBITCLIENTSECRET
- FITBITACCESSTOKEN
- FITBITREFRESHTOKEN
自动化(定时任务)
定时任务在 OpenClaw 的网关中配置,而非此仓库。将这些添加到您的 OpenClaw 设置中:
每日晨间简报(上午 8:00)
bash
openclaw cron add \
--name 晨间 Fitbit 健康报告 \
--cron 0 8 * \
--tz America/Los_Angeles \
--session isolated \
--wake next-heartbeat \
--deliver \
--channel telegram \
--target TELEGRAMCHAT_ID> \
--message python3 /path/to/your/scripts/fitbit_briefing.py --format text
注意: 将 /path/to/your/ 替换为您的实际路径,将 TELEGRAMCHAT_ID> 替换为您的 Telegram 频道/群组 ID。