hikvision_next
hikvision_next copied to clipboard
Integration will not load
HA Version: 2023.4.5 Integration Verison: 1.03 NVR: iDS-7204HUHI-M1 / P Cameras: 1
Issue I upgraded to v1.03 and the integration will no longer load. Have reverted to v1.02 and this resolves.
Error
Logger: homeassistant.config_entries
Source: config_entries.py:1242
First occurred: 11:01:01 (25 occurrences)
Last logged: 11:49:06
Config entry 'Embedded Net DVR' for hikvision_next integration could not authenticate: Credentials expired for http://192.168.200.93 Cannot fetch state for scenechangedetection
I think the issue is related to the fact that it reports in smart capabilities that it supports scene change but it actually doesn't. It also reports region entry and exit are supported but they are not either. As such, when trying to get the rest endpoint for these the NVR returns a 403 error. When this is happening (with the changes to v1.03) it is failing to complete setup and keeps retrying.
In v1.02, the integration switches to enable/disable these unsupported (but reported as supported) functions show an unknown.

Capabilities Output http://192.x.x.x/ISAPI/Smart/capabilities
<?xml version="1.0" encoding="UTF-8" ?>
<SmartCap version="1.0" xmlns="http://www.hikvision.com/ver20/XMLSchema">
<isSupportROI>false</isSupportROI>
<isSupportFaceDetect>true</isSupportFaceDetect>
<isSupportIntelliTrace>false</isSupportIntelliTrace>
<isSupportFieldDetection>true</isSupportFieldDetection>
<isSupportDefocusDetection>true</isSupportDefocusDetection>
<isSupportAudioDetection>true</isSupportAudioDetection>
<isSupportSceneChangeDetection>true</isSupportSceneChangeDetection>
<isSupportLineDetection>true</isSupportLineDetection>
<isSupportRegionEntrance>true</isSupportRegionEntrance>
<isSupportRegionExiting>true</isSupportRegionExiting>
<isSupportLoitering>true</isSupportLoitering>
<isSupportGroup>true</isSupportGroup>
<isSupportRapidMove>true</isSupportRapidMove>
<isSupportParking>true</isSupportParking>
<isSupportUnattendedBaggage>true</isSupportUnattendedBaggage>
<isSupportAttendedBaggage>true</isSupportAttendedBaggage>
<isSupportAnalysisUnitSwitch>true</isSupportAnalysisUnitSwitch>
</SmartCap>
Responses for Endpoints http://192.x.x.x/ISAPI/Smart/SceneChangeDetection/1
<?xml version="1.0" encoding="UTF-8" ?>
<ResponseStatus version="1.0" xmlns="http://www.hikvision.com/ver20/XMLSchema">
<requestURL>/ISAPI/Smart/SceneChangeDetection/1</requestURL>
<statusCode>4</statusCode>
<statusString>Invalid Operation</statusString>
<subStatusCode>notSupport</subStatusCode>
</ResponseStatus>
'''
http://192.168.200.93/ISAPI/Smart/regionEntrance/1
```xml
<?xml version="1.0" encoding="UTF-8" ?>
<ResponseStatus version="1.0" xmlns="http://www.hikvision.com/ver20/XMLSchema">
<requestURL>/ISAPI/Smart/regionEntrance/1</requestURL>
<statusCode>4</statusCode>
<statusString>Invalid Operation</statusString>
<subStatusCode>notSupport</subStatusCode>
</ResponseStatus>
Love this integration btw and thanks very much for all your efforts on it.
In v1.03 I've implemented reauthentication feature. The error message you included begins that process. After 120s integration should try to connect again and all sensors should back to normal state. It's strange it occurred 25 times in 1 hour. In my system sensors went to unavailable state after NVR reboot, thanks to reauthentication they back in 120s. Please write more how to reproduce your issue.
I upgraded (via HACs) and restarted HA and it did not start with these errors. I then redownloaded v1.02, reatarted HA again and all working ok.
It is because in your handle_exception method, a 403 error ( HTTPStatus.FORBIDDEN ) is assumed this is because the client is no longer authorised. However, in this situation, when you are doing an update on the endpoints for scenechange, regionentry or regionexit, the NVR is returning a 403 because it is not supported. Therefore on every reauth, the same situation occurs on each update. Maybe i didnt make clear that the xml outputs above both return a 403 with this message via postman even though i can query other endpoints fine.
I'm also having the same issue on Hikvision NVR DS-7208HQHI-K1/E. The integration used to work on version 1.0.2 but after upgrading to 1.0.3 it fails to load with Cannot fetch state for scenechangedetection.
Hi, Did you find a solution to the issue? Thanks, Peter
Thanks for the tips. I've installed 1.02 and the integration now loads without errors.
I've still got some work to do as I'm not getting events triggered from the cameras.
Thanks,
Peter
OK, I have been looking into this more and will issue a PR shortly. I think the basic issue is 2 fold:
-
The device reports as a DVR not an NVR. As such, the integration assumes it is a single IP camera and does not load it as a DVR/NVR. Both the 7204 and 7208 (seems to be the common theme) do this.
-
Equally, this integration does not support (currently) analog (POC etc) cameras (which the 7204 and 7208 support).
As such, the changes I have made in the PR address both these issues. @maciej-or I cannot test an an actual NVR but hope that you can do that for me.
There is still a minor issue in that the video loss event is forced as supported and whilst my 7204 does support video loss, it is giving a 400 error when trying to read the event endpoint. However, this just issues a warning level log entry and shows the lightning bolts on the video loss switch for each camera. Will continue to work out why, when supported, you cannot use this endpoint for a later PR.
EDIT: Should also add that now it is correctly identifying/loading it as an NVR/DVR, the correct supported events are detected and the region entry/exit and scenechange errors are also resolved.
Thanks @msp1974, will test on NVR soon
Hi @msp1974, I tested your PR on a 7208 and it indeed fixed the issue as the integration now loads successfully, thanks!
However, the integration still sees my DVR and 8 analog cameras as a single device, which, I understand from your comment, is also something you aim to address with your PR #41. Please let me know if this is a separate problem and I'll file it as a new issue instead.
@Eskander Can you enable debugging on this custom component and post your logs
Hi @msp1974, I tested your PR on a 7208 and it indeed fixed the issue as the integration now loads successfully, thanks!
However, the integration still sees my DVR and 8 analog cameras as a single device, which, I understand from your comment, is also something you aim to address with your PR #41.
Please let me know if this is a separate problem and I'll file it as a new issue instead.
Sorry, I'm new to this... How do I test the new code? Do I need to manually cut and paste the new code into the files? Or is there a simple way for updating the files?
Thanks Peter
@Eskander Can you enable debugging on this custom component and post your logs
I zeroed out the serial number, otherwise this is the debug log as is with some intrusion events.
home-assistant_hikvision_next_2023-05-23T21-19-25.958Z.log.txt
How do I test the new code?
@Fitzpap one way to test is to remove the currently installed integration, add the URL of the fork with the changes to HACS as a Custom repository, then restart Home Assistant and install the integration again.
And double check that the version matches the last commit of the fork you're installing.
Ok @Eskander it looks like your DVR reports its device type as IPC amd not DVR or NVR. Couple of points here.
- You have pretty old firmware and there is a much newer version avaialable. Not sure whether newer firmware will change its reported device type to DVR. https://www.hikvision.com/ph/products/Turbo-HD-Products/DVR/Pro-Series/ds-7208hqhi-k1-e/
- You could try adding IPC to the DEVICE_TYPE_NVR constant in const.py and see if that works.
This is basically the issue that originally existed for the 7204 in that the integration was seeing it as a single IP camera.
@maciej-or i dont really understand the purpose of these parts of the code if it is not an NVR. Is it designed to support individual IP cameras also? Would it be better to assume an NVR type device or maybe change this detection logic to look for some other identifier of it being a multiple camera setup?
@msp1974 Thank you for taking the time to look at this.
Adding IPC to DEVICE_TYPE_NVR fixed the issue! Now the integration reports 9 devices: 1 DVR and 8 Video cameras.
I tested different events and streams and they're all working as expected.
As for firmware upgrades my DVR is the DS-7208HQHI-K1/E(S) variant, and the last firmware it accepts is V4.30.210_210111. Any other firmware is rejected.
@msp1974 yes, the integration supports stand alone cameras as well. They need different approach than NVR. I see we need to treat DVR separately too.
How do I test the new code?
@Fitzpap one way to test is to remove the currently installed integration, add the URL of the fork with the changes to HACS as a
Custom repository, then restart Home Assistant and install the integration again.
Hi when I try to add the url /msp1974/hikvision_next the "add" button is greyed out?
I'm assuming that I need to go into HACS, then click on the 3 buttons in the top right. Select custom repository?
Thanks, Peter :)
I'm assuming that I need to go into HACS, then click on the 3 buttons in the top right. Select custom repository?
Yes that's how I installed it. Another method is to install the custom component manually, check the instructions in the Readme.
Edit: You have to select integration in Category.
I'm assuming that I need to go into HACS, then click on the 3 buttons in the top right. Select custom repository?
Yes that's how I installed it. Maybe use the full URL.
Another method is to install the custom component manually, check the instructions in the Readme.
Hi,
For reference my device is iDS-7204HUHI-M1/FA/A. The changes made to the allow the integration to install and connect. Thanks for the excellent coding!
I manually installed the files. This still did not recognise the 4 analog cameras connected by BNCs. So I followed the suggestion above and added "IPC" as a device_type. Then restarted the HA. Suddenly I've got 5 devices and 40 entities. 😀 it feels like I'm getting really close now!
So far I've not managed to get any of the entries to change state. If I toggle smart alerts on I get a 400 error. The intrusion detection and lien cross also report as being clear.
I'm getting notifications from the Hikvision software. So I know the DVR is detecting motion. I just can't work out how to get the last part working....
🥲
Hi,
I’ve upgraded to 1.07. Since updating the integration no longer works. I had successfully added a device type of IPC. However I can’t find anywhere to add this device type.
I’m not sure how to get the integration working again?
Thanks for your help,
Peter
On Wed, 28 Jun 2023 at 20:21, Maciej @.***> wrote:
Closed #34 https://github.com/maciej-or/hikvision_next/issues/34 as completed.
— Reply to this email directly, view it on GitHub https://github.com/maciej-or/hikvision_next/issues/34#event-9668836165, or unsubscribe https://github.com/notifications/unsubscribe-auth/A32PTUE7AV5UIWJLUCOWAQLXNR73ZANCNFSM6AAAAAAXK24DGE . You are receiving this because you were mentioned.
@Fitzpap v1.06 and above now use a different method to determine if it is an NVR/DVR etc and no longer need the different reported types listing as before. I think you are seeing the same issue as some others in that a HDD sensor was added but some DVRs seem to provide a list of hdds in an unexpected format. The fix for this is already in the master branch and you just need to wait for v1.08.
Hi, thanks for the feedback. I will wait patiently! :)
Thanks again for all your hard work making this integration possible.
Peter
On Mon, 3 Jul 2023 at 01:37, Mark Parker @.***> wrote:
@Fitzpap https://github.com/Fitzpap v1.06 and above now use a different method to determine if it is an NVR/DVR etc and no longer need the different reported types listing as before. I think you are seeing the same issue as some others in that a HDD sensor was added but some DVRs seem to provide a list of hdds in an unexpected format. The fix for this is already in the master branch and you just need to wait for v1.08.
— Reply to this email directly, view it on GitHub https://github.com/maciej-or/hikvision_next/issues/34#issuecomment-1617050234, or unsubscribe https://github.com/notifications/unsubscribe-auth/A32PTUCIY22NTL7VFPAZWVDXOIH3BANCNFSM6AAAAAAXK24DGE . You are receiving this because you were mentioned.Message ID: @.***>