← investigations
self-hosted

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:

  1. First setup — user enters SmartRent email, password, and 2FA code via the HA config flow UI.
  2. Token acquired — the integration exchanges credentials for a websocket token and writes it to the config entry.
  3. Subsequent restartsasync_setup_entry reads the stored token and refreshes it. No user interaction required.
  4. 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 unavailable during the backoff window instead of silently going stale.

Supported devices

DeviceHA platformCapabilities
Door locklocklock / unlock, battery level
Thermostatclimatemode, target temp, current temp, humidity
Leak sensorbinary_sensorwet / dry state, battery level

Installation

  1. Open Home Assistant → HACSIntegrations.
  2. Click the three-dot menu (top right) → Custom repositories.
  3. Add the repository URL:
    https://github.com/abipalli/homeassistant-smartrent
    Category: Integration.
  4. Search for SmartRent in HACS and click Install.
  5. Restart Home Assistant.
  6. Go to Settings → Devices & Services → Add Integration and search for SmartRent.
  7. Enter your SmartRent email, password, and 2FA code when prompted.

Manual

  1. Download the latest release from GitHub releases.
  2. Copy the custom_components/smartrent folder into your HA config/custom_components/ directory.
  3. Restart Home Assistant.
  4. 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.