Web api actions not reliable

I have implemented a Nuki app in Appdaemon for Home Assistant. However, I am having real issues with the Web API. Often after sending a command, nothing happens. I have thus already implemented a loop, which should really not be needed, but even then I have issues.

For example, the log from last night:

2020-04-23 23:20:52.265130 INFO Nuki: lock_door_event: input_boolean.night
2020-04-23 23:20:52.272324 INFO Nuki: lock_door_action
2020-04-23 23:21:02.018549 INFO Nuki: lock_door_action
2020-04-23 23:21:02.125474 INFO Nuki: lock_door_repeat: try: 0, r.status_code: 423
2020-04-23 23:21:12.036646 INFO Nuki: lock_door_action
2020-04-23 23:21:12.143880 INFO Nuki: lock_door_repeat: try: 1, r.status_code: 423
2020-04-23 23:21:22.027391 INFO Nuki: lock_door_action
2020-04-23 23:21:22.131888 INFO Nuki: lock_door_repeat: try: 2, r.status_code: 423
2020-04-23 23:21:32.036903 INFO Nuki: lock_door_action
2020-04-23 23:21:32.173512 INFO Nuki: lock_door_repeat: try: 3, r.status_code: 423
2020-04-23 23:21:42.034066 INFO Nuki: lock_door_action
2020-04-23 23:21:42.139362 INFO Nuki: lock_door_repeat: try: 4, r.status_code: 204

When I go to bed, the Nuki should lock. The first attempt (lock_door_action) doesn’t result in a locked or locking state, thus it tries again. Notice the resulting status codes.

Even after attempt 5, the door was still not locked, and by then it gives up. So the door remains unlocked over night.

The lock door action basically does:

hed = {‘Authorization’: 'Bearer ’ + self.auth_token}
data = {‘action’: action}
url = ‘https://api.nuki.io/smartlock/507613268/action
r = requests.post(url, json=data, headers=hed)

With action = 2 in this case.

I am seeing similar effects with unlocking as well as with the Opener RTO. Any idea what’s going on here and/or how to fix this?

Error code 423 means that the lockAction could not be triggered (process “locked”); so in your case only try 4 really went through (and I can not say frmo this lock why this also not worked). As you already have 10 seconds delay I am not sure what caused this. Are there any calls to the API you did inbetween?

Ok I have enabled email notifications now…figured no one had replied.

Thanks for your swift reply, I actually have a rolling 1-sec status loop that checks for the lock and opener status. From your reply I take it this could be interfering with the lock/unlock calls. I would have to rewrite the app in that case, so the status loop pauses or something when I need to perform an action…

This does appear to work better after the rewrite, but still testing.

I do have another issue. I am polling the Opener status:

2020-04-29 11:24:51.158536 INFO Nuki: nuki_opener_status: 3
2020-04-29 11:24:51.264517 INFO Nuki: nuki_opener_status: 3
2020-04-29 11:24:53.117159 INFO Nuki: nuki_opener_status: 3
2020-04-29 11:24:55.120979 INFO Nuki: nuki_opener_status: 3

This means “RTO active”. This has been the status for many hours now. Opening the IOS App, Nuki correctly tells me that the Opener is “online”, and not “RTO active”. Why this mismatch, and how do I solve it?