ClawSkills logoClawSkills

Garmer

从 Garmin Connect 提取健康和健身数据,包括活动、睡眠、心率、压力、步数和身体成分。当用户询问关于

介绍

# Garmer - Garmin Data Extraction Skill

该技能支持从 Garmin Connect 提取健康和健身数据,以便进行分析和获取洞察。

## 前置条件

1. 一个包含健康数据的 Garmin Connect 账户 2. 已安装 `garmer` CLI 工具(请参阅元数据中的安装选项)

## 身份验证(一次性设置)

在使用 garmer 之前,请先通过 Garmin Connect 进行身份验证:

```bash garmer login ```

这将提示您输入 Garmin Connect 的电子邮件和密码。令牌将保存到 `~/.garmer/garmin_tokens` 以备将来使用。

要检查身份验证状态:

```bash garmer status ```

## 可用命令

### 每日摘要

获取今日的健康摘要(步数、卡路里、心率、压力):

```bash garmer summary # For a specific date: garmer summary --date 2025-01-15 # Include last night's sleep data: garmer summary --with-sleep garmer summary -s # JSON output for programmatic use: garmer summary --json # Combine flags: garmer summary --date 2025-01-15 --with-sleep --json ```

### 睡眠数据

获取睡眠分析(时长、阶段、评分、HRV):

```bash garmer sleep # For a specific date: garmer sleep --date 2025-01-15 ```

### 运动活动

列出最近的健身活动:

```bash garmer activities # Limit number of results: garmer activities --limit 5 # Filter by specific date: garmer activities --date 2025-01-15 # JSON output for programmatic use: garmer activities --json ```

### 活动详情

获取单个活动的详细信息:

```bash # Latest activity: garmer activity # Specific activity by ID: garmer activity 12345678 # Include lap data: garmer activity --laps # Include heart rate zone data: garmer activity --zones # JSON output: garmer activity --json # Combine flags: garmer activity 12345678 --laps --zones --json ```

### 健康快照

获取某一天的综合健康数据:

```bash garmer snapshot # For a specific date: garmer snapshot --date 2025-01-15 # As JSON for programmatic use: garmer snapshot --json ```

### 导出数据

将多天的数据导出为 JSON:

```bash # Last 7 days (default) garmer export

# Custom date range garmer export --start-date 2025-01-01 --end-date 2025-01-31 --output my_data.json

# Last N days garmer export --days 14 ```

### 实用工具命令

```bash # Update garmer to latest version (git pull): garmer update

# Show version information: garmer version ```

## Python API 用法

对于更复杂的数据处理,请使用 Python API:

```python from garmer import GarminClient from datetime import date, timedelta

# Use saved tokens client = GarminClient.from_saved_tokens()

# Or login with credentials client = GarminClient.from_credentials(email="[email protected]", password="pass") ```

### 用户资料

```python # Get user profile profile = client.get_user_profile() print(f"User: {profile.display_name}")

# Get registered devices devices = client.get_user_devices() ```

### 每日摘要

```python # Get daily summary (defaults to today) summary = client.get_daily_summary() print(f"Steps: {summary.total_steps}")

# Get for specific date summary = client.get_daily_summary(date(2025, 1, 15))

# Get weekly summary weekly = client.get_weekly_summary() ```

### 睡眠数据

```python # Get sleep data (defaults to today) sleep = client.get_sleep() print(f"Sleep: {sleep.total_sleep_hours:.1f} hours")

# Get last night's sleep sleep = client.get_last_night_sleep()

# Get sleep for date range sleep_data = client.get_sleep_range( start_date=date(2025, 1, 1), end_date=date(2025, 1, 7) ) ```

### 运动活动

```python # Get recent activities activities = client.get_recent_activities(limit=5) for activity in activities: print(f"{activity.activity_name}: {activity.distance_km:.1f} km")

# Get activities with filters activities = client.get_activities( start_date=date(2025, 1, 1), end_date=date(2025, 1, 31), activity_type="running", limit=20 )

# Get single activity by ID activity = client.get_activity(12345678) ```

### 心率

```python # Get heart rate data for a day hr = client.get_heart_rate() print(f"Resting HR: {hr.resting_heart_rate} bpm")

# Get just resting heart rate resting_hr = client.get_resting_heart_rate(date(2025, 1, 15)) ```

### 压力与身体电量

```python # Get stress data stress = client.get_stress() print(f"Avg stress: {stress.avg_stress_level}")

# Get body battery data battery = client.get_body_battery() ```

### 步数

```python # Get detailed step data steps = client.get_steps() print(f"Total: {steps.total_steps}, Goal: {steps.step_goal}")

# Get just total steps total = client.get_total_steps(date(2025, 1, 15)) ```

### 身体成分

```python # Get latest weight weight = client.get_latest_weight() print(f"Weight: {weight.weight_kg} kg")

# Get weight for specific date weight = client.get_weight(date(2025, 1, 15))

# Get full body composition body = client.get_body_composition() ```

### 水合与呼吸

```python # Get hydration data hydration = client.get_hydration() print(f"Intake: {hydration.total_intake_ml} ml")

# Get respiration data resp = client.get_respiration() print(f"Avg breathing: {resp.avg_waking_respiration} breaths/min") ```

### 综合报告

```python # Get health snapshot (all metrics for a day) snapshot = client.get_health_snapshot() # Returns: daily_summary, sleep, heart_rate, stress, steps, hydration, respiration

# Get weekly health report with trends report = client.get_weekly_health_report() # Returns: activities summary, sleep stats, steps stats, HR trends, stress trends

# Export data for date range data = client.export_data( start_date=date(2025, 1, 1), end_date=date(2025, 1, 31), include_activities=True, include_sleep=True, include_daily=True ) ```

## 常见工作流程

### 健康检查查询

当用户询问“我睡得怎么样?”或“我的健康摘要是什么?”时:

```bash garmer snapshot --json ```

### 活动分析

当用户询问锻炼或运动情况时:

```bash garmer activities --limit 10 ```

### 趋势分析

当分析随时间变化的健康趋势时:

```bash garmer export --days 30 --output health_data.json ```

然后使用 Python 处理 JSON 文件进行分析。

## 可用的数据类型

- **Activities(运动活动)**:跑步、骑行、游泳、力量训练等。 - **Sleep(睡眠)**:时长、阶段(深睡、浅睡、REM)、评分、HRV。 - **Heart Rate(心率)**:静息心率、样本、区间。 - **Stress(压力)**:压力水平、身体电量。 - **Steps(步数)**:总步数、距离、楼层数。 - **Body Composition(身体成分)**:体重、体脂率、肌肉量。 - **Hydration(水合)**:水分摄入追踪。 - **Respiration(呼吸)**:呼吸频率数据。

## 错误处理

如果未通过身份验证:

``` Not logged in. Use 'garmer login' first. ```

如果会话已过期,请重新进行身份验证:

```bash garmer login ```

## 环境变量

- `GARMER_TOKEN_DIR`:用于存储令牌的自定义目录。 - `GARMER_LOG_LEVEL`:设置日志级别(DEBUG、INFO、WARNING、ERROR)。 - `GARMER_CACHE_ENABLED`:启用/禁用数据缓存(true/false)。

## 参考

有关详细的 API 文档和 MoltBot 集成示例,请参阅 `references/REFERENCE.md`。

更多产品