Solution to track your google home alarms and timers and trigger different home assistant events

@skank @ddjj767

I wouldn’t count on Google bringing back the unauthenticated local API. It is possible to get the API to work, but it’s gonna be a bit more of a hassle than it was. Unfortunately it will likely stay like this.

Since this is a hard thing to integrate natively in homeassistant, I think the script above (or a similar workaround) provides a nice solution. Feel free to pm if you need help setting it up!

Please update the OP to reflect current status.

Cheers, Richard

Pitty this is closed off I have just decided I wanted this myself! Find it annoying that I set a timer in the kitchen for dinner and it doesn’t play on the others around the house so thought use HASS to detect next timer and announce around the house.

@chvancooten i’m in desperate need to get it to work, but it sounds so hard to get it working, and will this stay working?

@skank
It’s not too hard to get it to work, provided you can have access to a machine (preferably Linux) where you can set up the script to run as a cronjob. This will automatically take care of periodically pushing the tokens into your Hass, where you can use them. It does require some setting up since there’s some dependencies, but overall it’s doable.

Willing to help me with that?
I’m running HA OS on a raspberry pi
so thats linux… ur dutch btw? might be easier since i’m dutch

Maybe its possible to use a shell command to run it and use an automation to trigger it?
see How to execute a bash script time-based (weekly)?

Still help would be needed

I’m guessing (didn’t try) that this is not going to work on HassOS, as you need full shell access and you also need to run some python dependencies. You could run it on another machine and push the retrieved tokens to Hass using the api, though, adjusting the script for that should be easy enough!

That it should run on the same machine :frowning: guess a no go then :frowning:

I manage to draft a little python package that is extracting google devices’ tokens that can be used for REST requests to local google assistant devices. If there will be interest I’ll try to find some time to automate it in Home Assistant, so it will periodically fetch those tokens, so they could be used inside HA.

See the https://github.com/leikoilja/glocaltokens on how to get local tokens.

And https://rithvikvibhu.github.io/GHLocalApi/ for how to use these tokens for manipulating your google devices.

2 Likes

My needs were pretty basic, but rithvikvibhu’s token extract prog + the shell script from @chvancooten (for sending the extracted token to HA) gave me what I need:

2 Likes

That would be lovely!
I’m still in desperate need to be able to do automations in HA based on the alarms in google hub.
For now , the only thing possible is what happens in this thread :frowning:

So yeah, interested a lot here ! Although i have no skill or understanding to do or help smth
Running hass OS
Edit: would it be available via an addon? Would love that.

I was thinking of implementing it using AppDaemon and making it available as a backend integration via HACS(if someone has a better idea - I’m all ears). Then it would be easier to maintain and hopefully more useful for a wider audience. I think that integration is going to require a google login/password or master token, then it will be fetching local-authentication-token for each of google devices and fetch the assistant’s alarms and timers.

I will try to implement some beta version in January and will post it here once something is ready to be tested :slight_smile:

5 Likes

Cool thx
I already have hacs so no problem to do it there

How is it going?

Hi everyone.

I am very interested in a solution for this and have for a while tried to do it myself. Being a nerd but no programmer, i have no clue as to how to continue. I have successfully done all the steps but need a way to combine it into a single script which can be run.

You need 3 (2) tokens in order to make requests.

First you can use this link to get a Python script which can fetch the first authentication key. You need to input google authentication / or create an app with password in order to run this. When you run the script, you will also get a Master token (Long lived) which can be used instead of the google authentication.

This script also fetches an Access Token (short lived) which can be used to get the final get the final Local Authorization Token (Very short lived).

To get the Authorization Token, this command can be run.

./grpcurl -H 'authorization: Bearer ya29.*Access Token*' \
  -import-path /home/ollioddi/google/internal/home/foyer/ \
  -proto /home/ollioddi/google/internal/home/foyer/v1.proto \
  googlehomefoyer-pa.googleapis.com:443 \
  google.internal.home.foyer.v1.StructuresService/GetHomeGraph | jq '.home.devices[] | {deviceName, localAuthToken}'

This returns a list of available Google Home devices and their Local Authorization Token in the following format.

{
  "deviceName": "Oliver's Mini",
  "localAuthToken": "*Token here*"
}

And the last request

curl -H "cast-local-authorization-token: *Authorization Token*" --verbose --insecure https://192.168.1.xxx:8443/setup/assistant/alarms

This will then finally get the data.

{"alarm":[{"fire_time":1.6070628e+12,"id":"alarm/e5f4d82f-1650-4506-8f40-2fbdb56062bf","recurrence":[1,2,3,4,5],"status":1,"time_pattern":{"hour":7,"minute":20,"second":0}}],"timer":[]}

I cannot figure out how to make a single script that passes these values and does the whole loop in order to get the data.

The most important thing to me would to get the simple alarm time. If possible, it would be awesome to get the dates and possible even make a custom card since we can tell what day of the week that the alarm fires.

Hopefully this inspires someone to help. I would gladly test it out.

This was mostly made to show an example of what is necessary and what data it returns. Hope it helps!

1 Like

Nice!
I did not have the patience to do all that so I opted to build a timer function in HA that I activate using Google Home and IFTTT.
It actually works much better than the timer function in Google Home devices.
My timer does not have the loud obnoxious ring tone at the end that is hard to turn off and never stops if you don’t tell it to stop.

But that is nice to see how to do it.
Perhaps I will give it a go now that there is clear instructions like this

Is there anything else you can get from this API?

Yes!

There is multiple things that you can get from this api. From gathering data to editing.

Read more on the documentation https://rithvikvibhu.github.io/GHLocalApi/.

I use a Lenovo Smart Clock, intended as a replacement for my phone at bedtime.

Your solution sounds good enough, but i wanted to interface with a display since the voice part is hit and miss in my native language.

The only thing i needed was to combine it with Home Assistant.

Does your way differ from what @Ilja_Leiko will make?
@Ilja_Leiko any update?

The basics are the same i guess, but my hope was that it could maybe inspire someone else to help contribute who actually knows how to code. If i can figure it out i suppose a programmer also could.

Furthermore an example might be helpful since I don’t know if every device return the same data.

I was currently busy with something else, but will have a look at this closer to the end of the next week :slight_smile: will greatly appreciate any help testing it out once I have something. Will keep you updated here