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.
Full Stack Developer2 min read
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
- Get your MongoDB URI, it should look something like this:
mongodb+srv://<username>:<password>@xxx.xxxxx.mongodb.net/<database>?retryWrites=true&w=majority - Deploy the server and start it with
npm start.
Frontend setup
- Rename
.env.templateto.env. - Point it at your server:
NEXT_PUBLIC_SERVER_URI=https://your_servers.uri. - Build and deploy.
Phone setup
Tested with a Mi Band 4. This part only works on Android.
- Set up your Mi Band in Notify for Mi Band.
- Create a new profile in Tasker.
- As the Event/Trigger, pick Intent Received and type
com.mc.miband.heartRateGot. - Create a Task:
- Variable Set: Name
%heartRateTo%value. - HTTP Post:
- Server:Port = Your server's URL.
- Path =
/send. - Data / File =
hr=%heartRate. - Content Type =
application/x-www-form-urlencoded.
- Variable Set: Name
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.