Sync Sleep Tracking with Google Fit

ehangurbuz

New member
Greetings Macrodroid Community.

please help me, im using google fit but it wont track sleep automatically so macrodroid can track sleep and send intent to fit but im not good at macrodroid.
I think about on this macro let me introduce you:


Detect sleep (15-85) con: light sensor(10lx) hr(21-12)
Cycle:
If yes start chrono and save "first start time"
If awake stop
If sleep again continue chrono
End of cycle

I dont know how recognize "last awake" and save it
And chrono "duration"
Send intent that 3 values to google fit

Bard ai says:

Choose "Custom Intent."
In the "Action" field, enter "com.google.android.apps.fitness.RECORD_SLEEP."
In the "Extras" field, enter the sleep time data in JSON format. For example, to record 8 hours of sleep starting at 10 PM:

Bard Ai says this is google fit JSON:

{
"startTimeMillis": 1709467200000,
"endTimeMillis": 1709553600000,
"durationMillis": 36000000
}


Best Regards.
Emirhan GÜRBÜZ
 

Dimlos

Well-known member
I'm sorry but I'm not going to be able to help you, please wait for someone else to come up with a better idea.
 

mapriex

Active member
what sleep tracker do you use for record? from where do you want to take the json data?
you know google fit is just a "data-collector", preparing, summarize and visualize data. google fit isn't able to track sleepsessions.

the ai explains how you can import the data to google fit not to generate data.
 

mapriex

Active member
sorry, macrodroid is an automation application - a software and not a device equipped with sensors that measures vital signs.

from which sensor do you want to get the data?
 

mapriex

Active member
ok, if i understand you right you want to use sleeping time thats predicted? can you provide some sleeping data from macrodroid?

my suggestion is to create timestamps when the app predicts sleeping and awaking times. then put the values to google fit and insert the values via a macrodroid automation(1 time per day).
it needs some math to split the date values that can actually inserted to google fit sleeping data.

basically:
you create variables(macrodroid), convert them as you needed(macrodroid) and then store(automated with eg. macrodroid) them in a database (google fit).

your request is using the saved data to 'sync' with google fit. so thats the question, how does your data look like? i know sleeping data can be personal, you can change the values you get, its just to prepare the macro for the right changes.
 

ehangurbuz

New member
My device is support it, Tried and works fine.
View attachment 8289
ok, if i understand you right you want to use sleeping time thats predicted? can you provide some sleeping data from macrodroid?

my suggestion is to create timestamps when the app predicts sleeping and awaking times. then put the values to google fit and insert the values via a macrodroid automation(1 time per day).
it needs some math to split the date values that can actually inserted to google fit sleeping data.

basically:
you create variables(macrodroid), convert them as you needed(macrodroid) and then store(automated with eg. macrodroid) them in a database (google fit).

your request is using the saved data to 'sync' with google fit. so thats the question, how does your data look like? i know sleeping data can be personal, you can change the values you get, its just to prepare the macro for the right changes.
After the sensor triggers, MD start the counter, the counter pauses when sleep pauses, continue when sleep contunuie and then pull the data from this counter needs to be shared with fit, but I don't know how to do it.
 

mapriex

Active member
> can you provide some sleeping data from macrodroid?

if this is the problem then share the macro pls.
After the sensor triggers, MD start the counter, the counter pauses when sleep pauses
do you save the counter data in a MD-Variable? so you can store it on MD while the sleepmacro finished? otherwise you can't really continue, if you don't "save" the data during the migration process to google fit (it might be possible, but it makes it a bit harder, working with variables is easier to transform).
 

ehangurbuz

New member
> can you provide some sleeping data from macrodroid?

if this is the problem then share the macro pls.

do you save the counter data in a MD-Variable? so you can store it on MD while the sleepmacro finished? otherwise you can't really continue, if you don't "save" the data during the migration process to google fit (it might be possible, but it makes it a bit harder, working with variables is easier to transform).
Thanks for info i hope someone can help
 

MacroDroidDev

Administrator
Staff member
I can't find any public information regarding com.google.android.apps.fitness.RECORD_SLEEP, so I suspect this is either some private functionality within the Google Fit app, or Bard is just completely making it up (This wouldn't be the first time I've seen completely made up stuff regarding Android from AI).

I'm not planning on adding Google Fit integration directly into MacroDroid as I've worked with it in the past and it proved to be a bureaucratic nightmare with various approval needed from Google and ever changing goalposts. No doubt Google will decide at some point in the future that it's not a core feature of the app and pull access (or make me jump through hoops to keep using the API).
 

ehangurbuz

New member
Here is the complete conversation:

Me: Send intent sleep track data from Macrodroid to Google Fit.

Bard: I can't directly send intents to other apps like Google Fit from MacroDroid through this interface. However, I can help you set up the intent yourself within MacroDroid. Here's how:

1. Open MacroDroid and create a new macro:

Tap the "+" button in the bottom right corner.
Select "Triggers" and choose the trigger that will initiate the sleep time intent. For example, you could use "Time" and set it to trigger at bedtime.
2. Add an "App Launch" action:

In the macro editing screen, tap the "+" button again.
Select "Actions" and then "App Launch."
Choose "Google Fit" as the app to launch.
3. Add a "Custom Intent" action (optional):

If you want to specify the sleep time data more precisely, you can add a "Custom Intent" action after "App Launch."
Tap the "+" button and select "Actions" again.
Choose "Custom Intent."
In the "Action" field, enter "com.google.android.apps.fitness.RECORD_SLEEP."
In the "Extras" field, enter the sleep time data in JSON format. For example, to record 8 hours of sleep starting at 10 PM:
{
"startTimeMillis": 1709467200000,
"endTimeMillis": 1709553600000,
"durationMillis": 36000000
}
4. Save the macro and run it:

Once you've configured the macro, tap the checkmark in the top right corner to save it.
You can then test the macro by running it manually or waiting for the trigger event you selected.
Additional notes:

Make sure you have MacroDroid Pro to access the "Custom Intent" action.
The JSON format for sleep time data might change in future versions of Google Fit. Check the official documentation for the latest format.
I hope this helps! Let me know if
you have any other questions.
 

Endercraft

Moderator (& bug finder :D)
"Bard" is speaking nonsense. This intent literally doesn't exist (the only mentions of it are on this very page and a reddit thread on the MacroDroid subreddit). "Make sure you have MacroDroid Pro to access the "Custom Intent" action." There is not even such a thing as a "custom intent" and intents are definitely not a paid feature.
 
Last edited:
Top