Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add COM1 and COM2 Relay Control for Indoor Station #25

Open
ukiews opened this issue Nov 21, 2024 · 14 comments
Open

Add COM1 and COM2 Relay Control for Indoor Station #25

ukiews opened this issue Nov 21, 2024 · 14 comments

Comments

@ukiews
Copy link

ukiews commented Nov 21, 2024

For Indoor Stations like the DS-KH6350 there are two relays on board (COM1 and COM2).
Page 10 here: https://assets.hikvision.com/prd/public/all/doc/m000056209/UD30790B-A_Network-Indoor-Station_Operation-Guide_V2.2.2_20240819.pdf

Could you please add these?

The plugin already pulls the paired door station locks from the indoor station, but adding the two relays would allow for full control.

IMG_5401

@ukiews
Copy link
Author

ukiews commented Dec 3, 2024

@judge any chance this could be added?

@judge
Copy link
Owner

judge commented Dec 4, 2024

Hello,
Currently I'm busy with life stuff, I'll check this soon, sorry about that!
In the meantime, could you please help me with the payload you receive from the station? I don't have these relays in my system so I cannot test it. There is a guide about how to send me the response: https://github.com/judge/homebridge-hikconnect/blob/main/DEBUGGING.md

@ukiews
Copy link
Author

ukiews commented Dec 4, 2024

Thank you for getting back.
Looks like Step 2 in Debugging instructions does not work.
Even though I am logged into Hik-Connect, the url kicks back a 401 error: "{"meta":{"code":401,"message":"Unauthorized"}}"
Do I need a developer account to accomplish this since the link is "api.hik-connect.com..."?

@ukiews
Copy link
Author

ukiews commented Dec 7, 2024

@judge I opened a dev account at tpp.hikvision.com, but I still get the same 401 error when clicking your link.

@judge
Copy link
Owner

judge commented Dec 8, 2024

I checked it as well and it seems the method I described in the docs is not working anymore. You need to craft the requests by hand. :( I'll publish a new version of the plugin to help with debugging, I have an idea.

@judge
Copy link
Owner

judge commented Dec 8, 2024

I published a new version with debug logging. Could you please follow the updated https://github.com/judge/homebridge-hikconnect/blob/main/DEBUGGING.md docs?

@ukiews
Copy link
Author

ukiews commented Dec 9, 2024

Log sent!
There seem to be nested arrays marked as '[Object]' that don't fully populate. Not sure if that is relevant.

@ukiews
Copy link
Author

ukiews commented Dec 11, 2024

@judge I was able to do a bit of reverse engineering by monitoring the traffic from my iPhone and the Hik-Connect app to control the Com1 port:

    "onUrl": {
        "url": "https://apiius.hik-connect.com/v3/userdevices/v1/isapi",
        "method": "POST",
        "headers": {
            "Content-Type": "application/x-www-form-urlencoded",
            "featureCode": "xxx",
            "appId": "NewHikConnect",
            "sessionId": "xxx"
        },
        "body": "apiData=PUT%20/ISAPI/SecurityCP/control/outputs/0?format%3Djson%0D%0A%7B%0A%20%20%22OutputsCtrl%22%20%3A%20%7B%0A%20%20%20%20%22switch%22%20%3A%20%22open%22%0A%20%20%7D%0A%7D&apiKey=100014&channelNo=0&deviceSerial=xxx&method=1"
    },
    "offUrl": {
        "url": "https://apiius.hik-connect.com/v3/userdevices/v1/isapi",
        "method": "POST",
        "headers": {
            "Content-Type": "application/x-www-form-urlencoded",
            "featureCode": "xxx",
            "appId": "NewHikConnect",
            "sessionId": "xxx"
        },
        "body": "apiData=PUT%20/ISAPI/SecurityCP/control/outputs/0?format%3Djson%0D%0A%7B%0A%20%20%22OutputsCtrl%22%20%3A%20%7B%0A%20%20%20%20%22switch%22%20%3A%20%22close%22%0A%20%20%7D%0A%7D&apiKey=100014&channelNo=0&deviceSerial=xxx&method=1"
    }

Would this help?
Only trouble is that I could not use regular digest authentication for some reason.
SessionId expires every 24 hours.

@judge
Copy link
Owner

judge commented Dec 13, 2024

Hmm it seems this is based on isapi, which is an API interface for hikvision devices. My plugin does not use that, but I also sniffed data between my device and phone app. I cannot enable isapi on my device because I live in a flat and my device is managed by someone else. :(
So to implement something like this into the plugin, I would need to use the isapi but I can't. Do you have local access to you device? If so, there is a forum thread on HomeAssistant forums (https://community.home-assistant.io/t/ds-kd8003-ds-kv8113-ds-kv8213-ds-kv6113-ds-kv8413-and-integration-hikvision-hikconnect-video-intercom-doorbell/238535), the LAN access is based on isapi as far as I know and it supports much more features than my plugin.

@ukiews
Copy link
Author

ukiews commented Dec 18, 2024

Hmm it seems this is based on isapi, which is an API interface for hikvision devices. My plugin does not use that, but I also sniffed data between my device and phone app. I cannot enable isapi on my device because I live in a flat and my device is managed by someone else. :( So to implement something like this into the plugin, I would need to use the isapi but I can't. Do you have local access to you device? If so, there is a forum thread on HomeAssistant forums (https://community.home-assistant.io/t/ds-kd8003-ds-kv8113-ds-kv8213-ds-kv6113-ds-kv8413-and-integration-hikvision-hikconnect-video-intercom-doorbell/238535), the LAN access is based on isapi as far as I know and it supports much more features than my plugin.

Yes I have looked and interacted there. Unfortunately, for some reason status request through ISAPI does not work using reverse engineering (no documentation provided). Did the log I send help at all?

@judge
Copy link
Owner

judge commented Dec 23, 2024

Unfortunately, no, I cannot see any info about the relays in that payload. Maybe if I would have a device like that (with relays) I could reverse engineer it, but it seems it's ISAPI only. :(

@trempetic92
Copy link

@judge I was able to do a bit of reverse engineering by monitoring the traffic from my iPhone and the Hik-Connect app to control the Com1 port:

    "onUrl": {
        "url": "https://apiius.hik-connect.com/v3/userdevices/v1/isapi",
        "method": "POST",
        "headers": {
            "Content-Type": "application/x-www-form-urlencoded",
            "featureCode": "xxx",
            "appId": "NewHikConnect",
            "sessionId": "xxx"
        },
        "body": "apiData=PUT%20/ISAPI/SecurityCP/control/outputs/0?format%3Djson%0D%0A%7B%0A%20%20%22OutputsCtrl%22%20%3A%20%7B%0A%20%20%20%20%22switch%22%20%3A%20%22open%22%0A%20%20%7D%0A%7D&apiKey=100014&channelNo=0&deviceSerial=xxx&method=1"
    },
    "offUrl": {
        "url": "https://apiius.hik-connect.com/v3/userdevices/v1/isapi",
        "method": "POST",
        "headers": {
            "Content-Type": "application/x-www-form-urlencoded",
            "featureCode": "xxx",
            "appId": "NewHikConnect",
            "sessionId": "xxx"
        },
        "body": "apiData=PUT%20/ISAPI/SecurityCP/control/outputs/0?format%3Djson%0D%0A%7B%0A%20%20%22OutputsCtrl%22%20%3A%20%7B%0A%20%20%20%20%22switch%22%20%3A%20%22close%22%0A%20%20%7D%0A%7D&apiKey=100014&channelNo=0&deviceSerial=xxx&method=1"
    }

Would this help? Only trouble is that I could not use regular digest authentication for some reason. SessionId expires every 24 hours.

This requires fetching a bearerToken using AppKey and App secret with developer account on hik connect or hik partner pro. Then you can redo requests

@judge
Copy link
Owner

judge commented Jan 25, 2025

Thanks! The plugin uses the normal end-user hik-connect account, that way the communication is not going through isapi, so it's pretty limited what it can do.
How do you guys get a developer account? When I try to register, I have to register as a company with valid company informations.

@ukiews
Copy link
Author

ukiews commented Jan 27, 2025

It does not seem they do any real verification on company info :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants