Integration with hikvision ax pro alarm system

Hi, I created scripts for the only purpose of resetting the arm/disarm switches off, after executing the operation:

alias: ax_arm_stay
sequence:
  - service: switch.turn_on
    target:
      entity_id: switch.ax_arm_home
  - service: switch.turn_off
    target:
      entity_id: switch.ax_arm_home
mode: single

Alternatively, you could create an automation, triggered by switch.ax_arm_home changing to ON, that sets it OFF after a second

1 Like

Hello,

Looks like your repo has been removed, could you repost the code please? I’m trying to achieve the same thing, adding my AX Pro setup to HA. Thanks.

Hi,

Looks like it doesn’t work the same way for AX PRO systems, too bad! But still thanks for the info. I think Emmet has some key information because he states “It works differently to the older axhub in that it needs more than just digest auth” but no more responses from him… @emmetdel care to join in again?

As other state, we tried your sensor code but when using developer tools and read the status of the sensor, we only get “friendly_name: axhubsys” and nothing more. In the logs we get:

Logger: homeassistant.components.template.template_entity
Source: components/template/template_entity.py:140
Integration: Template ([documentation](https://www.home-assistant.io/integrations/template), [issues](https://github.com/home-assistant/home-assistant/issues?q=is%3Aissue+is%3Aopen+label%3A%22integration%3A+template%22))
First occurred: 08:54:15 (4 occurrences)
Last logged: 08:54:15

* TemplateError('UndefinedError: None has no element 0') while processing template 'Template("{{ state_attr("sensor.axhubsys", "SubSysList")[0]["SubSys"]["arming"] }}")' for attribute '_attr_native_value' in entity 'sensor.axhubpanel'
* TemplateError('UndefinedError: None has no element 0') while processing template 'Template("{{ state_attr("sensor.axhubsys", "SubSysList")[0]["SubSys"]["arming"] }}")' for attribute 'arming' in entity 'sensor.axhubpanel'
* TemplateError('UndefinedError: None has no element 0') while processing template 'Template("{{ state_attr("sensor.axhubsys", "SubSysList")[0]["SubSys"]["id"] }}")' for attribute 'id' in entity 'sensor.axhubpanel'
* TemplateError('UndefinedError: None has no element 0') while processing template 'Template("{{ state_attr("sensor.axhubsys", "SubSysList")[0]["SubSys"]["alarm"] }}")' for attribute 'alarm' in entity 'sensor.axhubpanel'

EDIT:

I changed the code by removing the “value_template” attribute, this way I can see what goes wrong:

sensor:
  - platform: rest
    name: axhubsys
    resource: http://<ip>/ISAPI/SecurityCP/status/subSystems?format=json
    username: xxxxx
    password: yyyyy
    authentication: digest
    scan_interval: 10
    json_attributes:
        - SubSysList

This gives me in the developer tools: {“userCheck”: {“statusValue”: “401”, “statusString”: “Unauthorized”}}

I tried to create an operator user in the AX PRO hub but same result. Tried with admin, same result. But if I put http://ip/ISAPI/SecurityCP/status/subSystems?format=json in my browser, it works fine… But not from HA.

do you still got it working… ? any update?

1 Like

I hope this gets attention as I’m looking to install ax pro at my place soon. Already have cameras that I’d like to get integrated aswell

Hello. I so assume that you need to get an ID session. like here https://community.home-assistant.io/t/ds-kd8003-ds-kv8113-ds-kv8213-ds-kv6113-ds-kv8413-and-integration-hikvision-hikconnect-video-intercom-doorbell/ 238535/1133

if i log in to the axpro in my webbrowser and then test the sensor in developer it works but without login in i get 401 error. so it seems lite its the auth metod digest or basic that dont work, in hikvision kameras you kan change the auth metod but not in the alarm… so i think thats the problem but i cant find out what.
btw the axpro block the ip on my HA even if its the right user and password.

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…