Integration with hikvision ax pro alarm system

It certainly has to do something with the authentication method but in the ISAPI manuals from Hikvision there is nothing about AX PRO, they aren’t updated yet, so no idea what needs to be changed to make ISAPI calls work without first authenticating in the browser.

I have made a “HA” user in my AXhub with operator privileges. I had some problems login in with my admin credentials.

But I have DS-PHA64-P2 hub and it works great with @andcarbo scripts. Only I hope that he finds “alarm triggered” report and maybe even some zones. :sweat_smile:

Actually, I can share the code for the zones sensor:

       axhub1:
        friendly_name: "SENSOR NAME"
        value_template: '{{ state_attr("sensor.axhub", "AlarmHostStatus")["ZoneList"][0]["Zone"]["status"] }}'
        attribute_templates:
            id: '{{ state_attr("sensor.axhub", "AlarmHostStatus")["ZoneList"][0]["Zone"]["id"] }}'
            name: '{{ state_attr("sensor.axhub", "AlarmHostStatus")["ZoneList"][0]["Zone"]["name"] }}'
            tamperEvident: '{{ state_attr("sensor.axhub", "AlarmHostStatus")["ZoneList"][0]["Zone"]["tamperEvident"] }}'
            shielded: '{{ state_attr("sensor.axhub", "AlarmHostStatus")["ZoneList"][0]["Zone"]["shielded"] }}'
            bypassed: '{{ state_attr("sensor.axhub", "AlarmHostStatus")["ZoneList"][0]["Zone"]["bypassed"] }}'
            armed: '{{ state_attr("sensor.axhub", "AlarmHostStatus")["ZoneList"][0]["Zone"]["armed"] }}'
            isArming: '{{ state_attr("sensor.axhub", "AlarmHostStatus")["ZoneList"][0]["Zone"]["isArming"] }}'
            alarm: '{{ state_attr("sensor.axhub", "AlarmHostStatus")["ZoneList"][0]["Zone"]["alarm"] }}'
            charge: '{{ state_attr("sensor.axhub", "AlarmHostStatus")["ZoneList"][0]["Zone"]["charge"] }}'
            signal: '{{ state_attr("sensor.axhub", "AlarmHostStatus")["ZoneList"][0]["Zone"]["signal"] }}'

where axhub1 is the sensor name and [0] is the first zone, so you have to create multiple sensors (increasing [0] to [1] and so on - I’m a newbie, don’t know if there is any chance to use a FOR function in configuration)

1 Like

Somehow can not make this code pass configuration validation. :man_shrugging:

Try the commands first from a terminal wirh curl , then you can also change the auth method… Easier to troubleshoot…

So in that link posted above , from hikvision door intercom, I have attached an isapi zip file, it contains all pdf for all latest hardware

On first post there is an ISAPi zip file…
You can see the curl commands I used for hikvision door intercoms…

As latest hope, if you use hikconnect cloud , you can trace the commands from the hikconnect app, with an proxy tracer, and just simulate it with rest command in HA

Information from the manufacturer, in the ax pro series there is no access to the isapi, for security reasons. to control you need to use Hikpro connect. I’m exploring a stream from a mobile app using fiddler

yeah, i used fiddler too, but you need to remove the security from hikvision app first, otherwise you are not able to capture the https traffic, unless you are on android 6

пуе the string in fiddler apiData

POST /ISAPI/SecurityCP/status/host?format=json HTTP/1.1
Authorization: Digest username="admin", nonce="4567f56cf645f338dc2b403439a0eff7:54552352767", response="56739dd75876448717a2d0854df020f", UserType="Administrator"
UserType: Administrator

{
  "AlarmHostStatusCond" : {
    "communiStatus" : true,
    "subSys" : true,
    "hostStatus" : true,
    "battery" : true
  }
}

I run the request in Postman and I get an error

 "data": "HTTP/1.1 200 OK\r\nContent-Length: 141\r\n\r\n{ \"statusCode\": 5, \"statusString\": \"Invalid Format\", \"subStatusCode\": \"badJsonFormat\", \"errorCode\": 1342177282, \"errorMsg\": \"badJsonFormat\" }",
    "meta": {
        "code": 200,
        "message": "操作成功",
        "moreInfo": null
    }
}

how to set ApiDada parameter?

Hi, I found a lot of information on integration Hikvision on the website https://tpp.hikvision.com/. Registration takes a long time.

You can only join that site as an company, only ISAPi is there to find

I signed up and got access within a week

My code Python

def getHikProConnectToken():
 conn = http.client.HTTPSConnection("api.hik-proconnect.com")
 payload = json.dumps({
  "appKey": appKey,
  "secretKey": secretKey
 })
 headers = {
  'Content-Type': 'application/json'
 }
 conn.request("POST", "/api/hpcgw/v1/token/get", payload, headers)
 res = conn.getresponse()
 data = res.read().decode("utf-8")
 data = json.loads(data)
 data = data['data']['accessToken']
 return data
def getstatusSystem ():
 hikProToken = getHikProConnectToken()

 conn = http.client.HTTPSConnection("api.hik-proconnect.com")
 payload = ''
 headers = {
  'Accept': 'application/json',
  'X-Devserial': AXPro,
  'Authorization': f'Bearer {hikProToken}'
 }
 conn.request("GET", "/api/hpcgw/v1/device/transparent//ISAPI/SecurityCP/status/subSystems?format=json", payload,
              headers)
 res = conn.getresponse()
 data = res.read().decode("utf-8")
 data = json.loads(data)
 return data

Do you receive a long token then? Remember it’s oy valid for about 12 hours, you need to refresh it…

Can you also post your full code? I use it differently, I created an sensor in HA with scan interval 12 hours to receive the token… When I have the token, then I use rest commands

The token is valid for 7 days.
I have not done the integration of HA yet, I check the code in paycharm.
While I receive a token every time before sending a request.

def getstatusSystem ():
 hikProToken = getHikProConnectToken()

 conn = http.client.HTTPSConnection("api.hik-proconnect.com")

My code is divided into functions. what function to show you?
getstatusSystem ()
arm(ways)
disarmSystem() accepted via fiddler, can’t disarm if armed by another user
getStausZones()
getStatusRelay()
setStatusRelay() not checked, because the child’s computer is connected through the relay, and it is now turned on :slight_smile:

Ah, maybe it’s different, I don’t have an alarm, I have an hikvision door intercom :slight_smile:

I also have an intercom installed DS KH6320 + DS KV6113 and I want to make scene setting functions so that I can arm from the monitor.I also have an intercom installed and I want to make the functions of setting scenes so that I can arm from the monitor. did not find arming function in fiddler :slightly_smiling_face:

1 Like

Table A-31 GET /ISAPI/VideoIntercom/scene/nowMode

thats strange indeed :frowning:

Maybe you can wireshark your indoor panel to see the command that’s using?