SmartRent → Home Assistant: persistent credentials & restart resilience
A HACS integration that bridges SmartRent apartment devices into Home Assistant with credential persistence across restarts.
The problem
SmartRent is the smart-home platform installed in many managed apartment buildings. Residents get locks, thermostats, and leak sensors — but no way to pull them into Home Assistant. The smartrent-py library speaks the SmartRent websocket API, but previous HA wrappers re-authenticated on every restart and lost state when the connection dropped.
This integration fixes both issues: credentials persist across restarts and the connection recovers automatically.
What changed
Credential persistence
SmartRent authentication returns a short-lived websocket token after an email + password + 2FA exchange. Rather than repeating that flow on every HA restart, the integration stores the token (and its refresh metadata) in Home Assistant’s ConfigEntry data store. On startup it attempts a token refresh first, falling back to a full re-auth only when the token is genuinely expired.
The flow:
- First setup — user enters SmartRent email, password, and 2FA code via the HA config flow UI.
- Token acquired — the integration exchanges credentials for a websocket token and writes it to the config entry.
- Subsequent restarts —
async_setup_entryreads the stored token and refreshes it. No user interaction required. - Token expiry — if refresh fails, HA surfaces a re-auth notification so the user can re-enter credentials once.
Restart resilience
The websocket connection is managed by a coordinator that:
- Reconnects with exponential backoff on transient failures.
- Re-subscribes to device state updates after reconnection so entity values stay current.
- Marks entities as
unavailableduring the backoff window instead of silently going stale.
Supported devices
| Device | HA platform | Capabilities |
|---|---|---|
| Door lock | lock | lock / unlock, battery level |
| Thermostat | climate | mode, target temp, current temp, humidity |
| Leak sensor | binary_sensor | wet / dry state, battery level |
Installation
Via HACS (recommended)
- Open Home Assistant → HACS → Integrations.
- Click the three-dot menu (top right) → Custom repositories.
- Add the repository URL:
Category: Integration.https://github.com/abipalli/homeassistant-smartrent - Search for SmartRent in HACS and click Install.
- Restart Home Assistant.
- Go to Settings → Devices & Services → Add Integration and search for SmartRent.
- Enter your SmartRent email, password, and 2FA code when prompted.
Manual
- Download the latest release from GitHub releases.
- Copy the
custom_components/smartrentfolder into your HAconfig/custom_components/directory. - Restart Home Assistant.
- Add the integration via Settings → Devices & Services.
Configuration
Once installed, the integration is fully UI-driven — no configuration.yaml edits needed. All credentials are stored securely in HA’s config entry store and survive restarts, updates, and HA core upgrades.