I have problems when disarming Alarmo. Both when using the common disarm service and the specific alarmo disarm service it takes 3-4 seconds until it is actually disarmed. I don’t have any other issues with HA being slow. Have just used HA for a couple of months and think I have had the issue the whole time.
What’s those 4 sekunder (seconds) later?
alias: Keypaden - Avlarma från keypaden
trigger:
- platform: mqtt
topic: zigbee2mqtt/Keypaden
condition:
- condition: template
value_template: '{{ trigger.payload_json.action == ''disarm'' }}'
- condition: or
conditions:
- condition: state
entity_id: alarm_control_panel.master
state: armed_custom_bypass
- condition: state
entity_id: alarm_control_panel.master
state: armed_away
- condition: state
entity_id: alarm_control_panel.master
state: triggered
- condition: state
entity_id: alarm_control_panel.master
state: arming
- condition: state
entity_id: alarm_control_panel.master
state: armed_night
- condition: state
entity_id: alarm_control_panel.master
state: pending
action:
- service: alarmo.disarm
data:
entity_id: alarm_control_panel.master
code: '{{ trigger.payload_json.action_code }}'
mode: single
I’ve got some automation triggered by the alarm being disarmed, so those extra three seconds are disturbing. Any suggestions how to solve it?
HA 2021.6.5
I know this is ancient, but I found this because I’m running into the same issue.
I believe this is due to the way Alarmo checks the code against its user database, and happens when there is a large(ish) amount of users/codes defined.
opened 12:44AM - 27 Nov 24 UTC
bug
### Checklist
- [X] I am using the latest version of Alarmo (latest version can… be found [here](https://github.com/nielsfaber/alarmo/releases/latest))
- [X] I checked for similar existing requests (both open and closed) before posting.
### Alarmo Version
v1.10.7
### HA Version
2024.11.3
### Bug description
Calls to `alarmo.disarm` can take several seconds if there are multiple codes/users defined. I'm seeing ~6s for 13 users/codes.
How long it takes depends on which user's code is being checked.
I suspect this is because [this code](https://github.com/nielsfaber/alarmo/blob/64368ff62b8e7452f45e0fda414a5652a1403be4/custom_components/alarmo/__init__.py#L280) checks users in sequence. If the supplied code belongs to a user that's far down in the list (depending on order in which they were added?), a lot of `bcrypt.checkpw()` iterations are performed sequentially, which can be slow especially if running on an RPi.
Perhaps something like this could work?
```
def async_authenticate_user(self, code: str, user_id: str = None):
users = ...
def check_pw(user):
if not user[const.ATTR_ENABLED]:
continue
elif not user[ATTR_CODE] and not code:
return user
if bcrypt.checkpw(code.encode("utf-8"), base64.b64decode(user[ATTR_CODE]):
return user
with multiprocessing.Pool() as p:
for user in p.imap(check_pw, users.itervalues()):
if user: return user
return
```
Similar [report](https://community.home-assistant.io/t/call-disarm-service-takes-long-time/316343)
### Steps to reproduce
* add a generous amount of users, each with their unique code, to alarmo (~20 should do)
* call disarm with the code of the last user added
### Relevant log output
_No response_