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

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

This sounds great! Very much similar to what I was thinking of implementing as an integration using AppDaemon and HACS.
Basically, It will regularly fetch local authentication tokens using the python package mentioned previously for all local Google devices and store those tokens as new sensors within HA.
Then, one can implement any type of REST sensor/switch simply using these token-sensors as authentication tokens in the request when communicating to Google assistant local devices.
I haven’t worked with AppDaemon yet, but fingers crossed this type of logic will work, so I ll be able to post some examples here as well :slight_smile:

Superb, willing to try and help testing

This is so nice!

I actually also made an succesful way of retrieving tokens some months back, but not in anyway as nice as your’s. But i got stuck with how to best implement timers and alarms into HA and haven’t worked on it since.

What is your plans regarding an integration?

Did not actually think of it as integrating it as sensors within homeassistant, but it actually sounds like a better solution.

This way, any of the API calls can be made without making the scripting “specific” as to only gathering one information. Basically give us the keys to the playground and do what we wish with the api.

I look forward to see what you can create and I will gladly test out as soon as possible.

Closing thought, would there be any way to indicate to homeassistant if a request failed? Toggle a boolean for example since alarms are “critical” for us who need automations in order to get out of bed.

2 Likes

I’m currently developing a Python Script for implementing all the different steps easier. You can find it on Github (https://github.com/ArnyminerZ/HomeAssistant-GoogleHome).
I’m still developing it, but the main functionality has already been done. Just the implementation with Home Assistant is missing, which I will look forward to implement right now.
There are detailed instructions on the repo’s README, but if you have any doubt ask me :slight_smile:
Hope it’s useful for anyone with the same needs :sweat_smile:

3 Likes

Why don’t you use home assistant cast then? If your intention is to use the touch screen interface? https://www.home-assistant.io/blog/2019/08/06/home-assistant-cast/

Because you cannot cast to the Lenovo Clock and I want to use the integrated alarm app which means i need the local api in order to get.

1 Like

Sounds promising, will be happy to test this on my lenovo smart alarm essential once the hassio integration is completed.

Keep up the great work and keep us posted!

I’ve kept up with the development. Right now it is in a kind of functional way, in the sense of that Home Assistant is loading the script and updating it every half an hour (as I have programmed).
During this progress, I’ve encountered some issues that I want to summarize, just in case anyone wants to use the script.

First of all, I have to thank leikoilja for the glocaltokens repo. Without it the gRPC load was being impossible for me.

Important notice: Right now I have encountered a problem with the script that kept logging me out from my Google Account on my Android phone when the script was ran. Doesn’t make any sense, so I’m working on it.

First of all, for running the script through Home Assistant I ended up using the sensors.yaml config file. Simply add the following to sensors.yaml:

  - platform: command_line
    command: /home/homeassistant/clock.sh
    name: alarms
    scan_interval: 30
    json_attributes:
      - alarm
      - timer
    value_template: "{{ value_json.alarm[0] }}"

and create a shell file /home/homeassistant/clock.sh. Inside of this file enter the launch command for the script (check repo’s README), in my case:

/srv/homeassistant/homeassistant_venv/bin/python3.8 /home/pi/HomeAssistant-GoogleHome/ghome_get.py -j -i 192.168.1.76 -n "Lenovo Smart Clock" -p "/assistant/alarms"

After that, everything should be working as planned. This is not by any means completely functional. It just loads at entity alarms, the JSON content of the first alarm on the Lenovo Smart Clock, but the parsing and automation must still be done sepparatelly.

Having said that, hope this works for you, and I will keep working to improve the system. Any suggestions and comments are welcome :smiley:.

1 Like

Home Assistant integration is right now functional. Only alarms are implemented, but further integration is planned. Take a look at my Github Repo.

1 Like

The development is in a good stage. I’ve implemented an entity for automating next alarm actions. This is, for example, opening the blinds 5 minutes before waking up, or turning on the coffee machine.

Take a look at the Github repo, or download the package directly.

Edit: Having read some concerns about the storage of the Google’s credentials, it’s getting baked an update which stores just an authorisation token, and not the full credentials.

Installation instructions

First of all, download the version 0.0.3 (the last one right now) with wget, for example, at the custom_components directory of your Home Assistant configuration folder (e.g. ~/.homeassistant/custom_components):

wget -O ~/.homeassistant/custom_components/googlehome.zip https://github.com/ArnyminerZ/HomeAssistant-GoogleHome/releases/download/ha-0.0.3/googlehome.zip

After that, create a googlehome directory, and decompress the file inside it:

cd ~/.homeassistant/custom_components
mkdir googlehome
unzip googlehome.zip -d googlehome

Now the hard work is done, just restart your Home Assistant instance, and configure your device.

Configuring a device

Configuring your Google Home is really easy, and can be done from the UI.
Simply go to your integrations page at Home Assistant (e.g. 192.168.1.1:8123/config/integrations), select the Add Integration button, and if you have installed the integration correctly, an integration called Google Home should appear; select it.
The following window should open:

auth

You should fill the fields with your Google’s username, and your password. This second one can be:

  1. Your Google’s Account password (if you don’t have 2FA enabled)
  2. An app password (if you have 2FA enabled). It can be generated from
    Google’s website.

Now it’s time to configure your device. First, access the Google Home app on your phone, and search for the desired
device, enter its configuration, and at the bottom of the page, the IP of the device should appear. Now, fill as
follows:

device

On IP Address, put the found address, on Name, the name you have set to your device in the Google Home app. In GET
path, choose one of the following:

  • next_alarm: The value of the entity will be the timestamp (UNIX) of the next alarm at the device.

Conclusion

There’s still a lot of work to do, and right now only the “next alarm” feature is ready, but I’m optimistic, and with some hard work, this could be functional in little time.

Contribution Needed (TODO)

  • Logo
  • Service for calling features like reboot.
  • More options for automation.
5 Likes