Custom component : Google Tasks (abandoned)

How would a condition se for a list that isn’t empty on tasks?

@BlueBlueBlob istthere a way to detect when a task is marked done?

Check the sensor (not binary one) : it displays not done tasks only.

You should use templating :
To know what task is done : https://www.home-assistant.io/docs/automation/templating/#trigger-state-object
And state.attributes ( https://www.home-assistant.io/docs/configuration/state_object/ )

Sorry I didn’t an example since I don’t use HA anymore.

Regards

Sad to hear that.

any news here? I get a error that since home assistant 2021.6 a version is needed. Any help on this?

you just need to add a version into the manifest file. I haven’t gotten the integration to work though. Anyone that has been able to get it to work?

Hey Friends,
Is there a ‘simple’ guide to getting Google Tasks to pop up in HA? I’ve read thru the thread and got lost a number of times. I don’t need any interactivity… just to list the current task list on my dashboard!

so looks like this github repro has been pulled. Was working fine until recently, now i get 404 when it tried to apply a HACS update :frowning:

I was interested in using this custom component so I have forked both the google tasks component and the lovelace card and have been playing around with them and have them both working at the moment.

I haven’t had time to update the configuration information yet so that part is still fairly manual but if anyone wants to use this feel free to use:

Probably easiest to install these by adding those custom repositories to HACS.

1 Like

I have been wanting to integrate GTasks with HA for a while. I have tried using @myntath custom component but I am seeing a ‘Config flow could not be loaded: undefined’ error when I get to the last step of adding the GTasks integration to Home Assistant after I have added the required config lines to my configuration.yaml file.

my log file has this entry:

Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/aiohttp/web_protocol.py", line 435, in _handle_request
    resp = await request_handler(request)
  File "/usr/local/lib/python3.10/site-packages/aiohttp/web_app.py", line 504, in _handle
    resp = await handler(request)
  File "/usr/local/lib/python3.10/site-packages/aiohttp/web_middlewares.py", line 117, in impl
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 60, in security_filter_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 100, in forwarded_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 28, in request_context_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 79, in ban_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 236, in auth_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 136, in handle
    result = await result
  File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 145, in post
    return await super().post(request)
  File "/usr/src/homeassistant/homeassistant/components/http/data_validator.py", line 62, in wrapper
    result = await method(view, request, *args, **kwargs)
  File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 70, in post
    result = await self._flow_mgr.async_init(
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 222, in async_init
    flow, result = await task
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 249, in _async_init
    result = await self._async_handle_step(flow, flow.init_step, data, init_done)
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 359, in _async_handle_step
    result: FlowResult = await getattr(flow, method)(user_input)
  File "/config/custom_components/gtasks/config_flow.py", line 42, in async_step_user
    return await self.async_step_init(user_input)
  File "/config/custom_components/gtasks/config_flow.py", line 38, in async_step_init
    return await self.async_step_link(user_input)
  File "/config/custom_components/gtasks/config_flow.py", line 45, in async_step_link
    url = self.hass.data[DOMAIN_DATA]["auth_url"]
KeyError: 'auth_url'

Looking at the python files, it looks like this dict key is supposed to be defined by a call to:

  gtasks_obj = Gtasks(open_browser=False, force_login=force_login, credentials_location=creds, two_steps=True)
  hass.data[DOMAIN_DATA]["auth_url"] = gtasks_obj.auth_url()

Not sure where to go from there, wondering if the gtasks2 module is even installed on my system in python.

Would be amazing to get this working, I used to use DAKboard for this but I stripped my DAKboard down to just the calendar part and included it in my Lovelace dashboard as an iframe so I could use that calendar but still have all of my home assistant sensors and data on my wall too.

I can try to help where I can but developing home assistant components is new ground for me.

If you set your credentials_location to an invalid value (i.e. anything but the path to a valid credentials file), you should get an error something like this:

No valid Credentials file found.
Traceback (most recent call last):
  File "/config/custom_components/gtasks/__init__.py", line 124, in setup
    gtasks_obj = Gtasks(open_browser=False, force_login=force_login, credentials_location=creds, two_steps=True)
  File "/usr/local/lib/python3.10/site-packages/gtasks2/gtasks2.py", line 42, in __init__
    self.load_credentials()
  File "/usr/local/lib/python3.10/site-packages/gtasks2/gtasks2.py", line 54, in load_credentials
    raise IOError('No valid Credentials file found.')
OSError: No valid Credentials file found.

If you see gtasks2 in the traceback like that, then you at least know that the gtasks2 module is installed…

Unfortunately for me, I am having trouble getting any further than this. I set up authentication using Service Account credentials, and I’m wondering whether I’ve set up the wrong credential type. Should I be using OAuth client ID credentials instead?

1 Like

Fiddled with this a bit more and found that I also get the KeyError: 'auth_url' error if I try to add the integration via the UI.
My understanding is that this isn’t necessary if you add gtasks: to your HA configuration (i.e. you must choose only one option for step 7).
@russ-sentient do you get anything else in the logs related to this integration when you restart HA?

Ok, figured out that for authentication I need an OAuth 2.0 Client ID, type ‘Desktop’.

Now when I try to add the integration via the UI, it shows me this popup:
Screen Shot 2022-07-18 at 9.09.07 PM

I presume this is also supposed to contain a link to retrieve an auth code, to paste into the input field.
If I leave it empty or enter random text, I get (invalid_grant) Malformed auth code. in the logs.

@myntath any ideas? If it’s possible to set it up without using the UI, is there something else I need to do? I’ve added this to my config:

gtasks:
  credentials_location: credentials.json
  default_list: 'My Tasks'
  force_login: false

and restarted HA but can’t see any gtasks entities.

You are almost there. If you check the home assistant logs you will get the authorisation link. When you complete that it will redirect you somewhere which will fail. However, in the url is the code you need to copy to that box.

I need to take some time to rewrite the whole auth flow I think. As aside from it being incredibly difficult currently it depends on gtasks2 which has been removed from GitHub and the authorisation expires with no simple way to renew.

1 Like

Ah haha finally got the sucker working, thank you!

In my config, I had the log setting set to ‘error’, so initially I couldn’t see the info logs which contain the auth link. Then I had some trouble with the redirect because I already had something running at localhost. However, I was able to check the request logs of that, got the auth code and now it’s working.

Depending on time and motivation, I might take a look at updating the auth flow, if you don’t get there first…

1 Like

Great, and yes if you have time would love to see a pull request for the auth flow. I have never worked on it before so after a quick look I shelved it until I also have the time and motivation.

I’ve made a few notes in the repo about getting this setup and I’ll add some of your experiences to it to help others.

1 Like

I have made a small update so that the config UI works again and prompts you with a link to the URL. This should make one step a little smoother at least.

2 Likes

Sorry, I have been extremely busy with work. I will give it another go. I have spent a few hours this morning trying to write a python google API auth in AppDaemon for HA. I get the link, paste it into a browser and can login to google and allow the access requested but I am having difficulty working out the Return URI so that google can send the auth code back to my app. It’s all new to me, so I guess a trial by fire.

Once I get some kind of link formed either with this code or my own, and can start polling my tasks, I could easily populate an entity with the data using a python script in either app daemon or pyscript. This auth stuff is difficult to me, and I don’t want to open up a port and setup a dns record unless I absolutely have to. It looks like the code runs client side, so a local address might work. Still not clear on it.

I was able to get this one to work! Had to scrape the code from the redirect url, might be possible to have the config text box accept the entire URL you copy from the browser, and then separate it out in the backend in python so it’s a little easier, but it works!

Thank you guys! Now that its working I’ll take a look into the code and see about simplifying.

Might be a silly question, but how do I add multiple lists from the same account?

Looking at the code, it looks to be for a single list only at this time. My use case requires multiple lists, one for each person as a Todo list, and some for Shopping Lists ( grocery, Lowes ). And more for hobby tasks etc. I’ll be trying to wrap my head around how to allow for multiple lists, possibly automatically pulled from the API or defined as a list in the config.

Now it appears like the integration has lost authorization.