Hik-Connect

Hi everyone,

thanks to this post + some additional reverse engineering on Hik-Connect app I created a Home Assistant integration for Hik-Connect cloud. Basically, if you are able to open your door using Hik-Connect app, it should be working with this integration too. There are no other features yet.

The target audience is people living in block of flats where other Hikvision devices (smart doorbells, recorders) are managed by someone else and you only have admin access to your video intercom device mounted in your flat.

Known compatible systems: home-assistant-hikconnect/COMPATIBILITY.md at main · tomasbedrich/home-assistant-hikconnect · GitHub


Example usage:

  1. Install the integration and login. The list of devices (locks) should appear in your Devices.
  2. Find a lock entity and click “Unlock”. That’s it.

Please report how it’s working for you, possible bugs, your video intercom types (to extend the compatibility list)… Thanks, looking forward for your feedback! :slight_smile:

6 Likes

Good also will be if you alsowill be add view from camera (video Intercom) and also support for second door(i have second door as Gateway)In android App i have available second door to open. I start test it with 1 generation Video Intercom : door station: DS-KV8102-IM and Indoor station DS-KH8301-WT.
DS-KV8102-IM (FW.1.5.1)
DS-KH8301-WT (FW.1.5.1)

I also has in HicConnect app my cameras and NVR and when i add this integration it also show me lock. device from cameras ? What is it ? Camera as lock.xxxxxxxx ?

I found some lock. device which maybe looks as second door. Create script but no open my second door(gateway).
This device looks like:
lock.c044xxxxx_c044xxxxx

and script looks like:

alias: Otwarcie bramy z domofonu
sequence:
  - service: lock.open
    target:
      entity_id: lock.c044xxxxx_c044xxxxx
mode: single

For first door entity looks as:

lock.c044xxxxx_main_1_1_1

For first door work s perfect. Open door no problem.

But second door no working.

Hi @pepeEL, first – thank you for fast feedback! Both here + GitHub issues and pull requests. :+1:

Then some explanation – the integration is based on assumption, that all devices connected to Hik-Connect has both lock + camera function available. This seems to be wrong assumption (based on your example) and we must fix it somehow. In other words: the first bugfix is not to report camera-only devices as locks.

The second bugfix is that you cannot open your second door. This is should be working, I am personally using the integration to open 5 different doors.

Third thing is a feature request – add live view from Hik-Connect connected cameras. I would love to implement it too, but I haven’t reverse-engineered the protocol yet (lacking time). Therefore this will be postponed for now.

Would you mind helping me with debugging on your side? I need you to add this to your Home Assistant config:

logger:
  logs:
    hikconnect: debug
    custom_components.hikconnect: debug

Please send me the logs so that I know the difference between your and mine setup. You can upload to GitHub Gist, elsewhere, or mail to [email protected]. Beware there are potentially sensitive info there: session_id, refresh_session_id + your intercom device ID + serial number.

great job!! :slight_smile:
i was playing with this too before, but didnt see any events for door open and stuff, only call events
do you see them?

btw, when i used this with fiddler, i needed to lookup the session id and some personal parameters… dont you need them?

Thanks. :slight_smile: It took me some time and playing to figure out what parameters are optional, whether they must be part of HTTP headers/cookies, how they behave when changed etc. so that I can only require username/password from Home Assistant user.

Door open API call is mentioned in the original thread, that was easy. What is worse, is the “ring” event (if we define “event” as something which is pushed from server to client). I have not found any such event yet – but I haven’t been looking for it either. :smiley: There is only get_call_status(...) API endpoint, but it would require status polling to deliver ring event to Home Assistant. I dislike this solution, therefore I postponed implementation of ring event until I have time to explore how Hik-Connect app handles it.

i used indeed the poll event

But I don’t use the hikconnect cloud anymore, I use the isapi…

But isn’t the SDK a ba better solution @tomasbedrich ?

It’s local , and many more feature and also documented

I would love to use local approach! But as noted on the top:

The target audience is people living in block of flats where other Hikvision devices (smart doorbells, recorders) are managed by someone else and you only have admin access to your video intercom device mounted in your flat.

In my case it means NVR, indoor stations and door stations are separated on the network layer and password protected. Our “group of flat owners” (Czech legal entity) hires a network administrator who maintains all the stuff as a paid service and guarantees they are working. So the only option remaining is to use Hik-Connect cloud.

oh ok :slight_smile:
too bad :slight_smile:

Hey @pepeEL – I have created GitHub issues for the bugs you mentioned:

+ a few other issues for feature requests: https://github.com/tomasbedrich/home-assistant-hikconnect/issues

Let’s please move the discussion to relevant GitHub issue, so that this topic is cleaner. :wink: Thanks once more for your feedback!

But how you show in Home Assistant second and next door ?
On email i send you logs debug…

For completeness I point to this https://github.com/CornerBit/HikSink

Tomas it is very good job and we waiting for more… One person which start create integration. Good JOB :slight_smile: I like it :slight_smile:

1 Like

@tomasbedrich

can you also have a look if you see events like “door opened”, or “badge swiped” ?

thnx in advance

After reboot my Home Assistant i have status red ? for entities…

In logs show this:

Logger: homeassistant.components.lock
Source: custom_components/hikconnect/lock.py:18
Integration: Zamek (documentation, issues)
First occurred: 13:12:22 (1 occurrences)
Last logged: 13:12:22

Error while setting up hikconnect platform for lock
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/httpx/_transports/default.py", line 61, in map_httpcore_exceptions
    yield
  File "/usr/local/lib/python3.9/site-packages/httpx/_transports/default.py", line 281, in handle_async_request
    ) = await self._pool.handle_async_request(
  File "/usr/local/lib/python3.9/site-packages/httpcore/_async/connection_pool.py", line 234, in handle_async_request
    response = await connection.handle_async_request(
  File "/usr/local/lib/python3.9/site-packages/httpcore/_async/connection.py", line 136, in handle_async_request
    self.socket = await self._open_socket(timeout)
  File "/usr/local/lib/python3.9/site-packages/httpcore/_async/connection.py", line 163, in _open_socket
    return await self._backend.open_tcp_stream(
  File "/usr/local/lib/python3.9/site-packages/httpcore/_backends/auto.py", line 44, in open_tcp_stream
    return await self.backend.open_tcp_stream(
  File "/usr/local/lib/python3.9/site-packages/httpcore/_backends/anyio.py", line 154, in open_tcp_stream
    stream = await TLSStream.wrap(
  File "/usr/local/lib/python3.9/contextlib.py", line 137, in __exit__
    self.gen.throw(typ, value, traceback)
  File "/usr/local/lib/python3.9/site-packages/httpcore/_exceptions.py", line 12, in map_exceptions
    raise to_exc(exc) from None
httpcore.ConnectTimeout

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 249, in _async_setup_platform
    await asyncio.shield(task)
  File "/config/custom_components/hikconnect/lock.py", line 18, in async_setup_entry
    await api.login(entry.data["username"], entry.data["password"])
  File "/usr/local/lib/python3.9/site-packages/hikconnect/api.py", line 57, in login
    res = await self.client.post(f"{self.BASE_URL}/v3/users/login/v2", data=data)
  File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 1825, in post
    return await self.request(
  File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 1494, in request
    response = await self.send(
  File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 1586, in send
    response = await self._send_handling_auth(
  File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 1616, in _send_handling_auth
    response = await self._send_handling_redirects(
  File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 1655, in _send_handling_redirects
    response = await self._send_single_request(request, timeout)
  File "/usr/local/lib/python3.9/site-packages/httpx/_client.py", line 1699, in _send_single_request
    ) = await transport.handle_async_request(
  File "/usr/local/lib/python3.9/site-packages/httpx/_transports/default.py", line 276, in handle_async_request
    (
  File "/usr/local/lib/python3.9/contextlib.py", line 137, in __exit__
    self.gen.throw(typ, value, traceback)
  File "/usr/local/lib/python3.9/site-packages/httpx/_transports/default.py", line 78, in map_httpcore_exceptions
    raise mapped_exc(message) from exc
httpx.ConnectTimeout

When i reload again Integration all start work ok. and status has no RED !

And maybe goos solution also will be as create addon to HA as for Dahua https://github.com/elad-bar/Hassio-addons
But it is also to think about it :slight_smile: Integration is also good and maybe when we create official (no beta) integration maybe good will be if add to official integration HA ( no by HACS).

I will take a look, but I am pessimistic in my setup (mentioned above) there will be any such event published from the indoor station through the Hik-Connect cloud.

Thanks for a report. Let’s discuss that in a GitHub issue which you created: