guerrerotook / securitas-direct-new-api

This repository contains the new securitas direct API that can be integrated in Home Assistant
Apache License 2.0
79 stars 30 forks source link

cannot disarm #97

Closed finamix closed 1 year ago

finamix commented 1 year ago

Hi, the alarm does not disarm. all other functions are working.

This error originated from a custom integration.

Logger: custom_components.securitas.securitas_direct_new_api.apimanager Source: custom_components/securitas/securitas_direct_new_api/apimanager.py:193 Integration: Securitas Direct (documentation, issues) First occurred: 11:31:01 PM (1 occurrences) Last logged: 11:31:01 PM

Unauthorized

guerrerotook commented 1 year ago

The Unauthorized means that you need to make sure that you authorized your user, did you try to reboot the HA?

finamix commented 1 year ago

Hi thanks for the answer. I have in fact authorized my user, as I'm able to alarm the system (both full and partial modes), although the disarm function doesn't seem to be working at all. Any ideas? I've tried more than once uninstalling and installing back, but the problem persists.

alruallm commented 1 year ago

Hi first of all...Great work here!!! I have the same issue: Disarm not working, I had never used this integration before. HA (Docker Installation) logs says;

Logger: custom_components.securitas.securitas_direct_new_api.apimanager Source: custom_components/securitas/securitas_direct_new_api/apimanager.py:193 Integration: Securitas Direct (documentation, issues) First occurred: 17:58:34 (1 occurrences) Last logged: 17:58:34

Unauthorized

Logger: homeassistant Source: config_entries.py:1263 First occurred: 17:58:48 (2 occurrences) Last logged: 17:58:48

Error doing job: Task exception was never retrieved Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/config_entries.py", line 1263, in async_forward_entry_setup await entry.async_setup(self.hass, integration=integration) AttributeError: 'collections.OrderedDict' object has no attribute 'async_setup'

The user is configured can login in the app and do all the work fine (arm/disarm). I tried to reboot HA and after that I only receive a warning msg:

Logger: homeassistant.helpers.service Source: helpers/service.py:441 First occurred: 18:22:59 (1 occurrences) Last logged: 18:22:59

Unable to find services.yaml for the securitas integration

vixium commented 1 year ago

Hello,

Same here, I can arm both (full and partial) but I can not disarm the alarm. All the functions are working correctly (sentinel temp, hum and quality air) and check status or arm. Only disarm is not working.

LOG:

Logger: homeassistant.helpers.service Source: helpers/service.py:441 First occurred: 06:31:41 (1 occurrences) Last logged: 06:31:41

Unable to find services.yaml for the securitas integration

itadna commented 1 year ago

Hello everybody, very nice job and useful integration.

I can arm any piece of the alarm but noting happens if I try to deactivate the system.

So only disarming is not working.

Regards.

haas85 commented 1 year ago

Hello, I have the disarming issue too. In my logs I can see this line, which I do not know if it is related to the issue:

2022-12-28 10:34:41.828 WARNING (SyncWorker_3) [homeassistant.helpers.service] Unable to find services.yaml for the securitas integration

I have properly done the 2FA authentication And I can arm it properly, but as I said, disarming doesn't work for me. I will try to debug more to find out what is happening.

Thank you

guerrerotook commented 1 year ago

How are you trying to disarm the alarm? through the panel?

alruallm commented 1 year ago

How are you trying to disarm the alarm? through the panel?

In my case through the Lovelace card into home assistant.

vixium commented 1 year ago

How are you trying to disarm the alarm? through the panel?

I tried with the panel and with an automation... no effect on disarm.

haas85 commented 1 year ago

In my case through the panel and through HomeKit. I’m both arming it works, but disabling it doesn’t

El El mié, 28 dic 2022 a las 19:31, vixium @.***> escribió:

How are you trying to disarm the alarm? through the panel?

I tried with the panel and with an automation... no effect on disarm.

— Reply to this email directly, view it on GitHub https://github.com/guerrerotook/securitas-direct-new-api/issues/97#issuecomment-1366842918, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAJHOOJY67HIC2OCIEMENLDWPSBPLANCNFSM6AAAAAASGCYUQM . You are receiving this because you commented.Message ID: @.***>

jcorreaes commented 1 year ago

Same issue here. Arming is working but disarming seems to do nothing. No errors on the logs. Tried from developer tools, alarm panel card and node-red.

duquedaniel commented 1 year ago

Same issue on my side.

Gallach commented 1 year ago

Same here!

It may be related, when I reboot HA it always says that has descovered a new Securitas Direct Integration.

agaleraib commented 1 year ago

same here …

aitor3ml commented 1 year ago

Same here!

haas85 commented 1 year ago

@guerrerotook will it be useful for you if I send you what the web sends to the server in my case?

jsole commented 1 year ago

Same here, disarming is not working, but arming works fine. I tried it from the lovelace panel, calling the service from the developer tools and from my nodered automation with no luck.

joaodforce commented 1 year ago

Same issue here, arms fine but cannot disarm. At first I thought the issue was that I was using the "Guest" account, so I removed the integration and set it back up with the main account, but the results end up the same. Im using the BR region btw.

guerrerotook commented 1 year ago

Do you have any kind of logs or exceptions that you can see in? Search for securitas in the home-assistant.log file!

joaodforce commented 1 year ago

securitas

all there is on my home-assistant.log file related to securitas are the following lines

I've installed the integration manually since I don't use HACS, all I did was copy the securitas folder from the repo to the custom components directory. Is that enough?

2023-01-16 23:50:38.655 WARNING (SyncWorker_1) [homeassistant.loader] We found a custom integration securitas which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant

2023-01-16 23:50:57.056 WARNING (SyncWorker_0) [homeassistant.helpers.service] Unable to find services.yaml for the securitas integration
guerrerotook commented 1 year ago

Tudo bem João, looking at the logs, those are warning and those are ok. Nothing to worry about.

Did you try to execute the disarm operation and then see if you have any issue?

joaodforce commented 1 year ago

Tudo bem João, looking at the logs, those are warning and those are ok. Nothing to worry about.

Did you try to execute the disarm operation and then see if you have any issue?

I tried yes, I just tested it right now, I went to the integration and selected the option enable debug logging, armed the alarm, waited a couple of minutes then tried to disarm, I went to the Log files, Looked at the home-assistant.log file, the home-assistant.log.1 file and the home-assistant.log.fault file, none of them have anything related to securitas, this is very strange I'd expected at least some logging, Perhaps it is logging to someplace else?

The thing when I run the disarm flow, it seems like nothing happens, the Panel on lovelace UI doenst start flashing to indicate the operation is running like it happens when arming.

joaodforce commented 1 year ago

@guerrerotook I've captured a disarm payload sent from the browser, I've tried capturing from the iOS app, but HTTP Proxying is broken on iOS 16

See if that maybe helps.

{
  "operationName": "xSDisarmPanel",
  "variables": {
    "request": "DARM1",
    "numinst": "SECRETINSTALL",
    "panel": "SDVFAST",
    "currentStatus": "P"
  },
  "query": "mutation xSDisarmPanel($numinst: String!, $request: DisarmCodeRequest!, $panel: String!) {\n  xSDisarmPanel(numinst: $numinst, request: $request, panel: $panel) {\n    res\n    msg\n    referenceId\n  }\n}\n"
}
{
  "operationName": "DisarmStatus",
  "variables": {
    "request": "DARM1",
    "numinst": "SECRETINSTALL",
    "panel": "SDVFAST",
    "currentStatus": "P",
    "referenceId": "OWP_______________SECRET________________",
    "counter": 1
  },
  "query": "query DisarmStatus($numinst: String!, $panel: String!, $referenceId: String!, $counter: Int!, $request: DisarmCodeRequest) {\n  xSDisarmStatus(numinst: $numinst, panel: $panel, referenceId: $referenceId, counter: $counter, request: $request) {\n    res\n    msg\n    status\n    protomResponse\n    protomResponseDate\n    numinst\n    requestId\n    error {\n      code\n      type\n      allowForcing\n      exceptionsNumber\n      referenceId\n    }\n    exceptions {\n      status\n      deviceType\n      alias\n    }\n  }\n}\n"
}
guerrerotook commented 1 year ago

That is very strange, can I ask from which branch did you deploy the code?

The payload for the disarm alarm is already integrated in the code.

https://github.com/guerrerotook/securitas-direct-new-api/blob/3bd89bcd3af2721c6c753aa8f06dd1230617b31a/custom_components/securitas/securitas_direct_new_api/apimanager.py#L571

joaodforce commented 1 year ago

That is very strange, can I ask from which branch did you deploy the code?

The payload for the disarm alarm is already integrated in the code.

https://github.com/guerrerotook/securitas-direct-new-api/blob/3bd89bcd3af2721c6c753aa8f06dd1230617b31a/custom_components/securitas/securitas_direct_new_api/apimanager.py#L571

At first I cloned straight from the main branch, and then I tried with the 2.1.0.0 release tag. Got the same results with both.

It is very strange, perhaps the issue isn't the request itself, but some check or processing before it maybe.

Another thing I noticed is that, if I ARM the alarm via the integration, and then disarm via the remote, and then I go to the integration and ask to disarm, it will quickly update the status to DISARMED.

agaleraib commented 1 year ago

Hi Luis, I can confirm what João pointed out, no logs are recorded whatsoever when arming or attempting to disarm via panel or script. Nothing is logged in HA after enabling debug login.

Same behavior when attempting to disarm vi HA (nothing happens) and after disarming via Securitas Direct app and disarming again from HA, then the status refreshes immediately.

I am using version 2.1.0.0 installed via HACS Home Assistant 2023.1.1 Supervisor 2022.12.1 Operating System 9.4 Frontend 20230104.0 - latest

garybrowngeo commented 1 year ago

Same issue here. I have tried via Lovelace and directly by changing state in the entity itself still no DISARM. All other functions i.e. arming are fine. Tried removing the need for a code to see if this helped but still no joy. Anyone found a solution?

haas85 commented 1 year ago

Hello, after debugging the app I found why is not working for me, in control_panel you have this code to trigger the disarm_alarm method:

async def async_alarm_disarm(self, code=None):
        """Send disarm command."""
        if isinstance(code, str):
            code = int(code)
        if (
            self.client.config.get(CONF_CODE, "") == ""
            or self.client.config.get(CONF_CODE, "") == code
        ):
            self.__force_state(STATE_ALARM_DISARMING)
            await self.set_arm_state("DARM1")

I was trying to disarm the alarm typing and without typing the code and was not working. In my case the problem was that in the secret.yml I was putting the securitas direct code as string so the comparison was not working. So changing the code:

or self.client.config.get(CONF_CODE, "") == code to or str(self.client.config.get(CONF_CODE, "")) == str(code)

Makes that no matter how the data was added by users it will work.

Another thing is that I wanted to disarm my securitas direct alarm through IOS homekit. So I need to add to the if another code line:

self.client.config.get(CONF_CODE, "") == ""
or str(self.client.config.get(CONF_CODE, "")) == str(code)
or code == None

So in case no code is sent disarm the alarm too, which I do not like, but is the only way I found to make it work.

I hope this can help some of you

agaleraib commented 1 year ago

It works!!!

@haas85 you are awesome! thank you for sharing this fix with the rest of us :)

phnguy commented 1 year ago

So, are you going to deploy a new one or i have to clone it? Thanks for your work

haas85 commented 1 year ago

The solution I did is a bit ugly (not as good as I thunk for a PR) and I have a couple of ideas for the integration. But I do not have time to do it now. My advice is that you install the visual studio addon and copy the code I addED, Then restart the server and is done

phnguy commented 1 year ago

Using the last piece


code == None

worked for me

duquedaniel commented 1 year ago

It worked for me. Thanks.

From: Phi-Lay NGUYEN @.> Sent: 29 de janeiro de 2023 09:40 To: guerrerotook/securitas-direct-new-api @.> Cc: Daniel Duque @.>; Comment @.> Subject: Re: [guerrerotook/securitas-direct-new-api] cannot disarm (Issue #97)

Using the last piece code == None worked for me

- Reply to this email directly, view it on GitHubhttps://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fguerrerotook%2Fsecuritas-direct-new-api%2Fissues%2F97%23issuecomment-1407613234&data=05%7C01%7C%7Ca275d940841e48ec8c6308db01dcbdf5%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C638105819806076401%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=IGV0JJ7Nrcl1M3Q%2FHH335hTnjqMn%2FZUtvgT9jxcPLh8%3D&reserved=0, or unsubscribehttps://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FASQND4YXIMQJXFUN4J4SIQTWUY3FXANCNFSM6AAAAAASGCYUQM&data=05%7C01%7C%7Ca275d940841e48ec8c6308db01dcbdf5%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C638105819806076401%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=hqLwW3PiYzBM9sDMWn4SFU%2BpbAbLqzbmRzeoyItWOQo%3D&reserved=0. You are receiving this because you commented.Message ID: @.**@.>>

garybrowngeo commented 1 year ago

Look like it's not just if you use the secrets.yaml. If you use the UI to set-up the integration it also stores the code in core.config__entries as a string hence causing the the disarm code to fail to run. I updated the code directly in the alarm_control_panel.py with str(self.client.config.get(CONF_CODE, "")) == str(code) as suggested and it works! Thanks haas85!

joaodforce commented 1 year ago

Hello, after debugging the app I found why is not working for me, in control_panel you have this code to trigger the disarm_alarm method:

async def async_alarm_disarm(self, code=None):
        """Send disarm command."""
        if isinstance(code, str):
            code = int(code)
        if (
            self.client.config.get(CONF_CODE, "") == ""
            or self.client.config.get(CONF_CODE, "") == code
        ):
            self.__force_state(STATE_ALARM_DISARMING)
            await self.set_arm_state("DARM1")

I was trying to disarm the alarm typing and without typing the code and was not working. In my case the problem was that in the secret.yml I was putting the securitas direct code as string so the comparison was not working. So changing the code:

or self.client.config.get(CONF_CODE, "") == code to or str(self.client.config.get(CONF_CODE, "")) == str(code)

Makes that no matter how the data was added by users it will work.

Another thing is that I wanted to disarm my securitas direct alarm through IOS homekit. So I need to add to the if another code line:

self.client.config.get(CONF_CODE, "") == ""
or str(self.client.config.get(CONF_CODE, "")) == str(code)
or code == None

So in case no code is sent disarm the alarm too, which I do not like, but is the only way I found to make it work.

I hope this can help some of you

Good job figuring this out, Tested here and it works too, in my case I set it up via the UI, and after applying this patch it is now working.

I think this needs more treatment, like I don't know how HASS Alarm Control panel works, but I'd think that inputting a wrong password or no password should output an error or warning somewhere.

Now this unrelated to the issue, on my case if arming with a zone that is still open I get a service error, but the panel keeps on the "Arming" state indefinitely, not the cleanest solution, but its sort of usable.

Also @haas85 adding the or code == None to get it working with HomeKit is probably not the best option, I think you can add the code to the homeKit integration config so that the code will be injected to the service when controlling via HK.

But overall with this patch the integration is great. finally I dont have to fondle with the terrible verisure app anymore.

guerrerotook commented 1 year ago

Hello, after debugging the app I found why is not working for me, in control_panel you have this code to trigger the disarm_alarm method:

async def async_alarm_disarm(self, code=None):
        """Send disarm command."""
        if isinstance(code, str):
            code = int(code)
        if (
            self.client.config.get(CONF_CODE, "") == ""
            or self.client.config.get(CONF_CODE, "") == code
        ):
            self.__force_state(STATE_ALARM_DISARMING)
            await self.set_arm_state("DARM1")

I was trying to disarm the alarm typing and without typing the code and was not working. In my case the problem was that in the secret.yml I was putting the securitas direct code as string so the comparison was not working. So changing the code:

or self.client.config.get(CONF_CODE, "") == code to or str(self.client.config.get(CONF_CODE, "")) == str(code)

Makes that no matter how the data was added by users it will work.

Another thing is that I wanted to disarm my securitas direct alarm through IOS homekit. So I need to add to the if another code line:

self.client.config.get(CONF_CODE, "") == ""
or str(self.client.config.get(CONF_CODE, "")) == str(code)
or code == None

So in case no code is sent disarm the alarm too, which I do not like, but is the only way I found to make it work.

I hope this can help some of you

Thanks for finding the solution, do you think it make sense to integrate this into the code so everyone benefits from it? @haas85

haas85 commented 1 year ago

Hey @guerrerotook, form me makes sense doing the str change str(self.client.config.get(CONF_CODE, "")) == str(code)

The code === None code do not add it, it would be the same as not adding a CONF_CODE in the configuration file, and as @joaodforce pointed you can create a homekit brige with the pin code you configured so homekit uses the code:

For anyone who is in my situation (want to disarm the alarm from homekit too), you can create a homekit bridge with this configuration:

securitas:
  username: !secret securitas_direct_username
  password: !secret securitas_direct_password
  code: !secret securitas_direct_code
  country: ES

homekit:
  entity_config:
    alarm_control_panel.MY_SECURITAS_ALARM_ENTITY_ID:
      name: "Securitas direct"
      code: !secret securitas_direct_code