Charting your heart rate with a Mi Band and Tasker

Build a live heart rate chart from a Mi Band using Tasker, a small Node server and MongoDB.

AL
Andrea Lin

Full Stack Developer2 min read

Placeholder cover image

Ever wanted to see your own heart rate on a chart, on your own website, without handing the data to anyone else? Turns out you can do it with a Mi Band, an Android phone and a couple of small apps. Here's how I set it up.

Things you need

  • MongoDB — stores the heart rate readings.
  • Client — the website that draws the chart.
  • Server — receives readings from your phone and saves them.
  • Notify for Mi Band — reads the heart rate from the band.
  • Tasker — forwards each reading to the server.

Backend setup

  1. Get your MongoDB URI, it should look something like this: mongodb+srv://<username>:<password>@xxx.xxxxx.mongodb.net/<database>?retryWrites=true&w=majority
  2. Deploy the server and start it with npm start.

Frontend setup

  1. Rename .env.template to .env.
  2. Point it at your server: NEXT_PUBLIC_SERVER_URI=https://your_servers.uri.
  3. Build and deploy.

Phone setup

Tested with a Mi Band 4. This part only works on Android.

  1. Set up your Mi Band in Notify for Mi Band.
  2. Create a new profile in Tasker.
  3. As the Event/Trigger, pick Intent Received and type com.mc.miband.heartRateGot.
  4. Create a Task:
    1. Variable Set: Name %heartRate To %value.
    2. HTTP Post:
      • Server:Port = Your server's URL.
      • Path = /send.
      • Data / File = hr=%heartRate.
      • Content Type = application/x-www-form-urlencoded.

How does this work?

Every time the Mi Band takes a heart rate reading, Notify for Mi Band broadcasts it as an intent, which triggers the Tasker profile. Tasker then sends an HTTP POST request to the server, which stores the value along with the timestamp (Epoch) in MongoDB.

When you open the website, it asks the server for your readings and draws the chart from whatever has been collected. That's the whole loop — band to phone, phone to server, server to chart.