DEV Community

Tim Oster
Tim Oster

Posted on • Originally published at timoster.dev

How I automated my fitness goals

My dilemma: I am lazy efficient, health is important, and exercise cannot be automated yet. At least the physical activity cannot - the tracking however can.

A few years ago, I bought an Oura Ring. Since then, I started optimizing for high scores but always fell short on the Activity Metric for two reasons:

  1. I don't get enough activity every day, since I only go to the gym every other day.
  2. Even when I go, if the wearable does not track what I am doing auto-magically, I usually forget to log my workouts.

In this post, I am presenting my automations to fix these issues and consistently hit my daily activity goal!

Under-desk Treadmill

The idea of a treadmill under your desk is amazing. Walking the recommended 7-10k steps every day takes about 2 hours at 2.5-3 km/h. While doable, this can be difficult to fit into one's schedule, especially taking factors into account such as bad weather, insufficiently long free time blocks, or in general too much to do that needs a computer.

Having the treadmill accessible while working has been a game changer for me. Spreading those two hours over a working day and being able to pause at any point is far more convenient than the outdoor alternative.

Fortunately, the walking pad I bought (Kingsmith Walkingpad P1) uses Bluetooth for its App and is popular enough so that others already invested the time to reverse engineer its protocol (shout out to ph4r05). This allowed me to build my own small MacOS App to control and track my walking sessions and fire a webhook after a session paused or ended with the corresponding metadata (steps or distance). I'll later explain how I use these webhooks to sync data to Oura Health.

The amazing part is that the treadmill automatically stops when it detects that you are no longer standing on it. Combined with the webhook and automatic session tracking, this allows me to grab another glass of water after an arbitrary amount of walking, get distracted for 15 minutes and come back and resume my session without having to press any buttons. In the background, my initial walking session gets synced to Oura, because the software detected that the treadmill stopped.

Detecting Gym Sessions

My other type of activity is going to the gym. Usually, this is easy to track since you can just activate the workout mode when you get there (or you could even use a location based Apple Shortcut). In my case, it is even simpler than that if I would track my workout using my gym's app, since it has a direct Apple Health integration. But that would be too simple, wouldn't it? My two issues are as follows:

  1. I almost never bring my phone to the gym. For me, this is an easy way to get some off-screen time.
  2. Even if I bring my phone, I cannot be bothered with taking it out after each set and logging my activity manually. And the chance is high that I would forget to, which is even worse because then I only have partial data.

So time to over-engineer this simple problem: since my gym uses EGym / Netpulse, it has Member Card NFC check-ins, which can be accessed via a private API that is called within their App. Using mitmproxy allowed me to quickly identify the check-in related endpoints and the auth mechanism.

With that knowledge, I built a simple worker function for Cloudflare Workers and used their Cron Triggers to periodically check if any new check-in occurred for my account, by comparing the most recent check-in with a value cached in a Cloudflare KV Namespace. Any new event will trigger a webhook with the check-in timestamp and a fixed duration of 60 minutes (the API does not expose the check-outs as of now).

Apple Health

With having the ability to send webhooks for my most common workouts, there is only one missing piece: logging those in the Oura App. They have a well documented Public API, but unfortunately it is read only. I used the mitmproxy trick from above again, but had to find out that the app uses gRPC and protocol buffers... I am not keen on reverse engineering that.

And I do not have to, since there is a way easier alternative! Oura integrates with Apple Health and can import workouts from it! Albeit Apple does not provide a direct API, apps can integrate with
HealthKit to write health data. After a bit of research, I found that there is an Apple Health IFTTT Action that can log workouts after receiving a webhook. For $3,5/month this currently saves me the trouble of writing my own iOS app.

I have two applets on IFTTT: one for the treadmill webhook and one for the gym check-in, each creating an entry in Apple Health for their respective workout type. The sync happens automatically in the background and I receive a push notification from Oura prompting me to select the intensity of my workout so that it can calculate the approximate amount of kcal burned.

With this, I only have to actually do the workout and must not worry about logging the activity correctly.

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay