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

AX Hub support #31

Closed
youmax01 opened this issue Mar 13, 2023 · 105 comments
Closed

AX Hub support #31

youmax01 opened this issue Mar 13, 2023 · 105 comments
Assignees
Labels
question Further information is requested

Comments

@youmax01
Copy link

youmax01 commented Mar 13, 2023

Hi, i hava a AX hub alarm, use the same ISAP protocol, but do not work with this integration
is possible to help to add config?

i have a list of isap config of my alarm

http://192.168.1.4/ISAPI/SecurityCP/status/host?format=json

{
	"AlarmHostStatus": {
		"ZoneList": [{
			"Zone": {
				"id": 0,
				"name": "Movimiento Quincho",
				"status": "online",
				"tamperEvident": false,
				"shielded": false,
				"bypassed": false,
				"armed": false,
				"isArming": false,
				"alarm": false,
				"charge": "normal",
				"signal": 113
			}
		}, ...],
		"ExDevStatus": {
			"OutputModList": [{
				"OutputMod": {
					"id": 1,
					"seq": "Q00987842",
					"status": "online",
					"tamperEvident": false,
					"charge": "normal",
					"signal": 195
				}
			},,...],
			"SirenList": [{
				"Siren": {
					"id": 1,
					"name": "Sirena interna",
					"seq": "Q01151860",
					"status": "off",
					"tamperEvident": false,
					"charge": "normal",
					"signal": 149
				}
			},...],
			"CardReaderList": [{
				"CardReader": {
					"id": 1,
					"seq": "",
					"name": "Lector de tarjetas 1",
					"status": "notRelated",
					"tamperEvident": false,
					"signal": 0
				}
			}, ...],
			"KeypadList": [{
				"Keypad": {
					"id": 1,
					"seq": "Q00987589",
					"name": "Teclado ingreso",
					"status": "online",
					"tamperEvident": false,
					"charge": "normal",
					"signal": 149
				}
			}, ...]
		},
		"BatteryList": [{"Battery": {...}}],
		"CommuniStatus": {...}
	}
}

For shortening of conversation - attached file (json not supported - log ext - still json valid file)
axhub-status-response.json.log

@petrleocompel petrleocompel self-assigned this Mar 13, 2023
@petrleocompel petrleocompel added the question Further information is requested label Mar 13, 2023
@petrleocompel
Copy link
Owner

Did you try to use the integration ? do you have any logs from "trial of usage this integration" from HA ?

@youmax01
Copy link
Author

youmax01 commented Mar 14, 2023

Hi petrleo !, thanks for repply
yes, i try, but dont work
local connection to alarm work ok
this is the log:

Logger: custom_components.hikvision_axpro.config_flow
Source: custom_components/hikvision_axpro/config_flow.py:92
Integration: hikvision_axpro
First occurred: 11:14:43 (1 occurrences)
Last logged: 11:14:43
Unexpected exception
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/hikaxpro.py", line 22, in getSessionParams
    sessionCap = self.parseSessionResponse(sessionResponse.text)
  File "/usr/local/lib/python3.10/site-packages/hikaxpro.py", line 35, in parseSessionResponse
    root.find("xmlns:salt", namespaces).text,
AttributeError: 'NoneType' object has no attribute 'text'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/config/custom_components/hikvision_axpro/config_flow.py", line 144, in async_step_user
    info = await validate_input(self.hass, user_input)
  File "/config/custom_components/hikvision_axpro/config_flow.py", line 117, in validate_input
    if not await hub.authenticate():
  File "/config/custom_components/hikvision_axpro/config_flow.py", line 92, in authenticate
    is_connect_success = await self.hass.async_add_executor_job(self.axpro.connect)
  File "/usr/local/lib/python3.10/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.10/site-packages/hikaxpro.py", line 60, in connect
    params = self.getSessionParams()
  File "/usr/local/lib/python3.10/site-packages/hikaxpro.py", line 25, in getSessionParams
    raise errors.IncorrectResponseContentError()
errors.errors.IncorrectResponseContentError: Response content is not in expected form.

@petrleocompel
Copy link
Owner

@youmax01 if the endpoints differs too much it is easier to make another integration and implement it separately or at least on start of configuration make it as device type and the workflow will be changed. This integration is for AX Pro. And it should stay for AX Pro. Because there seems to be lot of differences.

Can you gather some info. I cannot find this AX hub on official site. So I would get some documentation on this.

If the main protocol is that different I would rather create separated repo.

@youmax01
Copy link
Author

thanks you i add manually on my HA , do you need see config?

@petrleocompel
Copy link
Owner

No. I don't need currently see your config.

I need documentation for your device. Cannot find any links to AX Hub on HikVision official site.

Can you provide some docs? API Endpoints etc? The main login method is different can you manually check the result xml?

I can make some changes for easier debug of it. But it will be later today.

@petrleocompel
Copy link
Owner

@youmax01
Copy link
Author

@petrleocompel
Copy link
Owner

I understand. The ISAPI is standardised. It is going to be almost the same. But the stuff around.

Currently it is for you response of method /ISAPI/Security/sessionLogin. We will need some info there. If you are not able to code (to modify the integration your self for testing) you will have to wait until I will release version 1.0.0. I will add some debug information there.

@petrleocompel
Copy link
Owner

I was going in deep if we can check the connect process. Sadly /ISAPI/Security/sessionLogin is in dependency library. And we have no control over the connection process. And it is returning only true/false.

I will try maybe take over this control flow. For failed calls and make separate calling. But since this library is outside of the project we cannot tailor it to our needs.

Currently there is no easy way other than full debug of HA and communication. You can try on your own if you have the knowledge about XML, HTTP to make some cUrl calls or use postman or something like that. But when I don't have the device I cannot fully help.

In file /usr/local/lib/python3.10/site-packages/hikaxpro.py can be added line before line 34.

        import logging
        logging.getLogger(__name__).warning("Debug data %s", xml_data)

to make it look like this
image

In log of HA this would give me response of your device and we can try to proceed.

@youmax01
Copy link
Author

i will try! and post the result soon. tanks

@youmax01
Copy link
Author

dont have /usr/local/lib/xxxxxxxxxx folder

image

have:
image

@petrleocompel
Copy link
Owner

petrleocompel commented Mar 15, 2023 via email

@youmax01
Copy link
Author

yes, sorry, this is the printscreen
homeassistant os on X86

i dont know how /usb/local/lib/ is empty

image

@youmax01
Copy link
Author

image

@petrleocompel
Copy link
Owner

petrleocompel commented Mar 15, 2023 via email

@petrleocompel
Copy link
Owner

petrleocompel commented Mar 15, 2023 via email

@petrleocompel
Copy link
Owner

petrleocompel commented Mar 15, 2023 via email

@youmax01
Copy link
Author

same thing with sudo or su

image

@petrleocompel
Copy link
Owner

Okay I found out. HomeAssistant is running in docker container. So in SSH you have to get in the container first... docker exec -it homeassistant bash (container name can be different docker ps for list) and then you are in console of your HA instance. Watchout container does not have to have all commands. Maybe you would have to use vim or nano.

@youmax01
Copy link
Author

perfect !, but don show up

image

@youmax01
Copy link
Author

image

@petrleocompel
Copy link
Owner

petrleocompel commented Mar 15, 2023

Please try absolute path command. Like cat /usr/local/lib/python3.10/site-packages/hikaxpro.py

@youmax01
Copy link
Author

sorry, not have lucky
not know very much of these

image

@petrleocompel
Copy link
Owner

Did you update your HA instance by any chance ?

@petrleocompel
Copy link
Owner

If will not get trough this last hope will be update in version 1.0.0. Maybe released tomorrow. I will try manage some backup logging in connect process

@nautilus7
Copy link

I was going in deep if we can check the connect process. Sadly /ISAPI/Security/sessionLogin is in dependency library. And we have no control over the connection process. And it is returning only true/false.

I will try maybe take over this control flow. For failed calls and make separate calling. But since this library is outside of the project we cannot tailor it to our needs.

Currently there is no easy way other than full debug of HA and communication. You can try on your own if you have the knowledge about XML, HTTP to make some cUrl calls or use postman or something like that. But when I don't have the device I cannot fully help.

In file /usr/local/lib/python3.10/site-packages/hikaxpro.py can be added line before line 34.

        import logging
        logging.getLogger(__name__).warning("Debug data %s", xml_data)

to make it look like this image

In log of HA this would give me response of your device and we can try to proceed.

Hi, I have the previous ax alarm hub (not the pro). I also happen to be a programmer and I have some experience with python. I don't have any experience with home assistant though. It's all new stuff for me.

So, apart from adding these extra logging lines in the code, what else should I do? Are there any specific settings from the alarm hub side that are needed for the integration to work? Where do I find the logs from the integration?

I hope we can help to make this work. Thanks.

@nautilus7
Copy link

I run home assistant inside truenas scale using the truecharts app. It's not convenient to make changes to the integration files inside the app, so I think it would be better to fork this repo, make test changes and add that repo inside hacs, instead of the original one.

So, in which python file in the repo I put the above logging code?

@petrleocompel
Copy link
Owner

petrleocompel commented Mar 26, 2023

It is not that easy... The lib is https://github.com/gunkutzeybek/hikaxpro but it is for AX Pro. Owner of the repo is not responding -> gunkutzeybek/hikaxpro#11 waiting for first pull request...
I currently have in development a version which contains this login function directly not via hikaxpro library. I will make it public with option to test it.
I guess this week.

It was only a workaround to test it. Sadly I do not have AX Hub otherwise it would be tested and maybe if protocol differs too much I would create separate integration for that...
It is not about forking this repo. It is more about getting info from the API what it returns on the login function if you could test end provide results I would take care of that.

You can on your own test via postman, curl, insomnia etc.. what it returns on /ISAPI/Security/sessionLogin with correct xml input. For more info take a look in here https://github.com/gunkutzeybek/hikaxpro/blob/master/src/hikaxpro.py#L59

If you would provide response of correct login (you can scrable the return values for security) I can manage fix of that for compatibility. @nautilus7

@petrleocompel
Copy link
Owner

@nautilus7 for example HomeKit (iOS) integration if you use Apple. Or Google Home integration.
Automation for disarming / arming. Reading values of sensors. Temperature, signal, battery. Automate notification for low battery, temp etc..

@petrleocompel
Copy link
Owner

Currently there is a lot of logging enabled. I will create separate option for logging ex hub fully. (for reasons like this - since I do not own this device). And next release (1.2.0) will close this issue and we from now on support AX Hub.

@nautilus7
Copy link

nautilus7 commented Apr 1, 2023

I tried disarming the alarm (from the dashboard), but it did not work:

Logger: homeassistant.components.websocket_api.http.connection
Source: custom_components/hikvision_axpro/__init__.py:251
Integration: Home Assistant WebSocket API (documentation, issues)
First occurred: 13:52:18 (2 occurrences)
Last logged: 13:52:25

[140196928938592] HikAx.disarm() missing 1 required positional argument: 'sub_id'
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 200, in handle_call_service
    await hass.services.async_call(
  File "/usr/src/homeassistant/homeassistant/core.py", line 1787, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1824, in _execute_service
    await cast(Callable[[ServiceCall], Awaitable[None]], handler.job.target)(
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 213, in handle_service
    await service.entity_service_call(
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 680, in entity_service_call
    future.result()  # pop exception if have
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 968, in async_request_call
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 720, in _handle_entity_call
    await result
  File "/config/custom_components/hikvision_axpro/alarm_control_panel.py", line 108, in async_alarm_disarm
    await self.coordinator.async_disarm()
  File "/config/custom_components/hikvision_axpro/__init__.py", line 251, in async_disarm
    is_success = await self.hass.async_add_executor_job(self.axpro.disarm)
  File "/usr/local/lib/python3.10/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
TypeError: HikAx.disarm() missing 1 required positional argument: 'sub_id'

Same for arming (home and away). Same error.

@nautilus7
Copy link

nautilus7 commented Apr 1, 2023

Ok, so it seems that I cannot see the battery levels on the individual devices (motion detectors, door contacts, etc) when logging directly to the control panel. It seems the ax hub API does not provide this info?

Only the control panel itself has a battery level indicator which is NOT available in the integration...

Also I have a wireless keypad in my installation, which is not listed in the hass integration's devices...

@petrleocompel
Copy link
Owner

If Panel does not see battery levels we will not get it also.
The main battery will be displayed later. With #14 .
Keyboards are not currently integrated.

@petrleocompel
Copy link
Owner

With release v1.2.0 AX Hub should be supported. Logging is opt-in. And after solving other things with hikaxpro lib things should clear up more.

@nautilus7 thank you for providing debug outputs. And keeping up.
@youmax01 you can try on your own now.

@nautilus7
Copy link

Thank you for the hard work. Great results!

@youmax01
Copy link
Author

youmax01 commented Apr 1, 2023

Exellent ! Y willy try. Good work!

@nautilus7
Copy link

Still not able to arm/disarm:

2023-04-01 15:25:56.729 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [140205228996880] Unexpected response status code 400 returned with message { "statusCode": 4, "statusString": "Invalid Operation", "subStatusCode": "methodNotAllowed", "errorCode": 1073741828, "errorMsg": "methodNotAllowed" }
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 200, in handle_call_service
    await hass.services.async_call(
  File "/usr/src/homeassistant/homeassistant/core.py", line 1787, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1824, in _execute_service
    await cast(Callable[[ServiceCall], Awaitable[None]], handler.job.target)(
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 213, in handle_service
    await service.entity_service_call(
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 680, in entity_service_call
    future.result()  # pop exception if have
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 968, in async_request_call
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 720, in _handle_entity_call
    await result
  File "/config/custom_components/hikvision_axpro/alarm_control_panel.py", line 124, in async_alarm_arm_away
    await self.coordinator.async_arm_away()
  File "/config/custom_components/hikvision_axpro/__init__.py", line 245, in async_arm_away
    is_success = await self.hass.async_add_executor_job(self.axpro.arm_away)
  File "/usr/local/lib/python3.10/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/hikvision_axpro/hikax/hikax.py", line 164, in arm_away
    return self._base_json_request(f"http://{self.host}{consts.Endpoints.Alarm_ArmAway.replace('{}', sid)}",
  File "/config/custom_components/hikvision_axpro/hikax/hikax.py", line 153, in _base_json_request
    raise errors.UnexpectedResponseCodeError(response.status_code, response.text)
errors.errors.UnexpectedResponseCodeError: Unexpected response status code 400 returned with message { "statusCode": 4, "statusString": "Invalid Operation", "subStatusCode": "methodNotAllowed", "errorCode": 1073741828, "errorMsg": "methodNotAllowed" }

@petrleocompel
Copy link
Owner

petrleocompel commented Apr 1, 2023

@nautilus7 I dont know if AX Hub actually supports "Arm away". Or if you can disarm / arm without "code" you might will have to configure the code.

@petrleocompel
Copy link
Owner

@nautilus7 Can you in AX Hub panel trigger arm / disarm ? Can you capture it in Dev Tools ? URL + payload.

@nautilus7
Copy link

It does support "away arm". None of the arming/disarming can be done via the web interface of the control panel. You can only do it via the hik-connect app, or the keypad of course.

What "code" should I put in? I don't have any code, except from the one I use in the keypad. But the keypad code is only known to the keypad itself. The hub is not aware of that code.

@petrleocompel
Copy link
Owner

The keypad should be linked to the system and it knows the code (it should be assigned to the user). You can try.
If it does not follow the ISAPI then there will be no way. We can try something but do not expect much.

@nautilus7
Copy link

Tried the code. No luck unfortunately.... Exact same error as before. Tried both away and home arming...

@petrleocompel
Copy link
Owner

I will try figure out what call has to be made to make it fully work. The ISAPI spec says it should be supported and since the response is 400 not 404 I think it is just bad request content.

@nautilus7
Copy link

@petrleocompel hi, did you make any progress on this?

@petrleocompel
Copy link
Owner

@petrleocompel hi, did you make any progress on this?

Sadly no progress. I didn't find any documentation and differences. If anybody has some info or can try any kind of "post" request to the system would be amazing. Because I do not own AX Hub and I cannot test it.

It would be possible to test it with somebody live on discord or any other communicator. For such meeting please send me email to make it happen.

@petrleocompel
Copy link
Owner

Main bug found. Internal library has post instead of put. Also code is not being sent.

@petrleocompel petrleocompel reopened this Apr 14, 2023
@petrleocompel
Copy link
Owner

In this case Arm / disarm should be working from version 1.3.1.

@nautilus7
Copy link

Looking forward to it! Thanks.

@petrleocompel
Copy link
Owner

@nautilus7 you can test 1.3.1 it was released.
Currently i am looking in loading more data from it.

@nautilus7
Copy link

No it's not. You have forgotten to push the changes upstream, I guess.

@petrleocompel
Copy link
Owner

No it's not. You have forgotten to push the changes upstream, I guess.

https://github.com/petrleocompel/hikaxpro_hacs/releases/tag/v1.3.1

@petrleocompel
Copy link
Owner

Sorry my bad I really just released tag... 🤦‍♂️

petrleocompel added a commit that referenced this issue Apr 17, 2023
@nautilus7
Copy link

Yeah, me was looking in master branch commits only.

@petrleocompel
Copy link
Owner

Now it is released

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

No branches or pull requests

3 participants