Google Keep Custom Component

Google Keep is a big tool in my household, and I was incredibly annoyed when Google replaced Keep with Google Express as their default shopping list tool for Google Assistant. When this happened I wanted to restore the functionality through some roundabout DIY work, but no official API for Keep existed (nor does it still) and I wasn’t technically up to the task of writing one.

I recently found a great, unofficial Google Keep API that I encourage you to check-out and contribute to. I have used this API to create a simple service for Home Assistant that allows me to create and update Google Keep lists. I am currently using this service in HA with IFTTT to restore Google Keep functionality via Google Assistant. With it, I am able to have multiple, arbitrarily named shopping lists that my wife and I use.

14 Likes

I like where you are going with this custom implementation. I was wondering if there might be a way to retrieve the list to display on a tablet via this api.

Great! I’m using Keep for ages as my shopping list and was also very dissapointed to find out that it was not the default shopping list for my Google Home’s. Now my life has become much easier :wink:

Thanks for sharing!

I’m having trouble installing. I installed the gkeepapi but getting the following error:

2018-03-31 22:05:54 ERROR (MainThread) [homeassistant.loader] Error loading custom_components.google_keep. Make sure all dependencies are installed
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/loader.py", line 142, in get_component
    module = importlib.import_module(path)
  File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 673, in exec_module
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "/home/homeassistant/.homeassistant/custom_components/google_keep.py", line 19, in <module>
    import gkeepapi  # https://github.com/kiwiz/gkeepapi
ImportError: No module named 'gkeepapi'

Update:
I forgot to install it in the virtual environment. Now that I did, I got a new error which tells me I have to login through a browser?

2018-03-31 22:43:27 ERROR (MainThread) [homeassistant.setup] Error during setup of component google_keep
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.5/site-packages/homeassistant/setup.py", line 145, in _async_setup_component
    component.setup, hass, processed_config)
  File "/usr/lib/python3.5/asyncio/futures.py", line 380, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/lib/python3.5/asyncio/tasks.py", line 304, in _wakeup
    future.result()
  File "/usr/lib/python3.5/asyncio/futures.py", line 293, in result
    raise self._exception
  File "/usr/lib/python3.5/concurrent/futures/thread.py", line 55, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/home/homeassistant/.homeassistant/custom_components/google_keep.py", line 66, in setup
    login_success = keep.login(username, password)
  File "/srv/homeassistant/lib/python3.5/site-packages/gkeepapi/__init__.py", line 344, in login
    self._version = None
  File "/srv/homeassistant/lib/python3.5/site-packages/gkeepapi/__init__.py", line 48, in login
    self._email = None
gkeepapi.exception.LoginException: ('NeedsBrowser', 'To access your account, you must sign in on the web. Touch Next to start browser sign-in.')

The API does allow viewing the items of a particular list. What particular Home Assistant feature or use case are you thinking of?

I haven’t encountered this exception before. Are you able to import gkeepapi and login directly using python in a terminal? Try running these commands:

import gkeepapi
keep = gkeepapi.Keep()
success = keep.login('google_username', 'google_app_password')

I was thinking of the ability to show a list of items in the frontend kind of like what samsung does with their refrigerators. I see the api allows it, im just not any good with python at the moment. Ultimately I would like this list to display within hadashboard.

@aFrankLion this is great! Unfortunately this is not working for me. I have placed it in custom_components but after adding to my config I get the error [homeassistant.loader] Unable to find component google_keep. Is that not the right path?

@iantrich, thanks! Yes, the google_keep.py file should be placed in the custom_components folder in your home assistant configuration directory. Which version of homeassistant and Python are you running?

@aFrankLion
hass.io 0.67.1; python 3.5.3

thanks

@iantrich, I’m running homeassistant 0.67.1 and Python 3.6.4, but am unable to reproduce your error. I do not use hass.io, and am not sure if there are any breaking differences with my custom component and its installation.

Is there any additional information in the home-assistant.log file?

Also, please double-check the naming and permissions of the folders and files for the google_keep custom component.

Hi,

This sounds great but I am also having the same issue using Hass.io

I have added this to my configuration.yaml:

google_keep:
  username: "[email protected]"
  password: "xxxxxxx"
  list_name: "List"

And the google_keep.py file into the “custom_components” folder.

I am getting this error:

Testing configuration at /config
ERROR:homeassistant.loader:Error loading custom_components.google_keep. Make sure all dependencies are installed
Traceback (most recent call last):
File “/usr/lib/python3.6/site-packages/homeassistant/loader.py”, line 142, in get_component
module = importlib.import_module(path)
File “/usr/lib/python3.6/importlib/init.py”, line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File “”, line 994, in _gcd_import
File “”, line 971, in _find_and_load
File “”, line 955, in _find_and_load_unlocked
File “”, line 665, in _load_unlocked
File “”, line 678, in exec_module
File “”, line 219, in _call_with_frames_removed
File “/config/custom_components/google_keep.py”, line 19, in
import gkeepapi # https://github.com/kiwiz/gkeepapi
ModuleNotFoundError: No module named ‘gkeepapi’
ERROR:homeassistant.loader:Unable to find component google_keep
ERROR:homeassistant.setup:Setup failed for google_keep: Component not found.
Failed config
General Errors:
- Component not found: google_keep
- Setup failed for google_keep: Component not found.

Any ideas please?

It was permissions, thanks! But now it’s not loading gkeepapi module, on the fly, which I thought components do. Not sure how to use pip inside the hass.io container.

Use the custom dependencies add on to add that package. I’ve having some issues with it at the moment, where it is failing to connect to pypi, but I don’t think that is the add ons fault.

How do I go about doing that I added GitHub - aFrankLion/hass-google_keep: Custom component for Home Assistant to enable adding to and updating lists on Google Keep to the Repositories which added but nothing is showing to install.

Make your Custom Dependencies add-on config look like this:

{
  "pypi": [
    "gkeepapi"
  ],
  "apk": []
}

It will install into your deps directory in the config directory. I’m having some trouble with it right now though:

Retrying (Retry(total=4, connect=None, read=None, redirect=None)) after connection broken by 'NewConnectionError('<pip._vendor.requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x7f4df06ef470>: Failed to establish a new connection: [Errno -3] Try again',)': /simple/gkeepapi/

Did some digging and it turns out that the Docker container is not picking up a DNS server.

Not sure how yet to update the hass Docker startup so that it takes that argument. Hopefully you have better luck.

You might be able to have Home Assistant update your DNS server(s) on startup by using a shell_command:

shell_command:
  update_dns: >-
    echo -e "nameserver 1.1.1.1\nnameserver 1.0.0.1\n$(cat /etc/resolv.conf)" > /etc/resolv.conf

Just setup an automation to run this shell_command on startup. Please report back any success or failures.

Didn’t work, but I believe because of permissions to /etc/resolv.conf

I don’t think permissions will be an issue. Isn’t Home Assistant running as root user on the container?

You are correct. Regardless, the file changes are lost almost immediately if they are done. I manually updated the file and the changes were removed right away by systemd-resolved

hi, i too have issues with custom component
i installed home assistant on a raspian pi desktop, with python virtual setup

i have the errors below
also did an install of gkeepapi in my virtual setup like here :


so command was : ```
python3 -m pip install gkeepapi

it installed succesful

enabled google_keep in yaml config file
i have this error :

Tue Sep 04 2018 13:07:28 GMT+0200 (Central European Summer Time)

Unable to find component google_keep

&

Tue Sep 04 2018 13:07:28 GMT+0200 (Central European Summer Time)

Error loading custom_components.google_keep. Make sure all dependencies are installed
Traceback (most recent call last):
File “/srv/homeassistant/lib/python3.5/site-packages/homeassistant/loader.py”, line 94, in get_component
module = importlib.import_module(path)
File “/usr/lib/python3.5/importlib/init.py”, line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File “”, line 986, in _gcd_import
File “”, line 969, in _find_and_load
File “”, line 958, in _find_and_load_unlocked
File “”, line 673, in _load_unlocked
File “”, line 673, in exec_module
File “”, line 222, in _call_with_frames_removed
File “/home/pi/.homeassistant/custom_components/google_keep.py”, line 19, in
import gkeepapi # https://github.com/kiwiz/gkeepapi
ImportError: No module named ‘gkeepapi’

what todo next ?