Hikconnect, Hikvision Integration and Hangup

I have a Hikvision DS-KH6320-TE1 indoor unit (non-WiFi version) installed in the apartment I recently purchased. This unit is connected to an unknown model of the main gate lock. Additionally, I’ve equipped the exterior of my apartment door with a DS-KD8003-IME1, which is connected to the aforementioned indoor unit.

Many users of the DS-KH6320-TE1 are already familiar with its functionality: when a call comes in, it requires manual disconnection or hanging up. Failing to do so will result in continuous ringing, followed by the system reverting to voice message mode. This happens even if you’ve already opened the door since the system lacks the ability to detect whether the door has been opened.

Given that the indoor unit operates on a separate network, direct connection is impossible, leaving me to depend on the Hikconnect app and platform for its operation.

To assist with this, I’ve implemented an excellent custom integration by @tomasbedrich. This integration allows me to receive sensor updates whenever there’s a call, which I’ve converted to a vdp_ringing binary sensor using a template.

As for the disconnection process, I’ve utilized information from this forum to create a REST sensor connection for Hikconnect’s sessionId, as well as a REST_COMMAND to engage the hangup API. This setup allows me to seamlessly interact with the system and manage incoming calls as needed.

sensor:
  - platform: rest
    resource: https://api.hik-connect.com/v3/users/login/v2
    method: POST
    name: HikConnectSesion
    headers:
      Content-Type: "application/x-www-form-urlencoded"
      clientType: "55"
      lang: "en-US"
      featureCode: "deadbeef"
      Content-Length: "77"
    payload: !secret hikconnect_payload
    value_template: "{{ value_json.loginUser.username }}"
    json_attributes_path: "$.loginSession"
    json_attributes:
    - sessionId

For hikconnect_payload, it should be in format of
account=<URL encoded username>&password=<urlencoded md5 hash of password>

rest_command:
  hikconnect_hangup:
    url: 'https://api.hik-connect.com/v3/devconfig/v1/call/{{ states("input_text.hikconnect_primary_device_serial") }}/operation?cmdId=3&handler=deadbeef'
    method: PUT
    headers:
      sessionId: '{{ state_attr("sensor.hikconnectsesion", "sessionId") }}'
      featureCode: 'deadbeef'
      clientType: '55'
      lang: 'en-US'

I’ve a Text helper named hikconnect_primary_device_serial to store the serial number of the device to hangup. You can get it from the Hikconnect integration.

Here is the automation.

alias: HikConnect - Hangup call when door is open.
description: ""
trigger:
  - platform: state
    entity_id:
      - input_boolean.main_door
    to: "on"
    for:
      hours: 0
      minutes: 0
      seconds: 1
condition: []
action:
  - service: rest_command.hikconnect_hangup
    data: {}
mode: single

Thnx for sharing this info! usefull indeed for others, but i think Tomas will integrate those commands too in hikconnect platform…

I have DS-KH6320-TE1 unlike DS-KH6320-WTE1 which comes with the WiFi that one can use to connect to their home network.

Also, I’ve raised a PR with Thomas’ hikconnect python module to add hangup functionality after which we can add it to home assistant integration as a service.

That’s cool!! The hikconnect platform also supports sending ISAPI command, if your indoor panel uses scenes and alarm states, you can also create commands for those…

Of you are busy with PR, also submit a PR for the ‘reject’ command, that’s also very useful…

For example, if you have something like a zigbee open/close contact sensor at the door, and you open door manually you can reject the call, so indoor/mobile stops ringing

I posted example here:

Maybe with ISAPI, there is way to get the streaming live video from the outdoor station

@pergola.fabio I am using the hangup command to reject calls whenever I open the door similar to your recommendation. Except for the reasons best known to my old self, I’m still using my Echo Studio as a ZigBee proxy, so when a door opens, it triggers a boolean on HA, which starts the call cancellation.

As for other commands, I’m yet to test other cmdId values so that I can translate them to commands in hikconnect.

Yes. I’ve tested ISAPI through Hikconnect with Postman and I’m able to get a response for a simple capabilities call to GET /ISAPI/VideoIntercom/capabilities.

So will also look into that.

Thanks.

ah, ok but i believe “hangup” only works if the call was answered? The command “reject” cancels/aborts the call before answering, making all devices stop ringing

If ISAPI works, you can also send the callsignal ISAPI command, you can find some below that i added in my addon… WHat i have in my addon, created a TEXT entity, when using the service “service: text.set_value” , i send like command “PUT /ISAPI/… payload”

so its one service that can be used to send ISAPI commands

HI @pergola.fabio

I tried to call ISAPI using POSTMAN. Unfortunately I don’t know how to do PUT/POST vis Hikvision ISAPI proxy (GET is working). I tried following command and the error message is attached.

curl --location 'https://api.hik-connect.com/v3/userdevices/v1/isapi' \
--header 'sessionId: ey......i49' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'apiKey=100044' \
--data-urlencode 'channelNo=1' \
--data-urlencode 'deviceSerial=Q0XXXX473' \
--data-urlencode 'apiData=PUT /ISAPI/VideoIntercom/callSignal?format=json
{"CallSignal":{"cmdType":"reject"}}'

And here is the response.

{
    "data": "{\n\t\"statusCode\":\t\"5\",\n\t\"statusString\":\t\"Invalid Format\",\n\t\"subStatusCode\":\t\"badURLFormat\",\n\t\"errorMsg\":\t\"\",\n\t\"errorCode\":\t1342177283\n}",
    "meta": {
        "code": 200,
        "message": "操作成功",
        "moreInfo": null
    }
}

Here is the properly formatted output of data

{
	"statusCode":	"5",
	"statusString":	"Invalid Format",
	"subStatusCode":	"badURLFormat",
	"errorMsg":	"",
	"errorCode":	1342177283
}

Hmm maybe it’s a “” “” issue in the Json and you need to slash them out? I never tried)used it anymore, cause I use local now…

This command worked for me before…
But the example was with an XML can you try that to send XML instead? Just drop the format=Json from the URL also


curl -X POST --header "sessionId: SESSIONID" --data "apiKey=100044&channelNo=1&deviceSerial=QXXXXXX&apiData=PUT /ISAPI/AccessControl/RemoteControl/door/1%0D%0A<RemoteControlDoor><cmd>open</cmd><channelNo>1</channelNo><controlType>monitor</controlType><password></password></RemoteControlDoor>" "https://apiieu.hik-connect.com/v3/userdevices/v1/isapi"