Coder Social home page Coder Social logo

Re-Branded Hik - Different URL about pyhik HOT 17 CLOSED

mezz64 avatar mezz64 commented on June 24, 2024
Re-Branded Hik - Different URL

from pyhik.

Comments (17)

mezz64 avatar mezz64 commented on June 24, 2024

What type of http response do you receive when you query the /ISAPI/Event/triggers url on your cameras? Is it just a 404?

To the second part, you are saying that for your cams when you check Notify Surveillance Center in the camera configuration the method is reported as HTTP in the event stream, correct?

I just want to make sure that adding in the alternate options won't cause unintended behavior on the branded Hikvision cameras.

from pyhik.

Tim-GitHub avatar Tim-GitHub commented on June 24, 2024

When attempting to access /ISAPI/Event/triggers on the re-branded models I get the following pages:

Chrome:

Access Error: 404 -- Not Found

Can't locate document: /ISAPI/Event/triggers

404

IE11:

The webpage cannot be found

Most likely causes:
     • There might be a typing error in the address.
     • If you clicked on a link, it may be out of date.
 
What you can try:
 
    • Retype the address.  
    • Go back to the previous page.  
    • Go to  and look for the information you want.  

More information

This error (HTTP 404 Not Found) means that Internet Explorer was able to connect to the website, but the page you wanted was not found. It’s possible that the webpage is temporarily unavailable. Alternatively, the website might have changed or removed the webpage.

404-ie

For the second part this is the complete contents of /Event/triggers with only Notify Surveillance Center enabled for motion on the camera. Forgive the formatting if it's not quite right:

 <?xml version="1.0" encoding="UTF-8" ?> 
- <EventTriggerList version="1.0" xmlns="http://www.std-cgi.com/ver10/XMLSchema">
	- <EventTrigger version="1.0" xmlns="http://www.std-cgi.com/ver10/XMLSchema">
		  <id>1</id> 
		  <eventType>VMD</eventType> 
		  <eventDescription>VMD Event trigger Information</eventDescription> 
		- <EventTriggerNotificationList version="1.0" xmlns="http://www.std-cgi.com/ver10/XMLSchema">
			- <EventTriggerNotification>
				  <id>3</id> 
				  <notificationMethod>HTTP</notificationMethod> 
				  <notificationRecurrence>beginning</notificationRecurrence> 
			</EventTriggerNotification>
			</EventTriggerNotificationList>
		</EventTrigger>
	  <EventTrigger version="1.0" xmlns="http://www.std-cgi.com/ver10/XMLSchema" /> 
	  <EventTrigger version="1.0" xmlns="http://www.std-cgi.com/ver10/XMLSchema" /> 
	</EventTriggerList>

from pyhik.

Tim-GitHub avatar Tim-GitHub commented on June 24, 2024

Ah something interesting. On my genuine USA Hikvision /Event/triggers works as well. The list is much more condensed though like the sample above. Also the notificationMethod is HTTP in /Event/triggers but center in /ISAPI/Event/triggers

Same camera (USA Hikvision):

/ISAPI/Event/triggers:
iaspi-events-triggers.txt
/Event/triggers:
events-triggers.txt

Changing from Notify Surveillance Center to Send Email results in the notificationMethod changing to email, so HTTP seems exclusive to Notify Surveillance Center

from pyhik.

mezz64 avatar mezz64 commented on June 24, 2024

Your triggers XML is very similar to what gets returned for NVR's, but with the center/HTTP variation and unfortunately yet another naming scheme for the channel id.

Since you get a 404 on fetching the existing url it should be easy enough to catch it and switch to the other one. Adding in the HTTP shouldn't be an issue. Only thing I need to put some thought into is detecting the difference between this camera and an NVR so the channels get processed correctly.

I'll post back once i've got something for you to test.

from pyhik.

Tim-GitHub avatar Tim-GitHub commented on June 24, 2024

Fantastic thanks!

from pyhik.

mezz64 avatar mezz64 commented on June 24, 2024

I made the changes that should get things working for you.

Easiest way to test it out is download the "altcam" branch of pyhik from github and copy the pyhik folder to your hass configuration/deps directory.
https://github.com/mezz64/pyHik/tree/altcam

Then comment out the REQUIREMENTS line at the top of the hikvision.py file in your component/binary_sensor folder so HASS just looks in the deps directory rather than trying to use the current pip version.

Let me know how things work out.

from pyhik.

Tim-GitHub avatar Tim-GitHub commented on June 24, 2024

I copied the altcam branch and commented out the REQUIREMENTS line. Still no luck. Relevant log snippet below:

17-03-30 20:50:00 INFO (MainThread) [homeassistant.loader] Loaded binary_sensor.hikvision from homeassistant.components.binary_sensor.hikvision
17-03-30 20:50:01 INFO (MainThread) [homeassistant.bootstrap] Setting up binary_sensor
17-03-30 20:50:01 INFO (MainThread) [homeassistant.components.binary_sensor] Setting up binary_sensor.hikvision
17-03-30 20:50:01 DEBUG (<concurrent.futures.thread.ThreadPoolExecutor object at 0x02A5EB90>_4) [pyhik.hikvision] Initializing new hikvision device at: http://192.168.1.41
17-03-30 20:50:01 DEBUG (<concurrent.futures.thread.ThreadPoolExecutor object at 0x02A5EB90>_4) [pyhik.hikvision] Using Namespace: http://www.hikvision.com/ver20/XMLSchema
17-03-30 20:50:01 ERROR (MainThread) [homeassistant.components.binary_sensor] Error while setting up platform hikvision
Traceback (most recent call last):
  File "C:\Users\ha\AppData\Local\Programs\Python\Python36-32\lib\site-packages\homeassistant\helpers\entity_component.py", line 151, in _async_setup_platform
    entity_platform.add_entities, discovery_info
  File "C:\Users\ha\AppData\Local\Programs\Python\Python36-32\lib\concurrent\futures\thread.py", line 55, in run
    result = self.fn(*self.args, **self.kwargs)
  File "C:\Users\ha\AppData\Local\Programs\Python\Python36-32\lib\site-packages\homeassistant\components\binary_sensor\hikvision.py", line 85, in setup_platform
    data = HikvisionData(hass, url, port, name, username, password)
  File "C:\Users\ha\AppData\Local\Programs\Python\Python36-32\lib\site-packages\homeassistant\components\binary_sensor\hikvision.py", line 123, in __init__
    self._username, self._password)
  File "C:\Users\ha\AppData\Roaming\.homeassistant\deps\pyhik\hikvision.py", line 104, in __init__
    self.initialize()
  File "C:\Users\ha\AppData\Roaming\.homeassistant\deps\pyhik\hikvision.py", line 145, in initialize
    device_info = self.get_device_info()
  File "C:\Users\ha\AppData\Roaming\.homeassistant\deps\pyhik\hikvision.py", line 284, in get_device_info
    tag = item.tag.split('}')[1]
IndexError: list index out of range

XML located at http://192.168.1.41/event/triggers:

<EventTriggerList xmlns="http://www.hikvision.com/ver10/XMLSchema" version="1.0">
<EventTrigger xmlns="http://www.hikvision.com/ver10/XMLSchema" version="1.0">
<id>1</id>
<eventType>VMD</eventType>
<eventDescription>VMD Event trigger Information</eventDescription>
<EventTriggerNotificationList xmlns="http://www.hikvision.com/ver10/XMLSchema" version="1.0">
<EventTriggerNotification>
<id>3</id>
<notificationMethod>HTTP</notificationMethod>
<notificationRecurrence>beginning</notificationRecurrence>
</EventTriggerNotification>
</EventTriggerNotificationList>
</EventTrigger>
<EventTrigger xmlns="http://www.hikvision.com/ver10/XMLSchema" version="1.0"></EventTrigger>
<EventTrigger xmlns="http://www.hikvision.com/ver10/XMLSchema" version="1.0"></EventTrigger>
</EventTriggerList>

from pyhik.

mezz64 avatar mezz64 commented on June 24, 2024

Problem is it seems like you have no ISAPI endpoint at all so all the default API urls won't work. I pushed another update that tries your variant when it can't get the first for deviceinfo, triggers, and the event stream. Give it a shot.

from pyhik.

Tim-GitHub avatar Tim-GitHub commented on June 24, 2024

Getting closer (I hope!)

17-03-31 18:36:51 INFO (MainThread) [homeassistant.loader] Loaded binary_sensor.hikvision from homeassistant.components.binary_sensor.hikvision
17-03-31 18:36:51 INFO (MainThread) [homeassistant.bootstrap] Setting up binary_sensor
17-03-31 18:36:51 INFO (MainThread) [homeassistant.components.binary_sensor] Setting up binary_sensor.hikvision
17-03-31 18:36:51 DEBUG (<concurrent.futures.thread.ThreadPoolExecutor object at 0x0265CB90>_0) [pyhik.hikvision] Initializing new hikvision device at: http://192.168.1.41
17-03-31 18:36:52 DEBUG (<concurrent.futures.thread.ThreadPoolExecutor object at 0x0265CB90>_0) [pyhik.hikvision] Using Namespace: http://www.hikvision.com/ver10/XMLSchema
17-03-31 18:36:52 ERROR (MainThread) [homeassistant.components.binary_sensor] Error while setting up platform hikvision
Traceback (most recent call last):
  File "C:\Users\ha\AppData\Local\Programs\Python\Python36-32\lib\site-packages\homeassistant\helpers\entity_component.py", line 151, in _async_setup_platform
    entity_platform.add_entities, discovery_info
  File "C:\Users\ha\AppData\Local\Programs\Python\Python36-32\lib\concurrent\futures\thread.py", line 55, in run
    result = self.fn(*self.args, **self.kwargs)
  File "C:\Users\ha\AppData\Local\Programs\Python\Python36-32\lib\site-packages\homeassistant\components\binary_sensor\hikvision.py", line 85, in setup_platform
    data = HikvisionData(hass, url, port, name, username, password)
  File "C:\Users\ha\AppData\Local\Programs\Python\Python36-32\lib\site-packages\homeassistant\components\binary_sensor\hikvision.py", line 123, in __init__
    self._username, self._password)
  File "C:\Users\ha\AppData\Roaming\.homeassistant\deps\pyhik\hikvision.py", line 104, in __init__
    self.initialize()
  File "C:\Users\ha\AppData\Roaming\.homeassistant\deps\pyhik\hikvision.py", line 159, in initialize
    events_available = self.get_event_triggers()
  File "C:\Users\ha\AppData\Roaming\.homeassistant\deps\pyhik\hikvision.py", line 234, in get_event_triggers
    for notifytrigger in etnotify:
TypeError: 'NoneType' object is not iterable

from pyhik.

mezz64 avatar mezz64 commented on June 24, 2024

Your logs are indicating that unexpected data is getting returned during the initial device info stage. I've pushed a new commit with some more debugging statements that should lend some more insight. Can you also verify that this URL is accessible on your cameras and post the output here?

http://YOUR_CAM_IP/System/deviceInfo

from pyhik.

Tim-GitHub avatar Tim-GitHub commented on June 24, 2024

Tested.

Relevant logs:

17-04-01 10:05:13 DEBUG (<concurrent.futures.thread.ThreadPoolExecutor object at 0x02A5E3B0>_0) [pyhik.hikvision] Initializing new hikvision device at: http://192.168.1.41
17-04-01 10:05:14 DEBUG (<concurrent.futures.thread.ThreadPoolExecutor object at 0x02A5E3B0>_0) [pyhik.hikvision] Using alternate deviceInfo URL.
17-04-01 10:05:15 DEBUG (<concurrent.futures.thread.ThreadPoolExecutor object at 0x02A5E3B0>_0) [pyhik.hikvision] Auto Namespace Result: http://www.hikvision.com/ver10/XMLSchema
17-04-01 10:05:15 DEBUG (<concurrent.futures.thread.ThreadPoolExecutor object at 0x02A5E3B0>_0) [pyhik.hikvision] Using Namespace: http://www.hikvision.com/ver10/XMLSchema
17-04-01 10:05:17 ERROR (MainThread) [homeassistant.components.binary_sensor] Error while setting up platform hikvision
Traceback (most recent call last):
  File "C:\Users\ha\AppData\Local\Programs\Python\Python36-32\lib\site-packages\homeassistant\helpers\entity_component.py", line 151, in _async_setup_platform
    entity_platform.add_entities, discovery_info
  File "C:\Users\ha\AppData\Local\Programs\Python\Python36-32\lib\concurrent\futures\thread.py", line 55, in run
    result = self.fn(*self.args, **self.kwargs)
  File "C:\Users\ha\AppData\Local\Programs\Python\Python36-32\lib\site-packages\homeassistant\components\binary_sensor\hikvision.py", line 85, in setup_platform
    data = HikvisionData(hass, url, port, name, username, password)
  File "C:\Users\ha\AppData\Local\Programs\Python\Python36-32\lib\site-packages\homeassistant\components\binary_sensor\hikvision.py", line 123, in __init__
    self._username, self._password)
  File "C:\Users\ha\AppData\Roaming\.homeassistant\deps\pyhik\hikvision.py", line 104, in __init__
    self.initialize()
  File "C:\Users\ha\AppData\Roaming\.homeassistant\deps\pyhik\hikvision.py", line 159, in initialize
    events_available = self.get_event_triggers()
  File "C:\Users\ha\AppData\Roaming\.homeassistant\deps\pyhik\hikvision.py", line 234, in get_event_triggers
    for notifytrigger in etnotify:
TypeError: 'NoneType' object is not iterable

deviceInfo:

<DeviceInfo xmlns="http://www.hikvision.com/ver10/XMLSchema" version="1.0">
<deviceName>Front Door</deviceName>
<deviceID>88</deviceID>
<deviceDescription>IPCamera</deviceDescription>
<deviceLocation>hangzhou</deviceLocation>
<systemContact>Hikvision.China</systemContact>
<model>NC-KD032</model>
<serialNumber>NC-KD0320120130609CCRR424264952</serialNumber>
<macAddress>8c:e7:48:f7:0e:97</macAddress>
<firmwareVersion>V5.0.2</firmwareVersion>
<firmwareReleasedDate>130805</firmwareReleasedDate>
<bootVersion>V1.3.4</bootVersion>
<bootReleasedDate>100316</bootReleasedDate>
<hardwareVersion>V4.0</hardwareVersion>
</DeviceInfo>

from pyhik.

mezz64 avatar mezz64 commented on June 24, 2024

Ok, something doesn't make sense here. The first trigger response you posted listed a std-cgi.com namespace yet the device info shows a hikvision.com namespace. Are you testing with the same camera?

In any case I adding handling for the error you posted, give it another shot.

from pyhik.

Tim-GitHub avatar Tim-GitHub commented on June 24, 2024

Oops yes your right I mixed up which camera I was testing on from the previous night. Regardless it looks like your new commits were successful! There still appears that there may be an issue based on an error in the log and I don't see the sensor appear on my HA states web ui.

17-04-01 22:17:21 INFO (MainThread) [homeassistant.bootstrap] Setting up binary_sensor
17-04-01 22:17:21 INFO (MainThread) [homeassistant.components.binary_sensor] Setting up binary_sensor.hikvision
17-04-01 22:17:21 DEBUG (<concurrent.futures.thread.ThreadPoolExecutor object at 0x02A5E3B0>_2) [pyhik.hikvision] Initializing new hikvision device at: http://192.168.1.41
17-04-01 22:17:21 DEBUG (<concurrent.futures.thread.ThreadPoolExecutor object at 0x02A5E3B0>_2) [pyhik.hikvision] Using alternate deviceInfo URL.
17-04-01 22:17:21 DEBUG (<concurrent.futures.thread.ThreadPoolExecutor object at 0x02A5E3B0>_2) [pyhik.hikvision] Auto Namespace Result: http://www.hikvision.com/ver10/XMLSchema
17-04-01 22:17:21 DEBUG (<concurrent.futures.thread.ThreadPoolExecutor object at 0x02A5E3B0>_2) [pyhik.hikvision] Using Namespace: http://www.hikvision.com/ver10/XMLSchema
17-04-01 22:17:21 DEBUG (<concurrent.futures.thread.ThreadPoolExecutor object at 0x02A5E3B0>_2) [pyhik.hikvision] Using alternate triggers URL.
17-04-01 22:17:21 DEBUG (<concurrent.futures.thread.ThreadPoolExecutor object at 0x02A5E3B0>_2) [pyhik.hikvision] Processed CAM Device.
17-04-01 22:17:21 DEBUG (<concurrent.futures.thread.ThreadPoolExecutor object at 0x02A5E3B0>_2) [pyhik.hikvision] Found events: {'VMD': [1]}
17-04-01 22:17:21 DEBUG (<concurrent.futures.thread.ThreadPoolExecutor object at 0x02A5E3B0>_2) [pyhik.hikvision] Initialized Dictionary: {'Motion': [[False, 1, 0, datetime.datetime(2017, 4, 1, 22, 17, 21, 795821)]]}
17-04-01 22:17:21 DEBUG (Thread-3) [pyhik.hikvision] Stream Thread Started: Front Door, 88
17-04-01 22:17:22 DEBUG (<concurrent.futures.thread.ThreadPoolExecutor object at 0x02A5E3B0>_2) [homeassistant.components.binary_sensor.hikvision] Entity: Front Door - Motion, Options - Ignore: None, Delay: None
17-04-01 22:17:22 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "C:\Users\ha\AppData\Local\Programs\Python\Python36-32\lib\site-packages\homeassistant\helpers\entity_component.py", line 341, in _async_process_entity
    new_entity, self, update_before_add=update_before_add
  File "C:\Users\ha\AppData\Local\Programs\Python\Python36-32\lib\site-packages\homeassistant\helpers\entity_component.py", line 209, in async_add_entity
    yield from entity.async_update_ha_state()
  File "C:\Users\ha\AppData\Local\Programs\Python\Python36-32\lib\site-packages\homeassistant\helpers\entity.py", line 228, in async_update_ha_state
    device_attr = self.device_state_attributes
  File "C:\Users\ha\AppData\Local\Programs\Python\Python36-32\lib\site-packages\homeassistant\components\binary_sensor\hikvision.py", line 221, in device_state_attributes
    attr[ATTR_LAST_TRIP_TIME] = self._sensor_last_update()
  File "C:\Users\ha\AppData\Local\Programs\Python\Python36-32\lib\site-packages\homeassistant\components\binary_sensor\hikvision.py", line 186, in _sensor_last_update
    return self._cam.sensors[self._sensor][3]
IndexError: list index out of range
17-04-01 22:17:22 DEBUG (Thread-3) [pyhik.hikvision] Front Door Connection Successful.

from pyhik.

mezz64 avatar mezz64 commented on June 24, 2024

Looks like you aren't using the latest hikvision.py currently in the HASS dev branch. Please test with that version. Make sure to comment out the REQUIREMENTS line.

from pyhik.

Tim-GitHub avatar Tim-GitHub commented on June 24, 2024

That did it! Works perfectly now with all my various re-branded Hikvision cameras! Thank you for all your help getting this working. Ever since installing my cameras a couple years ago I always wanted to integrate motion events my HA system. Now to start playing with them!

from pyhik.

mezz64 avatar mezz64 commented on June 24, 2024

Once your multiple cam issue gets fixed and I verify everything still works as expected with normal hik cams and nvrs I'll make a release for the changes and get the updates merged into HASS.

from pyhik.

mezz64 avatar mezz64 commented on June 24, 2024

Updated version has been merged into HASS dev. Closing this issue.

from pyhik.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.