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

Sweden/Verisure not working - could any "default" locations possibly be working?! #260

Closed
kribjo opened this issue Dec 30, 2024 · 2 comments

Comments

@kribjo
Copy link

kribjo commented Dec 30, 2024

Background
The private alarm system business of Securitas Direct in Sweden is since some time (years) transferred to Verisure. AFAIK Securitas Direct is a part of the Verisure corporate group. Securitas Direct is still used in Sweden as a brand but not for the consumer market.
I had Home Assistant working with Verisure's system some 1-2 years ago, though I don't remember the details of how I set it up. I was only trying out Home Assistant for a short time then and have not used it anymore until I bought a HA Green a couple of days ago and have now set up HA to work nicely with everything I want except Verisure.

Issue
So it seemed this repository/integration was my best bet (or?!) and I have set things up but I can't get it to log in and connect to my Verisure account.

Documentation reference:

Country Code. One of BR (Brasil), CL (Chile), ES (Spain), FR (France), GB (Great Britain), IE (Ireland), IT (Italy). If you are outside of those countries, try entering "default" and if that doesn't work open an issue to see if we can expand.

Since I am in Sweden I have tried with "default" country code but immediately after submitting the login information I get "Unknown error occurred". It does not matter if I have checked "Use 2FA" or not.

The errors I see in HA logs make me wonder if the "default" thing could be working for anyone at all?

Judging from the logs it seems that the problem that happens now is that it tries to connect to the address customers.securitasdirect.default which I can't imagine is expected to resolve.
Also noteworthy is that for Sweden the web access pages are now based at https://mypages.verisure.com/.

I also note that based on the page https://mypages.verisure.com/ it seems that all countries other than SE/FI/DK/NL/DE/NO/FR/BE/UK are sent to https://customers.securitasdirect.es/owa-static/login , while those mentioned are sent to https://mypages.verisure.com/login . Would this imply that the same solution should work, or perhaps not work, for all the mentioned countries?

Logs included below. I redacted some information that did not seem wise to post publicly.

Logger: aiohttp.server
Source: /usr/local/lib/python3.13/site-packages/aiohttp/web_protocol.py:451
First occurred: 5:48:09 PM (3 occurrences)
Last logged: 5:52:27 PM

Error handling request
Traceback (most recent call last):
File "/usr/local/lib/python3.13/site-packages/aiohttp/resolver.py", line 103, in resolve
resp = await self._resolver.getaddrinfo(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...<5 lines>...
)
^
aiodns.error.DNSError: (11, 'Could not contact DNS servers')

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/usr/local/lib/python3.13/site-packages/aiohttp/connector.py", line 1351, in _create_direct_connection
hosts = await self._resolve_host(host, port, traces=traces)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.13/site-packages/aiohttp/connector.py", line 995, in _resolve_host
return await asyncio.shield(resolved_host_task)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.13/site-packages/aiohttp/connector.py", line 1026, in _resolve_host_with_throttle
addrs = await self._resolver.resolve(host, port, family=self._family)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.13/site-packages/aiohttp/resolver.py", line 112, in resolve
raise OSError(None, msg) from exc
OSError: [Errno None] Could not contact DNS servers

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/config/custom_components/securitas/securitas_direct_new_api/apimanager.py", line 152, in _execute_request
async with self.http_client.post(
~~~~~~~~~~~~~~~~~~~~~^
self.api_url, headers=headers, json=content
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
) as response:
^
File "/usr/local/lib/python3.13/site-packages/aiohttp/client.py", line 1425, in aenter
self._resp: _RetType = await self._coro
^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.13/site-packages/aiohttp/client.py", line 703, in _request
conn = await self._connector.connect(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
req, traces=traces, timeout=real_timeout
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "/usr/local/lib/python3.13/site-packages/aiohttp/connector.py", line 548, in connect
proto = await self._create_connection(req, traces, timeout)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.13/site-packages/aiohttp/connector.py", line 1056, in _create_connection
_, proto = await self._create_direct_connection(req, traces, timeout)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.13/site-packages/aiohttp/connector.py", line 1357, in _create_direct_connection
raise ClientConnectorDNSError(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorDNSError: Cannot connect to host customers.securitasdirect.default:443 ssl:default [Could not contact DNS servers]

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/config/custom_components/securitas/securitas_direct_new_api/apimanager.py", line 285, in validate_device
response = await self.execute_request(content, "mkValidateDevice")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/securitas/securitas_direct_new_api/apimanager.py", line 157, in execute_request
raise SecuritasDirectError(
f"Connection error with URL {self.api_url}", None, headers, content
) from err
custom_components.securitas.securitas_direct_new_api.exceptions.SecuritasDirectError: ('Connection error with URL https://customers.securitasdirect.DEFAULT/owa-api/graphql', None, {'app': '{"appVersion": "10.102.0", "origin": "native"}', 'User-Agent': 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.124 Safari/537.36 Edg/102.0.1245.41', 'X-APOLLO-OPERATION-ID': 'REDACTED OPERATIONID', 'X-APOLLO-OPERATION-NAME': 'mkValidateDevice', 'extension': '{"mode":"full"}', 'auth': '{"loginTimestamp": 0, "user": "REDACTED EMAIL", "id": "OWA
_____________REDACTED EMAIL_______________202412301748157039", "country": "DEFAULT", "lang": "en", "callby": "OWA_10", "hash": "", "refreshToken": ""}'}, {'operationName': 'mkValidateDevice', 'variables': {'idDevice': 'REDACTED DEVICEID', 'idDeviceIndigitall': '', 'uuid': 'REDACTED UUID', 'deviceName': 'SM-S901U', 'deviceBrand': 'samsung', 'deviceOsVersion': '12', 'deviceVersion': '10.102.0'}, 'query': 'mutation mkValidateDevice($idDevice: String, $idDeviceIndigitall: String, $uuid: String, $deviceName: String, $deviceBrand: String, $deviceOsVersion: String, $deviceVersion: String) {\n xSValidateDevice(idDevice: $idDevice, idDeviceIndigitall: $idDeviceIndigitall, uuid: $uuid, deviceName: $deviceName, deviceBrand: $deviceBrand, deviceOsVersion: $deviceOsVersion, deviceVersion: $deviceVersion) {\n res\n msg\n hash\n refreshToken\n legals\n }\n}\n'})

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/usr/local/lib/python3.13/site-packages/aiohttp/web_protocol.py", line 480, in _handle_request
resp = await request_handler(request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.13/site-packages/aiohttp/web_app.py", line 569, in _handle
return await handler(request)
^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.13/site-packages/aiohttp/web_middlewares.py", line 117, in impl
return await handler(request)
^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 92, in security_filter_middleware
return await handler(request)
^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 83, in forwarded_middleware
return await handler(request)
^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 26, in request_context_middleware
return await handler(request)
^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 86, in ban_middleware
return await handler(request)
^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 242, in auth_middleware
return await handler(request)
^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/components/http/headers.py", line 32, in headers_middleware
response = await handler(request)
^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/http.py", line 73, in handle
result = await handler(request, **request.match_info)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/components/http/decorators.py", line 81, in with_admin
return await func(self, request, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 222, in post
return await super().post(request, flow_id)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/components/http/data_validator.py", line 74, in wrapper
return await method(view, request, data, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 122, in post
result = await self._flow_mgr.async_configure(flow_id, data)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 367, in async_configure
result = await self._async_configure(flow_id, user_input)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 414, in _async_configure
result = await self._async_handle_step(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
flow, cur_step["step_id"], user_input
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 517, in _async_handle_step
result: _FlowResultT = await getattr(flow, method)(user_input)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/securitas/config_flow.py", line 157, in async_step_user
] = await self.securitas.validate_device()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/securitas/init.py", line 357, in validate_device
return await self.session.validate_device(False, None, None)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/securitas/securitas_direct_new_api/apimanager.py", line 289, in validate_device
data = err.args[1]["errors"][0]["data"]
~~~~~~~~~~~^^^^^^^^^^
TypeError: 'NoneType' object is not subscriptable

@guerrerotook
Copy link
Owner

Hey @kribjo, thanks for sharing this detailed investigation. As you mention in your post, this is the repository for the new API and I don't know if the same API/Operations are being used.

Can you spend some time here, https://github.com/guerrerotook/securitas-direct-new-api/blob/main/docs/how_to_capture.md and you can gather a little bit of what kind of API this web site has?

Please be mindful of not sharing any logs that may contains user name and passwords.

Thanks.

@kribjo
Copy link
Author

kribjo commented Jan 3, 2025

I actually just got this to work with the core Verisure integration, thanks to a hint from another user in my country that the password cannot be too long... I guess that probably indicates that all Verisure users who log in through https://mypages.verisure.com/ should use the core Verisure integration.

The fix for me was to change my long and secure password to just using a-zA-Z0-9 and shorten it a bit.

Sorry for wasting your time here. I hope my tale can be of use for others in the future.

See also:
home-assistant/core#99507

@kribjo kribjo closed this as completed Jan 3, 2025
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

2 participants