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

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

This is great! I’ll give it a shot and see how it goes. :smiley:

Update 2: Read up on where to place the ‘custom_components’-dir (under config), and now I see the same behaviour as islamek.

Was just testing to see if I can make it work, I got the integration called Google Home, but after clicking it the “Please wait while the integration is being installed” popup shows and just stays there.

Same issue here… I’m on the latest version of Home Assistant OS. This is what I’m seeing in the logs:

2021-02-13 21:34:11 ERROR (SyncWorker_6) [homeassistant.util.package] Unable to install package grpcio-tools: ERROR: Command errored out with exit status 1:
     command: /usr/local/bin/python3 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-ysur6iq4/grpcio-tools/setup.py'"'"'; __file__='"'"'/tmp/pip-install-ysur6iq4/grpcio-tools/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-yq1mef3f
         cwd: /tmp/pip-install-ysur6iq4/grpcio-tools/
    Complete output (11 lines):
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-install-ysur6iq4/grpcio-tools/setup.py", line 151, in <module>
        if check_linker_need_libatomic():
      File "/tmp/pip-install-ysur6iq4/grpcio-tools/setup.py", line 80, in check_linker_need_libatomic
        cpp_test = subprocess.Popen([cxx, '-x', 'c++', '-std=c++11', '-'],
      File "/usr/local/lib/python3.8/subprocess.py", line 854, in __init__
        self._execute_child(args, executable, preexec_fn, close_fds,
      File "/usr/local/lib/python3.8/subprocess.py", line 1702, in _execute_child
        raise child_exception_type(errno_num, err_msg, err_filename)
    FileNotFoundError: [Errno 2] No such file or directory: 'c++'
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
WARNING: You are using pip version 20.2.4; however, version 21.0.1 is available.
You should consider upgrading via the '/usr/local/bin/python3 -m pip install --upgrade pip' command.
2021-02-13 21:34:11 ERROR (MainThread) [aiohttp.server] Error handling request
1 Like

Hey all.
Just a little update on the progress.

Starting with the great news, the three of us, together with @DurgNomis-drol and @ArnyminerZ have joined forces to work on this together. We have pretty high ambitions on the integration, but it requires quite a bit of work before it works.

You can follow our progress or share some insights/ideas in our shared repo, however, it is still under active development. We are both refactoring and working on underlying python glocaltokens package as well as HACS integration that will enable lots of great Google Home features within Home Assistant.
If you are a developer - we would be happy you join us! :boom:

P.S. We’ll post some updates here, when there is something to play/test with.

8 Likes

Looking forward to trying this out

Hey hey :boom:

Soooo, after a few weeks of hard work, there is something finally out that can be tested and hopefully found useful :slight_smile:
Big thanks to all who contributed for putting much effort into making it work. :rocket:

Please see Google Home custom integration that implements a solution to track google home alarms and timers in a neat manner.
Also, check a UI custom card that @DurgNomis-drol has been working on to show timers in a beautiful way.

Drop a github :star: if you find it useful and please help to contribute with issues/PRs to make it even better.

Edit: If you encounter any unexpected behavior please open the corresponding issue in github

7 Likes