Automatically retrieving Google Home API keys into Home Assistant

Hi everyone!

A while ago Google suddenly closed off its “local” API for Google Home devices. This was very sad news for Home Assistant automations driven by input from these APIs, which provide a wealth of information for home automation!

Luckily, it is now possible again to access the Google Home API due to the excellent work of Rithvik Vibhu and others in figuring out and documenting the API. There is just one catch - the API now requires short-lived (1h) access tokens to be passed before they can be used. This is of course a big nuisance and breaks automations as much as closing the API off entirely did.

To ensure that the API can again be used within Home Assistant automations, I decided to create a script that automatically pulls the relevant authentication tokens and exposes them as entity attributes within Home Assistant. For reasons of laziness convenience, I created this script in Bash (for use within a cronjob). The relevant tokens are then pushed to Home Assistant attributes which can then be used within the templating system, again allowing for automatic requests to be made to the Google Home API! :partying_face:

The repo is available here (some documentation is included). Again, the code is not very pretty, but it works.

I hope it helps some people! Comments / issues / feature suggestions are more than welcome.

3 Likes

Great work!