Securitas Direct (Verisure EU) Custom Component [TESTERS WANTED]

I’m going to try to develope a component based on mobile api from cebeerre

1 Like

Published the first python version based on the great cebeerre work…

1 Like

So, is it possible to add it to Hassio?

I am working on it.

1 Like

Tested the Python script for Spain and worked :grinning:

If someone can add it to Home Assistant in the future it will be very useful for some automations :smiley:

I am proud to anounce a first version of a custom component for securitas direct alarm.

Just copy custom_components folder inside your homeassistant config folder, configure your configuration.yalm with config below, and restart HA.

# Include this part in your configuration.yaml changing username, password and code.
# Remember to mark all your controls (remotes and keys) to be tracked, in order to 
# ensure synchronization between this alarm_control_panel and real securitas alarm


securitas_direct:
  username: your_securitas_username
  password: your_securitas_password
  code: 1234
  country: ES

Please, could be great request for people in other countries and/or with more than one alarm, and other elements like perimeter etc., to improve this integration.

Thanks for all (specially to @Cebeerre)

Outstanding job. Great contribution. I am already adding this to my HA.

Hello,

Tanks for you contribution.

I’m a problem on start my homeassistant

Traceback (most recent call last):
  File "/homeassistant/homeassistant/lib/python3.7/site-packages/homeassistant/helpers/entity_platform.py", line 150, in _async_setup_platform
    await asyncio.wait_for(asyncio.shield(task), SLOW_SETUP_MAX_WAIT)
  File "/usr/lib/python3.7/asyncio/tasks.py", line 409, in wait_for
  File "/homeassistant/homeassistant/lib/python3.7/site-packages/homeassistant/setup.py", line 171, in _async_setup_component
    component.setup, hass, processed_config  # type: ignore
  File "/usr/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/homeassistant/homeassistant/.homeassistant/custom_components/securitas_direct/__init__.py", line 65, in setup
    HUB.update_overview()
  File "/homeassistant/homeassistant/lib/python3.7/site-packages/homeassistant/util/__init__.py", line 240, in wrapper
    result = method(*args, **kwargs)
  File "/homeassistant/homeassistant/.homeassistant/custom_components/securitas_direct/__init__.py", line 109, in update_overview
    self.overview = self.session.last_state()
  File "/homeassistant/homeassistant/.homeassistant/custom_components/securitas_direct/securitas.py", line 107, in last_state
    res = self._api_requests('ACT_V2',timefilter=2,activityfilter=0)
  File "/homeassistant/homeassistant/.homeassistant/custom_components/securitas_direct/securitas.py", line 57, in _api_requests
    sys.exit(json.dumps(res,indent=2))
SystemExit: {
  "PET": {
    "RES": "KO",
    "ERR": "60057",
    "MSG": "El usuario introducido no existe",
    "BLOQ": {
      "@remotereqactive": "1",
      "#text": "Estamos mejorando nuestros servicios. Por favor intentelo de nuevo mas tarde. Gracias por confiar en Securitas Direct"
    }
  }
}

See the message
“El usuario introducido no existe”,

You have to set your proper username and password

Thanks for reply.

My username and password is valid.

I am french user.
https://customers.securitasdirect.fr/

Sorry. Seems that we need to discover the Baseurl for france mobile api.
This code is based on mobile api. It works faster and better than Web access, but seems we need to discover the Base url for every country.

Maybe could be possible discover base url with some tcpump / ethereal filtering dns request from mobile over wifi.

I reverse engenering “My verisure” Android app.

I found two connections to two IP address :
188.94.56.137:12010
188.94.58.195:12010

and i’m check openssl connect to found url :

openssl s_client -connect 188.94.56.137:12010
CONNECTED(00000005)
depth=2 C = US, O = DigiCert Inc, OU = www.digicert.com, CN = DigiCert Global Root CA
verify return:1
depth=1 C = US, O = DigiCert Inc, CN = DigiCert SHA2 Secure Server CA
verify return:1
depth=0 C = ES, L = Pozuelo de Alarcon, O = Securitas Direct Espana S.A.U, CN = mob2217.securitasdirect.es

URL is mob2217.securitasdirect.es yet it does not work

The connection works

i edited this files

init.py : Line 41

                vol.Optional(CONF_COUNTRY,default="FR"): cv.string,

securitas.py : Line 43

    def __init__(self, user, pwd, country="FR", lang="fr" ):

Now I have new error

2019-10-30 22:17:02 ERROR (MainThread) [homeassistant.helpers.entity] Update for alarm_control_panel.securitas_*****fails
Traceback (most recent call last):
  File "/homeassistant/homeassistant/lib/python3.7/site-packages/homeassistant/helpers/entity.py", line 270, in async_update_ha_state
    await self.async_device_update()
  File "/homeassistant/homeassistant/lib/python3.7/site-packages/homeassistant/helpers/entity.py", line 450, in async_device_update
    await self.hass.async_add_executor_job(self.update)
  File "/usr/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/homeassistant/homeassistant/.homeassistant/custom_components/securitas_direct/alarm_control_panel.py", line 116, in update
    if status['@type'] in ("1","32"):
TypeError: 'NoneType' object is not subscriptable

I’m tried securitas.py script available in your repository github.

I have edit this line :

    def __init__(self, user, pwd, country="FR", lang="fr" ):

and launch script

./securitas.py <USERNAME> <PASSWORD> ACT_V2
{
  "PET": {
    "RES": "OK",
    "LIST": {
      "@totalreg": "2",
      "@costtotal": "0",
      "REG": [
        {
          "@alias": "Consultation d'\u00e9tat",

The one is working properly.
I hope that my tests will help solve e bug.

Once again thank you for this work

Sorry about that. I firget mention “country” parameter in yaml.
You could try

country: FR

In yaml, without modify code.

i have tried to add country parameter in configuration.yaml and i have always this error

  File "/homeassistant/homeassistant/.homeassistant/custom_components/securitas_direct/alarm_control_panel.py", line 116, in update
    if status['@type'] in ("1","32"):
TypeError: 'NoneType' object is not subscriptable

Sorry about that, @azrod … I cant test other countries.

Please could you change init.py file

From this:

        self.session = securitas.SecuritasAPIClient(
            domain_config[CONF_USERNAME],
            domain_config[CONF_PASSWORD],
            domain_config[CONF_COUNTRY]
        )

to this:

        self.session = securitas.SecuritasAPIClient(
            domain_config[CONF_USERNAME],
            domain_config[CONF_PASSWORD],
            country=domain_config[CONF_COUNTRY].upper(),
            lang=domain_config[CONF_COUNTRY].lower()
        )

And configuration.yaml:

securitas_direct:
  username: your_securitas_username
  password: your_securitas_password
  code: 1234
  country: FR

After modifying the init.py file, I still have this error

  File "/homeassistant/homeassistant/.homeassistant/custom_components/securitas_direct/alarm_control_panel.py", line 116, in update
    if status['@type'] in ("1","32"):
TypeError: 'NoneType' object is not subscriptable

that’s it works!

I had not interacted with the alarm since the implementation of the custom_components suddenly the script had no data to recover.

Thanks you !

Ok… I think I can figure where is the error.
The short answer is:

  • under keys and remotes (on your mobile app), enable “following” or reporting all of them.
  • arm and disarm the alarm with some of them, and see how it is automatically refreshed in HA.

The long answer:
I need to explain a little how this integration works.

Securitas platform dont have an elegant kind to get synchroniced with the real state of the alarm. There are only one command to get real state: ‘EST’. But this command to the frontend make a real request from the backend to the alarm. Probably you could not poll ‘EST’ command every 30 seconds because the system it is not prepared for that, and we could down all the system.

But there are another command to get a log of latest commands: ‘ACT_V2’ that give you all registered past commands (ex.in last 2 days), without make a real request to the alarm, so its supposed to work fine with poll every 30 seconds.

This is what this integration do: If all the keys and remotes report enable or disable alarm, we can suppose the last state of the alarm, and sync the HA alarm_control_panel with the real securitas-verisure alarm.

The error what you are seen is because on the log (ACT_V2) there are no register about the alarm state.

I will try to modify this, and when no register state is available and state are unknown make a ‘EST’ command.