@bachya - did a somewhat recent change (something between 0.106.* and 0.107.7) switch the SimpliSafe API to WebSocket from polling?
I’ve noticed quicker response time to state changes (awesome!), but I’ve also seen more frequent times when Home Assistant doesn’t pick up the state change at all. For example, I shut my alarm off this morning and Home Assistant still sees it as in Home while the SimpliSafe app shows it correctly as Off.
I know you were experimenting with using SimpliSafe WebSocket so wondering if that change went into effect and could explain the new behavior.
If that is the case, is there any way that a user can still configure a periodic poll to catch state changes that might have been missed?
Yes, the websocket now drives a lot of the state changes. What version are you running, by chance? A lot of fixes went in to the latest patch and the stability should have increased.
If that is the case, is there any way that a user can still configure a periodic poll to catch state changes that might have been missed?
This is definitely on my to-do list either way; I’m thinking on the correct architecture.
@bachya - love it. That design will be awesome - best of both worlds with quick reactions with safety of polling to ensure accurate state.
I’m currently on 0.107.7
Also, just confirming - I can’t do that today by setting an automation to run every X minutes calling the homeassistant.update_entity service on the alarm, right? I didn’t know if that would trigger a check on status. Doesn’t seem to, but just confirming.
Correct. The reason I have an implement this – and why it’s such an architectural challenge – is that this is very sporadic. For instance, mine has been running for over 96 hours without losing connection to the websocket (or, if it doesn’t drop, it re-connects). Since I don’t have a good understanding of what the problem is, I’m hesitant to just slap a solution in place.
@bachya - that’s awesome! Well done. I’m looking forward to getting it when it hits a Hassio release.
I’m still getting familiar with the HomeAssistant code, so this is probably a stupid question, but I’m curious so can’t help myself…
I see the async_update_from_rest_api and async_update_from_websocket_event, but where is the REST API update triggered? I’d image it’s set at some polling interval, but can’t see where that is.
If the question doesn’t make sense or it’s not a simple answer, feel free to disregard - it’s not important, just for my own edification
Not a stupid question at all; in fact, you asking it caused me to take a closer look and find a place where I could improve the architecture – so, thank you!
Take a look at lines 477-483 of homeassistant/components/simplisafe/__init__.py:
async def refresh(event_time):
"""Refresh data from the SimpliSafe account."""
await self.async_update()
self._hass.data[DOMAIN][DATA_LISTENER][
self._config_entry.entry_id
] = async_track_time_interval(self._hass, refresh, DEFAULT_SCAN_INTERVAL)
This instructs the class that manages to the REST API to update new data every DEFAULT_SCAN_INTERVAL, which, per line 10 of of homeassistant/components/simplisafe/const.py, is: