This site has been closed. To suggest and vote on feature requests, go to forum.urbandroid.org.

Send awakenings and sleep phases to Google Fit

Currently when retrieving data from the google fit integration, only the simple "sleep" activity is provided (activity type 72 from here: https://developers.google.com/fit/rest/v1/reference/activity-types).

Google fit also has activity types that can be used to provide more full information: Light sleep (109), Deep sleep (110), REM sleep (111), Awake (during sleep cycle) (112)
(The REST API and the records internally use the integers, but
the Android API uses string constants:
https://developers.google.com/android/reference/com/google/android/gms/fitness/FitnessActivities)

It would be great if Sleep as Android could store this additional data so it can be used more broadly by other services. An example of a service that would benefit is Exist.io, which has planned Google Fit integration but requires data on phases and awakenings: https://changemap.co/hellocode/exist/task/1824-sleep-from-google-fit/

Thanks for your consideration!

3 votes
Vote
Sign in
Check!
(thinking…)
Reset
or sign in with
  • facebook
  • google
    Password icon
    Signed in as (Sign out)
    You have left! (?) (thinking…)
    Stephen Klancher shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →
    completed  ·  AdminPetr Nálevka (Developer, Urbandroid) responded  · 

    Hello Stephen, we are already storing these phases in Fit, Google Fit just does not view them in the client app. Why do you think they are not stored? Did you import any graph which was mssing this data? In this case can you please use menu – report a bug?

    5 comments

    Sign in
    Check!
    (thinking…)
    Reset
    or sign in with
    • facebook
    • google
      Password icon
      Signed in as (Sign out)
      Submitting...
      • Kevin Kaland commented  ·   ·  Flag as inappropriate

        Just got a MI Band 2, which works with Sleep as Android, and Sleep as Android added awake detection...so it should have the appropriate data at hand, I think, and I'd love to (fiiiiinally) see my sleep data in Exist. Anyone have any workarounds in the meantime?

      • Josh commented  ·   ·  Flag as inappropriate

        Verifying what Stephen has mentioned here, in all my tests of Sleep as Android data exported to Google Fit I have only ever seen a Sleep segment (activityType `72`). Never any breakdown.

      • Stephen Klancher commented  ·   ·  Flag as inappropriate

        Hi Petr,

        That makes sense, and I believe this means you must be doing something like this sample:
        https://developers.google.com/fit/android/using-sessions#insert_activity_segments

        I understand that the Android and REST APIs are different, but they pull from the same data, therefore we would expect to be able to get the data points within the activity segments (DataSet) from a few different functions. For each I tried with the both the raw and derived data sources for dataSourceId and got the same results (raw:com.google.activity.segment:com.urbandroid.sleep:, derived:com.google.activity.segment:com.urbandroid.sleep:session_activity_segment).

        https://developers.google.com/apis-explorer/#p/fitness/v1/fitness.users.dataSources.datasets.get

        Using the start and end time from the session in my previous comment results in datasetId = "1507618753457-1507649918228" and the result shows no data points:

        {
        "minStartTimeNs": "1507618753457",
        "maxEndTimeNs": "1507649918228",
        "dataSourceId": "raw:com.google.activity.segment:com.urbandroid.sleep:",
        "point": [
        ]
        }
        https://developers.google.com/apis-explorer/#p/fitness/v1/fitness.users.dataSources.dataPointChanges.list

        I don't know if initial adding of data points would show up as "changes", but you can see that this function also shows no data point changes for the whole data source:

        {
        "insertedDataPoint": [
        ],
        "deletedDataPoint": [
        ],
        "nextPageToken": "1507481487164",
        "dataSourceId": "raw:com.google.activity.segment:com.urbandroid.sleep:"
        }
        https://developers.google.com/apis-explorer/#p/fitness/v1/fitness.users.dataset.aggregate

        In this call I ask for an aggragate from a period of about two weeks, and it returns no data points.

        Request:

        {
        "aggregateBy": [
        {
        "dataSourceId": "raw:com.google.activity.segment:com.urbandroid.sleep:"
        }
        ],
        "endTimeMillis": "1508086759275",
        "startTimeMillis": "1507006759275"
        }
        Response:

        {
        "bucket": [
        {
        "startTimeMillis": "1507006759275",
        "endTimeMillis": "1508086759275",
        "dataset": [
        {
        "dataSourceId": "raw:com.google.activity.segment:com.urbandroid.sleep:",
        "point": [
        ]
        }
        ]
        }
        ]
        }

        Can you confirm whether you see data points by trying the same steps? If you do then maybe there is a problem with my Google Fit account, or Sleep As Android on my particular phone. If you don't then either the data isn't being written correctly from Sleep As Android, or Google has a bug where data written from Android is not accessible via REST (seems unlikely, but maybe!).

        Thanks,
        Stephen

      • AdminPetr Nálevka (Developer, Urbandroid) commented  ·   ·  Flag as inappropriate

        +Stephen there is a one sleep session for the entire sleep tracking, but this contains associated segments which the various activity types like deep / light sleep, awake etc.. We did not work with the rest API (only the Android API) so I leave this to you, but you would probably need a second request the get the segments..

      • Stephen Klancher commented  ·   ·  Flag as inappropriate

        Hi Petr, I sent this via the report a bug feature at your request, but I will add it here too for completeness:

        Using the google API explorer go to the fitness API and get the list of sessions. This only works for the account you are logged in as (userId=me).
        https://developers.google.com/apis-explorer/#p/fitness/v1/fitness.users.sessions.list

        Of the 313 records returned for me, all sessions returned look like the below example, which only includes activity type 72, which is "Sleeping", but no occurances of the other items: Light sleep (109), Deep sleep (110), REM sleep (111), Awake (during sleep cycle) (112)
        Activity numbers are listed here: https://developers.google.com/fit/rest/v1/reference/activity-types

        {
        "id": "3e1e60711714132d43b9f387143354fb",
        "name": "Sleep",
        "startTimeMillis": "1507618753457",
        "endTimeMillis": "1507649918228",
        "modifiedTimeMillis": "1507651614758",
        "application": {
        "packageName": "com.urbandroid.sleep"
        },
        "activityType": 72
        },

      Sleep as Android

      Feedback and Knowledge Base