Skip to content

Mi-Band steps on node-RED Dashboard

Mi-Band 5
Smartphone: Nokia 5.3
OS on smartphone: Android 10
Apps on smartphone required: Gadgetbridge, FolderSync
Server: Raspberry Pi 4
OS: Raspbian GNU/Linux 10 (buster)
ioBroker: 4.0.10
node-red Adapter: 2.3.0
node-red version: 1.3.5

The idea was to display the steps recorded by the Mi-Band 5 on the node-RED Dashboard. The Mi-Band comes with a closed source App for the Smartphone that cant export data. Step one is to find an alternative to it. The App being used is gadgetbridge for Android. The App is not available on the PlayStore. To install it requires either the F-Droid “store” or it can be installed using the apk.

Step 2 to get the MiBand connected to the gadgetbridge requires a bit of effort, but is well documented here. This is essential to move on.

The result will be, that the MiBand is now connected to the gadgetbridge App.

2 settings on the gadgetbridge app are required:

  1. Auto fetch activity data including a setting of the Minimum time between fetches
  2. Auto export enabled including an export location and the “Export interval”

This set in motion will fetch the data from the device, and export to a sqlite Database.

Using the folder-sync app for Android the Database file can be copied over to a local PC/Server in regular intervals.

The initial idea was to use the sqlite Database file directly via a sqlite node on Node-RED. This failed due to the fact that the DB-file name never changes and Node-RED always uses the inital version of the DB-file.

Plan B required to first of all export the Data on the database to a csv file.

To do this an SQL-statement needs to be stored and excecuted on a regular basis. This sql code was stored in a file called steps_q.sql. It gets the steps recorded for the last 7 days.

,sum(schritte) as Schritte  

date(MB.TIMESTAMP, 'unixepoch') as Datum 
,sum(MB.STEPS) as Schritte  


group by MB.TIMESTAMP   


group by Datum  
order by Datum DESC  

To export this to a csv file the following sqlite3 statement can be used:

sqlite3 -header -csv /mnt/1TBTOSHIBA/files/transfer/miband/db < /mnt/1TBTOSHIBA/files/transfer/miband/steps_q.sql > /mnt/1TBTOSHIBA/files/transfer/miband/steps.csv

sqlite3 -header -csv is the command
/mnt/1TBTOSHIBA/files/transfer/miband/db is the sqlite Database
< /mnt/1TBTOSHIBA/files/transfer/miband/steps_q.sql is the SQL code stored in a file
>/mnt/1TBTOSHIBA/files/transfer/miband/steps.csv is the destination csv-file

The excecution of this file was set up as a cron job:

45 * * * * pi sqlite3 -header -csv /mnt/1TBTOSHIBA/files/transfer/miband/db < /mnt/1TBTOSHIBA/files/transfer/miband/steps_q.sql > /mnt/1TBTOSHIBA/files/transfer/miband/steps.csv

Every hour at the 45th minute the user “pi” exectues the statement and updates the csv file with the latest amount of steps.

The Node-RED flow after this is very simple: An inject that runs on an interval, the csv-file, the csv-node and the UI table export.

Result on the Node-RED Dashboard: