Verisure - enable/disable Auto-lock on Yale Doorman

Hi,

I was wondering if it would be possible to have the Verisure component support the enabling and disabling of the “Auto-lock” feature. It is possible to do so in HomeBridge which seems to be using the same underlying python script by @persandstrom as HomeAssistant seems to be using.

I would be great if a switch could be created in HA to allow for the Auto-lock feature to be enabled and disabled.

The HomeBridge integration of the Auto-lock can be found here:

Thanks in advance.

Hi,

The code is in the verisure lib, so it is a quite easy task to add the functionality to home assistant. I don’t have the locks myself though so it would be good if someone who can test it did the implementable.

I might have look at in a while if no one else can and someone volunteers to test.

/Per

I can do whatever testing you’d like, I just cannot do the implementation as that’s outside my capabilities.

Let me know if there’s anything I can do to assist.

I second that… I can contribute with the testing.

Also very interested in that feature.
I’m using HA to to create a bridge between the KNX-bus and the Yale Doorman and it would be nice to be able to activate/deactivate auto-lock with a KNX-telegram.

Hi Per,

Would you have time to look into this now? Doesn’t seem like anyone else is picking it up.
I’ll be happy to assist in whatever way I can.

1 Like

Hi,

I have added two new services to verisure:

  • disable_autolock
  • enable_autolock

Please test my branch “verisure_autolock_service” to see if it works as expected
https://github.com/persandstrom/home-assistant/tree/verisure_autolock_service

Hi,

Sorry, I missed that you created this, thanks a lot.

I’m running Hassio, so I’m not able to test you build(as far as I know), but I copied the “verisure” folder from your branch into my “custom_components” and I know have two services named “verisure.disable_autolock” and “verisure.enable_autolock”. I’m not sure how to get these into a button in the lovelace UI(or any other UI), or into Homekit on my Iphone?

I tried calling the service from HA->Developers tools. Calling the service without any “Service data” gives me the error required key not provided @ data['device_serial']
Calling the service with “Service data” { "device_serial": "12345" } gives me the error name 'hub' is not defined
Stack trace:

2019-08-16 12:09:27 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection.140094251033040] name 'hub' is not defined
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 128, in handle_call_service
    connection.context(msg),
  File "/usr/src/homeassistant/homeassistant/core.py", line 1235, in async_call
    await asyncio.shield(self._execute_service(handler, service_call))
  File "/usr/src/homeassistant/homeassistant/core.py", line 1262, in _execute_service
    await self._hass.async_add_executor_job(handler.func, service_call)
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/verisure/__init__.py", line 103, in disable_autolock
    HUB.disable_autolock(device_id)
  File "/config/custom_components/verisure/__init__.py", line 197, in disable_autolock
    hub.session.set_lock_config(device_id, auto_lock_enabled=False)
NameError: name 'hub' is not defined

Please let me know if I’m doing anything wrong or if you need stack traces or anything.

Thanks for the help

Hi again,

I created a VM with HA from your branch, but I’m still getting the same errors. Not sure what’s going on.

Let me know if/when I should update HA with something from your branch.

I also tried changing line 197 from
hub.session.set_lock_config(device_id, auto_lock_enabled=False) to HUB.session.set_lock_config(device_id, auto_lock_enabled=False) (also tried self.session.set_lock_config(device_id, auto_lock_enabled=False)) but then I get this error:

2019-08-16 16:08:28 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection.140225954784984] Expecting value: line 1 column 1 (char 0)
Traceback (most recent call last):
  File "/opt/homeassistant/lib64/python3.6/site-packages/homeassistant/components/websocket_api/commands.py", line 121, in handle_call_service
    connection.context(msg))
  File "/opt/homeassistant/lib64/python3.6/site-packages/homeassistant/core.py", line 1150, in async_call
    self._execute_service(handler, service_call))
  File "/opt/homeassistant/lib64/python3.6/site-packages/homeassistant/core.py", line 1174, in _execute_service
    await self._hass.async_add_executor_job(handler.func, service_call)
  File "/opt/rh/rh-python36/root/usr/lib64/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/opt/homeassistant/lib64/python3.6/site-packages/homeassistant/components/verisure/__init__.py", line 103, in disable_autolock
    HUB.disable_autolock(device_id)
  File "/opt/homeassistant/lib64/python3.6/site-packages/homeassistant/components/verisure/__init__.py", line 197, in disable_autolock
    HUB.session.set_lock_config(device_id, auto_lock_enabled=False)
  File "/opt/homeassistant/lib64/python3.6/site-packages/verisure/session.py", line 394, in set_lock_config
    _validate_response(response)
  File "/opt/homeassistant/lib64/python3.6/site-packages/verisure/session.py", line 16, in _validate_response
    raise ResponseError(response.status_code, response.text)
  File "/opt/homeassistant/lib64/python3.6/site-packages/verisure/session.py", line 43, in __init__
    self.text = json.loads(text)
  File "/opt/rh/rh-python36/root/usr/lib64/python3.6/json/__init__.py", line 354, in loads
    return _default_decoder.decode(s)
  File "/opt/rh/rh-python36/root/usr/lib64/python3.6/json/decoder.py", line 339, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/opt/rh/rh-python36/root/usr/lib64/python3.6/json/decoder.py", line 357, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Thanks
//Morten

Hi again,

Did some more testing, and the error I got when changing line 197 to self.session.set_lock_config(device_id, auto_lock_enabled=False) turned out to be because my user did not have access on my verisure installation to change the Autolock feature. I got a 403(Forbidden) back from verisure, but for some reason HA/the verisure component is not able to handle the reply.

As soon as I changed the permissions for my user on my verisure setup, and changed line 197 and 201 from hub. to self. , your services started to work.
Please let me know if there’s anything else I should/could do to help.

Hi Per,

Any news on my findings, and if/when this will be merged into Home assistant?

Hi Morten

Sorry, didn’t get any notifications from you previous messages, and had totally forgot about this.

I have created a PR now, is it possible for you to verify that the changes you made to make it to work are there?

https://github.com/home-assistant/home-assistant/pull/27366

BR
Per

Hi Per,

Looks good to me.

Did you look into why the code does not handle the 403 respons form Verisure?

Thanks.

I have added exception handling as well, would it be possible for you to test the PR @migselv ?

Hi Per,

I’ll be happy to test it. Will do it over the weekend.

Another Newbie question…
If I want to have a button/switch in HA that can enable and disable the Autolock feature on the Doorman, how do I do that with the services you have created? Just like I have a switch to turn on and off my lights, I’d like to have the same for the Autolock feature.

Thanks.

Hi Per,

Did some testing, and it does not seem to work :frowning:

I just copied in your new __init__.py file(No other files has changed have they) into my custom_components/verisure folder where your older version resides, and I keep getting an “Unauthorized” error when trying to enable or disable the autolock.
If I copy in your old __init__.py and restart HA, then it works, so I know it has nothing to do with my verisure user/setup.

This is the error I see in the HA log:

2019-10-15 07:39:41 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.140327331212432] Received {'type': 'call_service', 'domain': 'verisure', 'service': 'enable_autolock', 'service_data': {'device_serial': 'XXXX XXXX'}, 'id': 18}
2019-10-15 07:39:41 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: domain=verisure, service=enable_autolock, service_data=device_serial=XXXX XXXX>
2019-10-15 07:39:41 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection.140327331212432] Unauthorized
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 133, in handle_call_service
    connection.context(msg),
  File "/usr/src/homeassistant/homeassistant/core.py", line 1233, in async_call
    await asyncio.shield(self._execute_service(handler, service_call))
  File "/usr/src/homeassistant/homeassistant/core.py", line 1258, in _execute_service
    await handler.func(service_call)
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 447, in check_permissions
    perm_category=CAT_ENTITIES,
homeassistant.exceptions.Unauthorized: Unauthorized
2019-10-15 07:39:41 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.140327331212432] Sending {'id': 18, 'type': 'result', 'success': False, 'error': {'code': 'home_assistant_error', 'message': 'Unauthorized'}}

It seems to be related to a function outside the verisure component? I’m running the service call from the UI with an HA administrator account, and it’s the same account I use when it suceeds when using your old version of __init__.py. So I’m not sure what’s going on.

Please let me know if there’s some more log files you need or something else I should do.

Did some more testing, and turns out it works if I comment out @verify_domain_control(hass, DOMAIN) on line 112 and 126. I do not know what that function does, or how to assign permissions so that call will return true.

Hi Per,

Any news on my findings during my testing?

Yes, I managed to get the same error, but I do not know how to solve it. I need to get help from someone who understands the new permissions feature. I will try to request help again.

I have not received any help on the unauthorized issue so I have removed the authorization check, please test again too see that it works. If it works I’ll merge it.

@migselv have you been able to test?