Added last workout and last workouts sensors

This commit is contained in:
Ron Klinkien
2026-01-03 18:49:43 +01:00
parent dc45503bd5
commit cd520530db
5 changed files with 62 additions and 0 deletions

View File

@@ -124,6 +124,7 @@ Sensor values depend on your Garmin devices and connected apps.
|--------|-------------|
| Next Alarm | Next scheduled alarm time |
| Last Activity/Activities | Recent activity info |
| Last Workout/Workouts | Scheduled/planned training sessions |
| Badges/User Points/Level | Gamification metrics |
### Menstrual Cycle Tracking
@@ -361,6 +362,26 @@ pip install -r requirements_lint.txt
# to auto-fix: ruff check . --fix
```
### Discovering New API Endpoints
Want to add support for new Garmin features? Here's how to find the API endpoints:
1. **Login to [Garmin Connect](https://connect.garmin.com)** in your browser
2. **Open Developer Tools** (F12 or Right-click → Inspect)
3. Go to the **Network** tab
4. **Filter by "Fetch/XHR"** to see API calls only
5. **Navigate through the feature** you want to capture
6. **Look for API calls** - they typically go to:
- `connect.garmin.com/proxy/*`
- `connect.garmin.com/activity-service/*`
- `connect.garmin.com/metrics-service/*`
- `connect.garmin.com/*-service/*`
7. **Click on a request** to see the full URL and response data
**Share your findings** in a GitHub issue with:
- The full API URL path
- Example response data (redact personal info)
## 💖 Support This Project
If you find this library useful for your projects, please consider supporting its continued development and maintenance:

View File

@@ -182,6 +182,17 @@ class GarminConnectDataUpdateCoordinator(DataUpdateCoordinator):
summary["lastActivities"] = last_activities
summary["lastActivity"] = last_activities[0] if last_activities else {}
# Fetch workouts (scheduled/planned training sessions)
try:
workouts = await self.hass.async_add_executor_job(
self.api.get_workouts, 0, 10
)
summary["workouts"] = workouts.get("workouts", []) if isinstance(workouts, dict) else workouts
summary["lastWorkout"] = summary["workouts"][0] if summary["workouts"] else {}
except Exception:
summary["workouts"] = []
summary["lastWorkout"] = {}
badges = await self.hass.async_add_executor_job(self.api.get_earned_badges)
summary["badges"] = badges

View File

@@ -842,6 +842,25 @@ ACTIVITY_TRACKING_SENSORS: tuple[GarminConnectSensorEntityDescription, ...] = (
],
},
),
GarminConnectSensorEntityDescription(
key="lastWorkout",
translation_key="last_workout",
icon="mdi:dumbbell",
value_fn=lambda data: data.get("lastWorkout", {}).get("workoutName"),
attributes_fn=lambda data: data.get("lastWorkout", {}),
),
GarminConnectSensorEntityDescription(
key="lastWorkouts",
translation_key="last_workouts",
state_class=SensorStateClass.TOTAL,
icon="mdi:dumbbell",
value_fn=lambda data: len(data.get("workouts", [])),
attributes_fn=lambda data: {
"last_workouts": data.get("workouts", [])[-10:],
},
),
GarminConnectSensorEntityDescription(
key="badges",
translation_key="badges",

View File

@@ -337,6 +337,12 @@
"last_activities": {
"name": "Last activities"
},
"last_workout": {
"name": "Last workout"
},
"last_workouts": {
"name": "Last workouts"
},
"badges": {
"name": "Badges"
},

View File

@@ -101,6 +101,11 @@ This integration provides **110+ sensors** covering various health and fitness m
- **Fitness Age** - Estimated fitness age
- **Endurance Score** - Overall endurance rating
### Workouts
- **Last Workout** - Name of most recent scheduled workout
- **Last Workouts** - Count of recent workouts (details in attributes)
### Menstrual Cycle Tracking
- **Cycle Phase** - Current menstrual phase