04-17-2021 23:16
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

04-17-2021 23:16
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
I am trying to add the new Fitbit sleep API to my app and I followed the exact instructions on the Fitbit API site (https://dev.fitbit.com/build/reference/device-api/sleep/).
I put this in my app:
import sleep from "sleep"
if (sleep) {
sleep.onchange = () => {
console.log(`User sleep state is: ${sleep!.state}`)
}
} else {
console.log("Sleep API not supported on this device, or no permission")
}
This does not work. The backtick in console.log is poorly placed and does not even build and when I remove the exclamation mark it keeps posting asleep when I am awake and wearing the watch. What is the problem?
Answered! Go to the Best Answer.

Accepted Solutions
04-30-2021 06:15
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


04-30-2021 06:15
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
You're right, that rogue exclamation mark is a TypeScript'ism, sorry.
The detection is a basic sleep classifier, but if you're moving it shouldn't think you're asleep. Are you sitting completely still when it reports you're asleep?

04-30-2021 06:15
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


04-30-2021 06:15
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
You're right, that rogue exclamation mark is a TypeScript'ism, sorry.
The detection is a basic sleep classifier, but if you're moving it shouldn't think you're asleep. Are you sitting completely still when it reports you're asleep?

05-06-2021 17:48
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

05-06-2021 17:48
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
It is just not super accurate. It is useful though as a point of reference among other variables. Thanks for your response Jon.

