Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How do I make a Fitbit dashboard in Python?

This is my GUI. My GUI app

Code for GUI (frontend):

from tkinter import *

from tk_tools import *

from tkinter.ttk import *

from tkinter import messagebox

root=Tk()

root.title('Fitbit Dashboard')

root.grid()

hr=RotaryScale(root, max_value=(220-age), unit=' BPM Heart rate')

steps=Gauge(root, max_value=10000, label='steps', unit='', red_low=20, yellow_low=30, red=100, yellow=100)

steps.grid(column=2, row=1)

cals=Gauge(root, max_value=2400, label='calories', unit='', red_low=20, yellow_low=30, red=100, yellow=100)

cals.grid(column=4, row=1)

dist=Gauge(root, max_value=5, label='distance', unit=' mi', red_low=20, yellow_low=30, red=100, yellow=100)

dist.grid(column=3, row=1)

actmins=Gauge(root, max_value=30, label='active minutes', unit='', red_low=20, yellow_low=30, red=100, yellow=100)

actmins.grid(column=5, row=1)

hr.grid(column=1, row=1)

hr.set_value(0) hrEntry=Spinbox(root, from_=0, to=23, state='readonly')

hrEntry.grid(column=7, row=1)

minEntry=Spinbox(root, from_=0, to=59, state='readonly')

minEntry.grid(column=8, row=1)

addbutton=Button(root, text='Add Alarm', command=add_alarm) a

ddbutton.grid(column=9, row=1)

lo_bat=Led(root, size=50) lo_bat.grid(column=4, row=2)

lo_bat.to_red(on=False)

Label(root, text='Battery low when lit').grid(column=4, row=3)

 

Pseudocode for backend:

def add_alarm():

     if all textboxes filled:

          add alarm and notify user via messagebox

     else:

          show error via messagebox

 

while True:

     set cals needle to cals burned

     set steps needle to steps

     set heart needle to current heart rate

     set active minutes needle to active minutes

     set distance needle to distance walked

     if battery<=17:

          turn on LED

     else:

          turn off LED

How do I turn the needles of the gauges on my GUI according to Fitbit stats, light the low battery indicator when the Fitbit's battery runs low, and add an alarm when pressing the "Add Alarm" button? In other words, how do I do my pseudocode in Python? The gauge's needles turn to show live data.

Best Answer
0 Votes
9 REPLIES 9

The Web API doesn't provide live data. It's only updated whenever the device syncs, so could be 20 minutes or so behind.

Peter McLennan
Gondwana Software
Best Answer
0 Votes

If not, how do I get the data (steps, calories, dist. active mins) from the last day and light the "Low Battery"  LED as mentioned?

Best Answer
0 Votes

You can probably get yesterday's data (so long as it's not just after midnight). If you want current (near-real-time) data, you'll need to use the device and companion APIs.

Peter McLennan
Gondwana Software
Best Answer
0 Votes

@Gondwana Then how do I light the "Battery Low" LED when my Alta HR battery runs low, and how do I capture the last synced data?

Best Answer
0 Votes

Can I light the "Low Battery" LED when the battery gets low?

Best Answer
0 Votes

Oh sorry, I didn't realise this was about Alta. You can't use device and companion APIs with Alta.

Peter McLennan
Gondwana Software
Best Answer
0 Votes

@Gondwana  What libraries/variables should I use to detect a low battery on my fitbit and light the "Low Battery" LED?

Best Answer
0 Votes

Check whether battery charge is exposed in the Web API. I suspect it isn't.

There may be Python libraries you could use to help with the Oauth flow. If so, they'll be mentioned in the Web API documentation site.

Peter McLennan
Gondwana Software
Best Answer
0 Votes

Hi @423536271827 

 

As @Gondwana described, you may use the Fitbit Web APIs to pull the device data after the device syncs with the mobile application.   This includes querying the activity data for the previous day.   We do not have a Web API to turn on a low battery light.   My understanding is low battery notifications are managed by the device itself.   However, you may use the Get Devices endpoint, https://dev.fitbit.com/build/reference/web-api/devices/#get-devices, to find out a device's battery life.  From there, you could send an additional notification through your mobile application recommending the user charge their device.

 

Gordon

Gordon Crenshaw
Senior Technical Solutions Consultant
Fitbit Partner Engineering & Web API Support | Google
Best Answer
0 Votes