10-15-2017 08:14
10-15-2017 08:14
Hi Guys,
I'm working on my 1st watchface, so far it look great! Is there an example of getting the current battery charge percentage?
Thanks
Answered! Go to the Best Answer.
10-15-2017 14:38
10-15-2017 14:38
The Power API is coming in the next beta update, and it will be:
import { charger, battery } from "power"; console.log(Math.floor(battery.chargeLevel) + "%"); console.log("The charger " + (charger.connected ? "is" : "is not") + " connected");
10-15-2017 14:38
10-15-2017 14:38
The Power API is coming in the next beta update, and it will be:
import { charger, battery } from "power"; console.log(Math.floor(battery.chargeLevel) + "%"); console.log("The charger " + (charger.connected ? "is" : "is not") + " connected");
10-15-2017 14:42
10-15-2017 14:42
Oh that makes sense. I was under the impression that it was already implemented. May I ask approximately when the update regarding the Power API will be released?
10-15-2017 21:06
10-15-2017 21:06
@JonFitbit Thanks
04-03-2018 08:07
04-03-2018 08:07
Tried this on my ionic v27.32.4.19 but get NaN as chargeLevel.
Got any hints?
04-03-2018 08:55
04-03-2018 08:55
Can you provide the relevant code so we can look at it?
04-03-2018 10:47
04-03-2018 10:47
Found the error. My variable was named battery.
11-04-2018 17:54
11-04-2018 17:54
Mine is Ionic
I have recently started using the Fitbit Studio to create my own personal watch face, it was good fun and have learnt a lot.
Regarding the battery indicator using either a progress bar or simply displaying the charge level in text format or a radial ring or whatever you may think of, the usual answer one would get from the Fitbit Developer page regarding the Power API (https://dev.fitbit.com/build/reference/device-api/power/) or from someone who pasted fragment of their own code, there is one important point I have figured out and not mentioned by many "solved solution".
This leads to a problem many have encountered, that is the battery level seem not able to update itself in the watch face, but when swipe up to see the status check or to an app then back to the watch face, the battery level is updated.
The important point I figured out is where you put the following code in the "index.js", assuming to use a variable named "battLevel" (the the following code is to insert the actual battery level):
battLevel = battery.chargeLevel;
Now, the question is, at what location this "battery.chargeLevel" should be put at.
I have seen codes putting this line as part of the initial lines of "index.js" way before any call for any functions:
let ......
let ......
let batLevel = battery.chargeLevel;
If this is done so, the reading of the battery level is fed into the "battLevel" when the page "index.js" is called (at start up of the watch, swipe back from other pages etc.), and that's it, the reading will not change no matter how many times you look at the watch face, because if not going to other pages (including the swipe up) then back, I found the only parameters that keep updating the watch face are either:
clock.ontick = function(evt) {}
or
setInterval(function, 1000);
Then I realized the idea place to put "battery.chargeLevel" should be within the clock.ontick = function(evt) {}, also wrap it inside a condition, only perform the battery level update when the screen is put on:
function updateBattery() {
...
...
myBattlvl = battery.chargeLevel;
...
...
if (display.on) {
update_battery_function();
}
}
That's what I do and so whenever I turn my wrist, the watch face shows up, the above code activates the battery level check and my battery indicator shows the actual battery level.