Home

Awesome

Retrieving Google Home API keys into Home Assistant

This is a very quick and dirty Bash script to automatically pull relevant local authentication tokens for Google Home and load them into Home Assistant on a timer.

Based on great work by Rithvik Vibhu on figuring out the API and writing a script to retrieve the Google Master and Access tokens.

Requirements

Installation

Home Assistant Integration

The script will push the tokens for the specified devices as attributes to an entity input_text.google_tokens in Home Assistant. These attributes can now be retrieved via templating within Home Assistant. For example, here is the command_line sensor I am using to retrieve the timestamp of the next alarm from my Google Home device.

platform: command_line
command: "curl --insecure --header \"cast-local-authorization-token: {{ state_attr('input_text.google_tokens', 'token_my-google-home') }}\" https://my-google-home:8443/setup/assistant/alarms"
name: Next Alarm
value_template: >
  {% set alarms = value_json.alarm|sort(attribute='fire_time') %}
  {% if alarms[0] is defined %}
    {{ alarms[0].fire_time }}
  {% else %}
    None
  {% endif %}

If health checks are used, the healthchecksio custom component could be used to monitor the status of the script from within Home Assistant.