Kuna Surveillance Camera Support

Good to hear that the timeout issues are gone; I think the problem is that the API, not being official, is just flaky, and so can be unpredictable in returning responses. The testing branch pretty much does away with timeouts except for loading the component and reauthorizing just so that the component not loading doesn’t hold up the loading of Home Assistant (auth requests timeout in 10s, which anecdotally from you three seems to be long enough to get a response back). Now other requests just return whenever they return (and the lack of any uncaught timeout errors tells us that they all eventually return).

I have more work to do on the underlying library and once that’s done will merge testing into master with a new release.

For now, new users should use the testing branch!

1 Like

Well my camera is back, didn’t do anything with the component except to update HA to 0.91.3 and after the restart, my camera was back online. I had done several restarts/reboots in the past with no success, running the regular branch.

I am unable to load this custom component.
I followed the directions in post 46.
When I restart HA, I get a notification saying the kuna component has an invalid config.
Prior to restarting HA, I checked the config file and all was good (green button).
My error logs:
2019-04-11 22:14:24 WARNING (MainThread) [homeassistant.loader] You are using a custom component for kuna which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you do experience issues with Home Assistant.
2019-04-11 22:14:24 WARNING (MainThread) [homeassistant.components.http] Configuring api_password via the http component has been deprecated. Use the legacy api password auth provider instead. For instructions, see https://www.home-assistant.io/docs/authentication/providers/#legacy-api-password
2019-04-11 22:14:24 WARNING (MainThread) [homeassistant.components.http.auth] legacy_api_password support has been enabled.
2019-04-11 22:14:34 WARNING (MainThread) [homeassistant.setup] Setup of recorder is taking over 10 seconds.
2019-04-11 22:14:51 ERROR (MainThread) [pykuna.kuna] Request to Kuna API timed out
2019-04-11 22:14:51 ERROR (MainThread) [custom_components.kuna] There was an error logging into Kuna: No Kuna API token response returned, check username and password.
2019-04-11 22:14:51 ERROR (MainThread) [homeassistant.setup] Setup failed for kuna: Component ‘kuna’ did not return boolean if setup was successful. Disabling component.

I think my issues are similar to @TarheelGrad1998’s post #64.
Unfortunately I haven’t the technical skills to figure the rest out.
I see that @marthocoo’s V7.1 was supposed to sync the python http client (whatever that means! :slight_smile:).
FYI, since this didn’t load for me when I tried 1 week ago, today I first deleted my kuna folder from custom component, and deleted my kuna info from my config file, restarted everything, then did a fresh install per instructions on Post #46 (Hassio on RPi3) . What I’m saying is that the git pull should be the most recent files as of tonight for this custom component.
Reviewing this thread, I believe I am in the same boat as @Nico74350’s post #80.
If I can’t get the regular component to load, do you think the testing one will?
Does the fact that I’m using the Pihole component have any bearing on this?
@TarheelGrad1998’s POst #74 says “Still wasn’t working for me today. Then I realized my work machine still had the Content-Type = application/json header. Once I added that to my home machine, I get the token immediately. Don’t use my home machine to code usually”. Is that incorporated into the newest version I pulled, or is that something I can / should do? If so, how?
Thanks for your help.

It sounds like you’re having the same problem as everyone else that is fixed in the testing branch. Unfortunately information in these posts tends to get out of date quickly when new versions are released so I would always recommend checking my latest posts rather than relying on info in old posts.

Delete the custom_components/kuna directory, then in the custom_components directory do:

git clone https://github.com/marthoc/kuna
cd kuna
git checkout testing

Then start/restart Home Assistant and all should be working. (If not, let me know.)

I tried this. Unfortunately I was unable to access HA at all after loading the testing script on my RPi3. I had to completely erase the Kuna folder using samba and reboot the pi using Putty in order for it (the Pi) to start back up, which it finally did.

The good news, however, is that within the Kuna app I no longer have problems. A restart of the modem and router fixed it, and now my live feed works like a charm. I just wish I could get it into home assistant.

I failed to mention after I initially scrubbed the kuna folder, then did the git clone, the command loaded fine. I then did the git checkout command, and there was an error. (a “fatal” error). I dont recall the specific wording but can get that to you later today. But if I then chose the kuna directory, then ran the git checkout testing, the command worked, but it would fry my front end of homeassistand that the webpage wouldnt load.

You’ll have to get me the error that comes up when you’re on the testing branch so that I can tell you what’s going wrong. Since it is working for others and for me I’m fairly confident it’s not a component issue. Maybe it’s an issue with your configuration.yaml? Hard to say.

@marthocoo - first off, I really appreciate you helping me and everyone else get this camera up and running!
So today I erased my kuna config, and directory, and then did the

This loaded in SSH / worked just fine for me today. No clue why it got hung up last night.
Next, without rebooting, I added the following to my config files:

kuna:
  email: [email protected]
  password: XXXXXXXXXX
  
downloader:
  download_dir: downloads

I then restarted my HA.
It restarted / loaded fine, but the Kuna component still fails to load.
The log files say this:
2019-04-14 21:16:21 WARNING (MainThread) [homeassistant.setup] Setup of kuna is taking over 10 seconds.
2019-04-14 21:16:22 ERROR (MainThread) [custom_components.kuna] Error while authenticating Kuna:
2019-04-14 21:16:22 ERROR (MainThread) [homeassistant.setup] Setup failed for kuna: Component failed to initialize.
Any other thoughts are appreciated.
Thanks!

Unfortunately in my haste to get a working test branch out I didn’t make the authentication method very robust - I just pushed a commit to testing that will actually raise the exception you’re encountering so that I can figure out how to diagnose and fix it. Please do:

cd custom_components/kuna
git pull

and restart Home Assistant. If the Kuna component doesn’t load you should get another error, please post it here.

@marthocoo So, I did the above. The kuna component still doesn’t load.
Here are the logs that have kuna in it:

2019-04-14 22:40:50 WARNING (MainThread) [homeassistant.loader] You are using a custom component for kuna which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you do experience issues with Home Assistant.
2019-04-14 22:41:12 WARNING (MainThread) [homeassistant.setup] Setup of kuna is taking over 10 seconds.
2019-04-14 22:41:12 ERROR (MainThread) [custom_components.kuna] Error while authenticating Kuna: 
2019-04-14 22:41:12 ERROR (MainThread) [homeassistant.setup] Error during setup of component kuna
Traceback (most recent call last):
  File "/config/custom_components/kuna/__init__.py", line 194, in authenticate
    raise err
  File "/config/custom_components/kuna/__init__.py", line 187, in authenticate
    await self.account.authenticate()
  File "/config/custom_components/kuna/pykuna/kuna.py", line 34, in authenticate
    result = await self._request("post", AUTH_ENDPOINT, json=json)
  File "/config/custom_components/kuna/pykuna/kuna.py", line 80, in _request
    allow_redirects=allow_redirects,
  File "/usr/local/lib/python3.7/site-packages/aiohttp/client.py", line 1005, in __aenter__
    self._resp = await self._coro
  File "/usr/local/lib/python3.7/site-packages/aiohttp/client.py", line 476, in _request
    timeout=real_timeout
  File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 522, in connect
    proto = await self._create_connection(req, traces, timeout)
  File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 854, in _create_connection
    req, traces, timeout)
  File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 974, in _create_direct_connection
    req=req, client_error=client_error)
  File "/usr/local/lib/python3.7/site-packages/aiohttp/connector.py", line 924, in _wrap_create_connection
    await self._loop.create_connection(*args, **kwargs))
  File "uvloop/loop.pyx", line 1869, in create_connection
  File "uvloop/loop.pyx", line 1858, in uvloop.loop.Loop.create_connection
concurrent.futures._base.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/homeassistant/setup.py", line 151, in _async_setup_component
    hass, processed_config)
  File "/config/custom_components/kuna/__init__.py", line 82, in async_setup
    if not await kuna.authenticate():
  File "/config/custom_components/kuna/__init__.py", line 195, in authenticate
    return False
  File "/usr/local/lib/python3.7/site-packages/async_timeout/__init__.py", line 55, in __aexit__
    self._do_exit(exc_type)
  File "/usr/local/lib/python3.7/site-packages/async_timeout/__init__.py", line 92, in _do_exit
    raise asyncio.TimeoutError
concurrent.futures._base.TimeoutError

Thanks for your help.

I have the same errors with timeouts. I turned off my router firewall and had the camera in hassio for a day and then after a reboot of hassio I haven’t been able to connect again. The app never times out and I’m using an Asus AC=RT-5300 with only the 2.4 radio enabled.

Are you using the testing branch?

I’ve wiped and installed a bunch of times. if git checkout testing means I’m using the testing branch, then yes. I think that the one time it worked being right after turning my firewall off was a coincidence. The comment about the differences between restarting and power cycling are interesting. Can that be explained?

Its working again. I turned on the 5Ghz radio in the router and viola! My experience doesn’t make much sense and I’d chock it up to a flaky API by kuna.

The ability to play sounds via the fixture would be great. I’d like to schedule some bird’s of prey audio to scare the crows away from my yard.

@marthocoo - any other thoughts regarding why I get those errors? I have deleted and reinstalled, and am using the testing branch. The component still won’t load.
I am running on Hassio on a RPi3, HA version. 0.90.2.
Should I change my config file and add some of the optional lines to it to change the settings? I haven’t even listed any of those options in my config.
I have Google Wifi, if that means anything.
Any thoughts are appreciated.
Thanks!

@Nico74350 and @Corey_Maxim were you able to get this to work?
Is anybody running this on hassio on the RPi3? If so, what version of HA are you using?
I am really bummed because I am unable to load the Kuna component!
Any help is appreciated.

Hello, I did have this working once awhile back (Hassio On a Rpi) but had some trouble after going to a newer version of hassio. I haven’t tried in a bit. (I’m in pest control and have limited time at the moment.) I’ll try to give it a go over the next few days and if I get it working again I’ll let you know. Don’t be bummed, we can get this working for ya! Oh and I do have google WiFi also not sure if it matters or not but we have the same exact setup! Keep your head up m8!

1 Like

@DKrics sorry for the delay on this, work has been busy. Can you try updating to the newest testing - if you’re already on the testing branch, change to the kuna directory and do git pull.

@marthocoo you are the man! It totally works. I am so psyched. Thank you so much. Sorry for getting anxious over the past week, but I felt like for some reason I was the only guy who couldn’t get this working! I appreciate your time and skills. Thanks again.