Skip to content

Add AutoPresets feature: automatically activate your Loop override presets during walking/running activity#2402

Open
taylorpatterson-T1D wants to merge 1 commit intoLoopKit:devfrom
TaylorJPatterson:feat/AutoPresets
Open

Add AutoPresets feature: automatically activate your Loop override presets during walking/running activity#2402
taylorpatterson-T1D wants to merge 1 commit intoLoopKit:devfrom
TaylorJPatterson:feat/AutoPresets

Conversation

@taylorpatterson-T1D
Copy link

@taylorpatterson-T1D taylorpatterson-T1D commented Feb 8, 2026

Problem That We're Solving

People with Type 1 diabetes who use Loop often need to manually activate an override preset before physical activity like walking or running. This is easy to forget, especially for spontaneous activity — a walk with the dog, touring a new city on travel, or an unplanned errand on foot. Forgetting to activate an exercise preset can lead to lows, since Loop's algorithm doesn't know the user is moving and continues dosing at normal rates.

There is currently no way in Loop to automatically respond to real-world physical activity by adjusting insulin delivery. Users must either remember to manually activate a preset before every walk or run, or accept the risk of going low. This is a big quality-of-life gap, especially for active users who move throughout the day.

New Feature's Impact

AutoPresets adds automatic, hands-free override preset activation based on real-time walking and running detection using Apple's CoreMotion framework. When the user starts walking or running, Loop detects the activity and activates the preset they've chosen for that activity type. When they stop, Loop automatically deactivates it.

What it does

  • Detects walking and running activity using CMPedometer (step counting) and CMMotionActivityManager (activity classification)
  • Applies a user-selected override preset automatically when sustained activity is confirmed
  • Removes the override automatically after activity stops, with a configurable delay
  • Respects manually-activated overrides — won't override a preset the user set themselves
  • Supports separate preset assignments for walking vs. running (e.g., a mild reduction for walks, a stronger reduction for runs)

User-configurable settings

  • Enable/disable the feature entirely
  • Activity types — toggle walking and/or running detection independently
  • Preset selection — choose which existing override preset to apply for each activity type
  • Continuous Activity Time — how long sustained activity must continue before the preset activates (10 sec to 10 min, acts as a confirmation to avoid false triggers from brief movement)
  • Stop Delay — how long to wait after motion stops before deactivating the preset (10 sec to 10 min)
  • Require High Confidence — optionally require CoreMotion's high-confidence classification for stricter detection
  • Activity log — view recent activation/deactivation events with timestamps and durations
  • Debug logging — optional detailed logging for troubleshooting

How detection works

  1. CMPedometer counts steps in real-time
  2. After 20+ steps, a "Continuous Activity Time" timer starts
  3. CMMotionActivityManager classifies the activity as walking or running
  4. When the timer fires, it verifies steps are still accumulating (> 5 additional steps)
  5. If confirmed, the mapped preset is activated via Loop's existing override system
  6. A stop timer monitors for inactivity — if no significant steps occur during the stop interval, the preset is deactivated
  7. If the user resumes walking/running during the stop interval, the deactivation is cancelled

Safety considerations

  • Uses Loop's existing TemporaryScheduleOverride system — no new insulin delivery pathways
  • Will not override a manually-activated preset
  • Automatically deactivates when activity stops
  • All activation/deactivation events are logged
  • Feature is off by default and requires explicit user configuration
  • Errors in motion detection do not disable the feature or affect Loop's core operation

Architecture

  • 7 new files, all within Loop/Loop/ following Loop's layer-based architecture (Views, Managers, Models)
  • 2 existing files modified with minimal changes:
    • SettingsView.swift — NavigationLink to the new settings screen
    • LoopDataManager.swift — ~40-line delegate extension for preset activation/deactivation
  • Self-contained feature with a single delegate protocol for all communication with Loop
  • No changes to LoopKit, LoopAlgorithm, or any other submodules
  • Developed from v3.10.0 DEV branch

New files

| AutoPresetsSettingsView.swift | Views/ | SwiftUI settings UI |
| AutoPresetsCoordinator.swift | Managers/ | Main coordinator — activity detection and preset activation logic |
| AutoPresetsDelegate.swift | Managers/ | Protocol for communicating with LoopDataManager |
| AutoPresetsStorage.swift | Managers/ | UserDefaults persistence |
| AutoPresetsLogger.swift | Managers/ | Debug logging infrastructure |
| ActivityDetectionManager.swift | Managers/ | CoreMotion wrapper (CMPedometer, CMMotionActivityManager) |
| AutoPresetsModels.swift | Models/ | Data models (ActivityType, Settings, LogEntry, etc.) |


Screenshots

  1. Settings menu showing the Auto-Apply Presets entry
Screenshot 2026-02-07 at 3 59 09 PM
  1. AutoPresets main settings screen (feature enabled, activity types visible)
  2. Preset selection for an activity type
  3. Detection settings (sliders for timing)
Screenshot 2026-02-07 at 3 59 21 PM
  1. Activity log showing activation/deactivation events
Screenshot 2026-02-07 at 3 59 37 PM ---

Video Demo

https://youtube.com/shorts/H45iZCnL2XQ

Test Plan

  • Enable AutoPresets, select a preset for walking, walk for 1+ minutes — verify preset activates
  • Stop walking — verify preset deactivates after the configured stop delay
  • Enable running detection with a different preset — verify the correct preset activates for each activity type
  • Manually activate an override, then start walking — verify AutoPresets does not override the manual preset
  • Adjust Continuous Activity Time slider — verify brief movement does not trigger activation
  • Adjust Stop Delay slider — verify preset stays active during short pauses
  • Toggle "Require High Confidence" — verify stricter detection behavior
  • Disable the feature — verify monitoring stops and no presets are auto-activated
  • Check activity log for correct event entries and timestamps
  • Test on device without motion capabilities (simulator) — verify no crash
  • Test on device in the field. Capture and post logs for troubleshooting. Verify walking or running activity is captured and preset is applied, then deactivated after Stop Time.

Requesting review from @marionbarker

…ivity

CoreMotion-based activity detection that automatically applies user-selected
override presets when walking or running is detected. 7 new files, 2 modified.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant