core: Simplisafe integration starts getting 401 errors

Home Assistant release with the issue: 0.92.1

Last working Home Assistant release (if known): UNKNOWN

Operating environment (Hass.io/Docker/Windows/etc.): hass.io raspberry pi 3B

Component/platform: https://www.home-assistant.io/components/simplisafe/ Setup through “Configuration/integrations”

Description of problem: Ive reset my entire home assistant setup a couple times now from a fresh hassio release and every time after a couple weeks of working perfectly it will stop getting updates and stop sending events and start getting this error:

There was error updating "MYADDRESS": Error requesting data from users/823242/subscriptions: 401, message='Unauthorized'

Problem-relevant configuration.yaml entries and (fill out even if it seems unimportant):


Traceback (if applicable):


Additional information:

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 58 (31 by maintainers)

Most upvoted comments

In correcting the unhandled exception, I think I also addressed a use case where the access token could be “corrupted” due to overlapping calls: #23680

Alright, I think I have something – my forthcoming PR should fall back to the refresh token stored in the HASS config directory (which always seems to be good since HASS restarts fix things) when we get in this strange loop.

Yep, I haven’t hit this lately, either - though I’ve had to restart HA a few times, so it may have just not reached the requisite time. Thanks for diving into this. I’ll keep an eye out for it in the future; leaving SimpliSafe in debug mode for now.

Well… This started happening to me, too. 😒I see these logs:

2019-11-13 16:34:17 ERROR (MainThread) [homeassistant.components.simplisafe] SimpliSafe error while updating "1234 Main Street": 
2019-11-13 16:34:48 ERROR (MainThread) [simplipy.api] Refresh token was unsuccessful on 401
2019-11-13 16:34:48 ERROR (MainThread) [simplipy.api] Refresh token was unsuccessful on 401
2019-11-13 16:34:48 ERROR (MainThread) [simplipy.api] Refresh token was unsuccessful on 401
2019-11-13 16:34:48 ERROR (MainThread) [homeassistant.components.simplisafe] SimpliSafe error while updating "1234 Main Street": 
2019-11-13 16:35:16 ERROR (MainThread) [simplipy.api] Refresh token was unsuccessful on 401
2019-11-13 16:35:16 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/simplipy/api.py", line 178, in request
    resp.raise_for_status()
  File "/usr/local/lib/python3.7/site-packages/aiohttp/client_reqrep.py", line 946, in raise_for_status
    headers=self.headers)
aiohttp.client_exceptions.ClientResponseError: 401, message='Unauthorized', url='https://api.simplisafe.com/v1/ss3/subscriptions/xxxxxxxx/state/away

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/core.py", line 1236, in async_call
    await asyncio.shield(self._execute_service(handler, service_call))
  File "/usr/src/homeassistant/homeassistant/core.py", line 1261, in _execute_service
    await handler.func(service_call)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 213, in handle_service
    self._platforms.values(), func, call, service_name, required_features
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 348, in entity_service_call
    future.result()  # pop exception if have
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 370, in _handle_service_platform_call
    await getattr(entity, func)(**data)
  File "/usr/src/homeassistant/homeassistant/components/simplisafe/alarm_control_panel.py", line 167, in async_alarm_arm_away
    await self._system.set_away()
  File "/usr/local/lib/python3.7/site-packages/simplipy/system.py", line 179, in set_away
    await self._set_state(SystemStates.away)
  File "/usr/local/lib/python3.7/site-packages/simplipy/system.py", line 457, in _set_state
    "post", f"ss3/subscriptions/{self.system_id}/state/{value.name}"
  File "/usr/local/lib/python3.7/site-packages/simplipy/api.py", line 184, in request
    raise InvalidCredentialsError
simplipy.errors.InvalidCredentialsError

Same story: after I restart HASS, everything starts working again. This tells me that the refresh token stored by HASS is still valid; it’s just not getting picked up when there’s an error. That gives me something to work with. More soon.

@bachya, I tried your steps above. I’m not a developer, so please bear with me if I’m missing anything obvious. I ended up running the example_sensor_properties.py example since I couldn’t find example.py. I’m not sure if it matters, but I don’t subscribe to SimpliSafe’s interactive monitoring. This has never caused issues using their iOS App or this Home Assistant component to read the current state of the alarm system.

When I did the test with no changes, I got this:

INFO:root:System ID: <PRIVATE> INFO:root:Version: 2 INFO:root:User ID: <PRIVATE> INFO:root:Access Token: <PRIVATE> INFO:root:Refresh Token: <PRIVATE> INFO:root:Number of Events: 50 ERROR:root:Cannot determine triggered state for sensor:

Got it – makes sense.

When I changed the connector type, I got this:

Traceback (most recent call last):
 File "example_sensors_properties.py", line 51, in <module>
   asyncio.get_event_loop().run_until_complete(main())
 File "/usr/lib/python3.6/asyncio/base_events.py", line 484, in run_until_complete
   return future.result()
 File "example_sensors_properties.py", line 19, in main
   async with ClientSession(connector=TCPConnector(verify_ssl=False)):
NameError: name 'TCPConnector' is not defined

At the moment I’m not getting any errors in the Home Assistant log. I restarted HA this morning when I changed the logging setting; based on previous experience I won’t start seeing this issue for a few days.

That’s my fault: I forgot to have you import that package. At any rate, that test was slightly flawed: since this error seems to manifest after a while, a one-off test wouldn’t show it.

Let’s let your system run for a bit and see what the logs say when the issue reoccurs. Thanks for your patience!

Sure thing. Before I clear the logs, here are the timestamps of the errors:

2019-10-27 23:48:19 ERROR (MainThread) [simplipy.api] Refresh token was unsuccessful on 401
2019-10-28 00:47:44 ERROR (MainThread) [simplipy.api] Refresh token was unsuccessful on 401
2019-10-28 01:47:07 ERROR (MainThread) [simplipy.api] Refresh token was unsuccessful on 401
2019-10-28 07:43:33 ERROR (MainThread) [simplipy.api] Refresh token was unsuccessful on 401
2019-10-28 10:41:43 ERROR (MainThread) [simplipy.api] Refresh token was unsuccessful on 401
2019-10-28 12:40:32 ERROR (MainThread) [simplipy.api] Refresh token was unsuccessful on 401
2019-10-28 16:38:06 ERROR (MainThread) [simplipy.api] Refresh token was unsuccessful on 401
2019-10-28 20:35:41 ERROR (MainThread) [simplipy.api] Refresh token was unsuccessful on 401
2019-10-28 21:35:06 ERROR (MainThread) [simplipy.api] Refresh token was unsuccessful on 401
2019-10-28 23:33:56 ERROR (MainThread) [simplipy.api] Refresh token was unsuccessful on 401
2019-10-29 05:30:22 ERROR (MainThread) [simplipy.api] Refresh token was unsuccessful on 401
2019-10-29 08:28:35 ERROR (MainThread) [simplipy.api] Refresh token was unsuccessful on 401
2019-10-29 17:23:11 ERROR (MainThread) [simplipy.api] Refresh token was unsuccessful on 401
2019-10-29 21:20:47 ERROR (MainThread) [simplipy.api] Refresh token was unsuccessful on 401
2019-10-30 02:17:46 ERROR (MainThread) [simplipy.api] Refresh token was unsuccessful on 401
2019-10-30 07:14:48 ERROR (MainThread) [simplipy.api] Refresh token was unsuccessful on 401
2019-10-30 16:09:25 ERROR (MainThread) [simplipy.api] Refresh token was unsuccessful on 401

Got it! Once this fix is officially released, give it a try and let me know how you get on.

I actually never tried to just restart to fix it… 🤦 once i restart it works hahah thank you so much!! And thank you for the fixes!! Its so cool to have everything integrated with my alarm system!

Thanks, @kevindurb. RE: the 401 errors, do you get several in a row? How long does “it will stop getting updates and stop sending events” last before you have to restart?

RE: 500 errors, that will happen from time to time – that’s 100% on SimpliSafe’s cloud. That said, I should handle the exception properly.