<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Smart Life]]></title><description><![CDATA[Everything about IOT, docker, linux and a lot's of Home Assistant related stuff.]]></description><link>https://luisalves.hashnode.dev</link><image><url>https://cdn.hashnode.com/res/hashnode/image/upload/v1606950858324/irIGKDYs2.png</url><title>Smart Life</title><link>https://luisalves.hashnode.dev</link></image><generator>RSS for Node</generator><lastBuildDate>Tue, 01 Sep 2026 04:11:03 GMT</lastBuildDate><atom:link href="https://luisalves.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Feeding Google Home alarms into Home Assistant]]></title><description><![CDATA[The problem

I have a Lenovo Smart Clock in my bedroom which I use for setting alarms and interacting with Google Assistant and Home Assistant (HA) trough Nabu Casa. Great device for the money, but it has a problem.
I wanted to have a wake up routine...]]></description><link>https://luisalves.hashnode.dev/feeding-google-home-alarms-into-home-assistant</link><guid isPermaLink="true">https://luisalves.hashnode.dev/feeding-google-home-alarms-into-home-assistant</guid><category><![CDATA[smart home]]></category><category><![CDATA[hacking]]></category><category><![CDATA[iot]]></category><category><![CDATA[Google]]></category><dc:creator><![CDATA[Luís Alves]]></dc:creator><pubDate>Tue, 08 Dec 2020 15:26:40 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1607441191121/xgOnyi3Hy.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h1 id="the-problem">The problem</h1>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1607300274213/8FldY8uUT.jpeg" alt="IMG_20201206_155451_1.jpg" /></p>
<p>I have a Lenovo Smart Clock in my bedroom which I use for setting alarms and interacting with Google Assistant and Home Assistant (HA) trough Nabu Casa. Great device for the money, but it has a problem.</p>
<p>I wanted to have a wake up routine that triggers 15min before the alarm so that I can gently increase the brightness of my IKEA Smart bulbs until the alarm starts but had no way of feeding that alarm information into HA. Now I have!</p>
<h1 id="my-setup">My setup</h1>
<p>I'm currently using a Raspberry Pi 4 4GB running Raspbian lite 64-bit from a Crucial SSD as my host machine. A linux host is required for what I'm about to describe. Sadly, if you are using Hass.io this method won't work for you.</p>
<p>Inside the pi I'm using docker with the help of <a target="_blank" href="https://github.com/gcgarner/IOTstack">IOT Stack</a>, a great quick starter to have some of most used IOT docker containers up and running very fast. Home Assistant is running on top of docker with HA Supervised. Some of my important containers (NodeRed, deCONZ, Mosquitto, InfluxDB) are running outside of HA Supervised since I like to have the control over my most important applications. Additionally, it makes HA restarting faster as these containers keep running in the background. Maybe more about this in a future blog post!</p>
<h1 id="solution-overview">Solution overview</h1>
<blockquote>
<p>Note: This tutorial is based on Cas van Cooten <a target="_blank" href="https://github.com/chvancooten/homeassistant-googletokenretriever">Github</a>.</p>
</blockquote>
<p>To fetch the information from your Google Home devices, we will rely on Google Home Local API by <a target="_blank" href="https://rithvikvibhu.github.io/GHLocalApi/">Rithvik Vibhu</a>. This API will require local authorization tokens to get the information from your devices over HTTPS on port 8443 of your device.</p>
<p>Cas van Cooten (https://github.com/chvancooten/homeassistant-googletokenretriever) created a handy script which handles the creation of the tokens and pushes it to your HA instance. Let's check how to make it running.</p>
<h1 id="software-dependencies">Software dependencies</h1>
<p>To have the script running you will need  </p>
<ol>
<li><code>gpsoauth</code> python library</li>
<li>latest release of <code>grpcurl</code></li>
<li>Google Foyer proto files</li>
<li>python script to get tokens</li>
</ol>
<h3 id="1-python-dependencies">1. Python dependencies</h3>
<p>Install <code>gpsoauth</code> python library by running</p>
<pre><code><span class="hljs-attribute">pip3</span> install gpsoauth
</code></pre><p>If you don't have pip installed yet, install it by running </p>
<pre><code>sudo apt-<span class="hljs-keyword">get</span> install python3-pip
</code></pre><p>Reference:  <a target="_blank" href="https://gist.github.com/rithvikvibhu/952f83ea656c6782fbd0f1645059055d#file-readme-md">https://gist.github.com/rithvikvibhu/952f...</a> </p>
<h3 id="2-install-grpcurl">2. Install <code>grpcurl</code></h3>
<p>To run the scripts you will need a library called <code>grpcurl</code>. To install it, <code>golang</code> tool is required. There's a great tutorial <a target="_blank" href="https://linuxize.com/post/how-to-install-go-on-ubuntu-20-04/#1-downloading-the-go-tarball">here</a> on how to get it. </p>
<p>Once you have <code>go</code> commands available, install <code>grpcurl</code> with</p>
<pre><code><span class="hljs-keyword">go</span> get github.com/fullstorydev/grpcurl/...
<span class="hljs-keyword">go</span> install github.com/fullstorydev/grpcurl/cmd/grpcurl
</code></pre><p>In my case, here's my final folder structure after the last commands. The path to <code>grpcurl</code> will be <code>/home/pi/go/bin</code></p>
<pre><code>/home/pi
└──<span class="hljs-keyword">go</span>
│   └──bin
│       │   grpcurl
│   └──pkg
│   └──src
</code></pre><p>Reference: <a target="_blank" href="https://github.com/fullstorydev/grpcurl/releases">https://github.com/fullstorydev/grpcurl/releases</a></p>
<h3 id="3-google-foyer-proto-files">3. Google Foyer proto files</h3>
<p>Save to any directory you want the <a target="_blank" href="https://drive.google.com/drive/folders/1RvnN3y-G23pd2SWHmfV_7sef8QU5GNF4">proto file and it's folders</a>.  Preserve the folder structure otherwise it won't work. In my case I saved the folders to the directory <code>/home/pi/googlehome/</code>.</p>
<h3 id="4-tokens-script">4. Tokens script</h3>
<p>Get the <code>get_tokens.py</code> from <a target="_blank" href="https://gist.githubusercontent.com/rithvikvibhu/952f83ea656c6782fbd0f1645059055d/raw/00c724829a2786f97fc5251b5aaf998af9a93806/get_tokens.py">here</a> and save it to the directory you want. In my case it will be <code>/home/pi/googlehome/</code>.</p>
<p>Once saved, configure the script with your Google username and password. I've used <a target="_blank" href="https://support.google.com/accounts/answer/185833?hl=en">Google App Passwords</a> to generate a password because I have 2FA enabled in my Google account.</p>
<p>At this point you can run the script <code>python3 get_tokens.py</code> and check if it runs successfully. </p>
<h1 id="configuring-the-script">Configuring the script</h1>
<p>Now that all the dependencies are set, grab the latest <code>get_tokens.sh</code> script from <a target="_blank" href="https://raw.githubusercontent.com/chvancooten/homeassistant-googletokenretriever/master/get_tokens.sh">here</a> and configure the required variables. This bash script will create an authentication token using the python script and push it to HA.</p>
<p>Here's an example of how the configuration file looks like for me</p>
<pre><code><span class="hljs-comment"># Configure these variables</span>
<span class="hljs-attr">hassApi</span>=<span class="hljs-string">"http://localhost:8123/api"</span>
<span class="hljs-attr">hassApiToken</span>=your-long-key-from-homeassistant
<span class="hljs-attr">getTokenScriptPath</span>=<span class="hljs-string">"/home/pi/googlehome/get_tokens.py"</span>
<span class="hljs-attr">grpCurlPath</span>=<span class="hljs-string">"/home/pi/go/bin/grpcurl"</span>
<span class="hljs-attr">protoPath</span>=<span class="hljs-string">"/home/pi/googlehome"</span>
<span class="hljs-attr">targetDevices</span>=(<span class="hljs-string">"Clock"</span>)
<span class="hljs-attr">healthCheck</span>=<span class="hljs-literal">true</span>
<span class="hljs-attr">healthCheckUrl</span>=https://hc-ping.com/your-ping-will-explain-later
</code></pre><p>If you need to check your target device name, just go to Google Home app. If you want to fetch the alarms from more than one device you can use <code>targetDevices=("Bedroom clock 1" "Bedroom clock 2")</code> for example.</p>
<p>Run the script <code>./get_tokens.sh</code> to check if it's working correctly. After it runs you should already see <code>input_text.google_tokens</code> entity created in HA.</p>
<h1 id="schedule-a-timer">Schedule a timer</h1>
<p>The tokens expire after 1h. If you want to always have a working token, create a <code>cron</code> job to run the script at a given schedule. I only want to fetch the alarm data before my morning starts so I've set a <code>cron</code> job for 4am every day.</p>
<h1 id="configure-ha">Configure HA</h1>
<p>Now that the tokens are being generated, we can use the Google Home Local API to get the information we want using the authentication code.</p>
<p>I've tried two approaches: using a <code>command-line</code> entity in HA or by using Node-Red. The first method is documented in Cas van Cooten Github <a target="_blank" href="https://github.com/chvancooten/homeassistant-googletokenretriever#home-assistant-integration">here</a> so I'll show how I did it with Node-Red.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1607299796356/mbTjB-fd1.png" alt="node-red.PNG" /></p>
<p>The flow waits for a change in the token. When the token changes, it builds the header, runs <code>curl</code> command and it parses the data to be sent as a HA entity.</p>
<p>The flow code can be found on my Github  <a target="_blank" href="https://gist.github.com/luismalves/484ecedb8c98fecffa8a18fc29d0e218">here</a>.</p>
<h1 id="extra-lines">Extra lines</h1>
<p>If you want, you can have a service called healthchecks.io associated to the script to monitor if it's running. Just include both the ping id and the boolean in bash script variables. There's a healthchecksio custom component which you can use within Home Assistant.</p>
<p>Special thanks to: </p>
<ul>
<li>Cas van Cooten for  <a target="_blank" href="https://github.com/chvancooten/homeassistant-googletokenretriever">https://github.com/chvancooten/homeassistant-googletokenretriever</a> </li>
<li>Rithvik Vibhu for <a target="_blank" href="Link">https://rithvikvibhu.github.io/GHLocalApi/</a> </li>
</ul>
]]></content:encoded></item></channel></rss>