Kuna Surveillance Camera Support

Looks good! You may need to make a folder for each of those serial number subdirs, not sure if the downloader component handles that automatically.

And, where you’re using the filename parameter, you may need to specify the extension: '{{ trigger.event.data.label}}.mp4'.

The downloader component automatically creates the subdir if it doesn’t exist. Good call on the extension, I’ll add that now.

I might change the folder name from SN to a friendly name through a template or with an automation per camera (with the SN as a condition on the trigger).

Would it be possible to add the camera name (as defined in home assistant) to the event?

Wow, this is superb! I’ll update today and report back.

I’m having problems getting it to fully load.

When I restart I get:
Request to Kuna API timed out
There was an error logging into Kuna: No Kuna API token response returned, check username and password.
Setup failed for kuna: Component ‘kuna’ did not return boolean if setup was successful. Disabling component.

Timeouts in Kuna for me are common, though. I’m not sure if there’s a way to fix that…my network is pretty good. Maybe they are throttling me?

Or it may be my network, since my ecobee is doing similar:
Error connecting to Ecobee. Possible connectivity outage.

Seems fairly unlikely that they are throttling you and more likely, given your ecobee issues also, that there’s something flaky with your internet connection? The underlying pykuna library specifies 3 seconds as a timeout value, and I can get a response from the API in less than a half a second for a normal request. I know you remarked before that you saw lots of timeouts in your log, but I can say that I’ve actually never seen a timeout in either use or testing.

I’d be interested to hear others’ experiences on this as well.

I think the best I can do at this point is to add the name of the camera as it’s known in the Kuna app. I’ll do that and release an update.

Well, I waited a bit and restarted, ecobee is back online but not the Kuna. I am able to hit it from the app though.

Do you have something I can ping or trace route, to try to troubleshoot?

Strange that it’s not coming back up, especially since it does seem to be working for others (rules out something I screwed up in the library at least). Out of interest, what version of HASS and python are you using? Do you have the Kuna app installed on an iPhone or Android?

You could use Postman to try to interact with the API directly. The auth url (that you seem to have trouble hitting) is at https://server.kunasystems.com/api/v1/account/auth. To obtain an auth token you need to make a POST request to that url with the json body:

{ "email": "YOUR_EMAIL", "password": "YOUR_PASSWORD" }

If that times out then there’s some issue with your connection to Kuna I think? You could also tracert that. If it works then I’ve got to dig deeper for the problem.

This is a bit mindblowing. When I use postman to POST to that URL, I get an immediate response of:

{
“detail”: “Method “GET” not allowed.”
}

Same as if I actually do a GET command. I tried from my work network also and get the same result.

For grins I also tried PUT and PATCH. From my home, I get HTML, core of which:

Page unavailable

Sorry but the requested page is unavailable due to a server hiccup.

Our engineers have been notified so do check back on us later.

However, from my work network I get similar to the GET but for actual corresponding method.

Weird that it works for you. Are you in US?

I am using the docker version of hass:
|python_version|3.7.2|
|version|0.90.1|

I’m in Canada, not USA. What’s odd is that it’s working from your app.

I think at this point it seems like it’s not related to the component…? Since the post request you are sending from postman should return a json response: {“token”:“longtokenstring”}.

Yeah, I’m fairly confident it’s not the component either. Just bummer that it’s not working for me, and apparently I’m the only one. That’s why I’m looking for regional differences or something, but I can’t imagine why CA would be different than US.

Well…some progress. I was missing the trailing slash:

https://server.kunasystems.com/api/v1/account/auth/

I posted that from my work network, I get a token returned. When I do it from my home network, I get the “Sorry but the requested page is unavailable due to a server hiccup.”

So I feel like they’ve done something specific to my IP, or something.

I’m getting the same ‘No Kuna API’ thing upon HA container restart that @TarheelGrad1998 is - image

Didn’t have the issue at all with v6. The component does however load without issue if I reboot the VM, which I guess completely destroys the homeassistant container

I’m starting to wonder if its related to the change from sync to async under the hood. After you “reboot the VM” does it work from then on?

I have myself experienced an issue where new dependencies for a custom component are sometimes not installed properly after a restart - though this still wouldn’t answer @TarheelGrad1998’s issue with not being able to get a token returned even from Postman. The strange thing is if you can’t use Postman, then the Kuna App shouldn’t work either as the API calls are the exact same. I’m boggled by this.

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.

Does the hass code add that header?

I may try to dig a bit myself later. I’m a MS developer but blind to python.

This could be it… I think that requests (the sync python http client) may add the content type automatically and so I never worried about setting it. I’ll add it to the library and release a new update later today.

I just uploaded v7.1 - can you try it and see if it resolves your issue?

Success! Updated, restarted, and everything came up the first time.

I did get a timeout when I click to view the larger camera image. Could that be another touchpoint?

Anyway, thanks for the help and patience. Keep up the good work!

Hi there!
Still having an issue when upgrading to the last version, same one than @HITChris.

*** Extract from log ***
Setup failed for kuna: Component ‘kuna’ did not return boolean if setup was successful. Disabling component.
18:57 setup.py (ERROR)
There was an error logging into Kuna: No Kuna API token response returned, check username and password.
18:57 custom_components/kuna/init.py (ERROR)
Request to Kuna API timed out
18:57 deps/lib/python3.7/site-packages/pykuna/kuna.py (ERROR)

Do I need to upgrade pykuna as well?
Thanks guys!

Can you try updating to the latest version of the component? The latest version of pykuna is specified in the latest version of the component.