Docs/Admin/Sessions

Sessions

Monitor and manage active device access sessions in real time.


Overview

Sessions represent active or completed access to Shelly-controlled devices. Each session tracks who used the device, when they used it, and how long they had access.

Door access does not use sessions — it uses QR access codes that are checked directly at the lock. Only Shelly device sessions are tracked in this module.


Session States

StateRelayTimerGuest Experience
ACTIVEONRunningCountdown circle visible
COMPLETEDOFFExpired"Session Complete" message
CANCELLEDOFFEnded early"Session Ended" message

Understanding Each State

ACTIVE

The relay is powered on and the countdown is running. The guest can see a live countdown circle on their session page, which polls every 2 seconds for updates.

Active sessions appear on the Dashboard as the primary operational metric.

COMPLETED

The timer reached zero and the relay was automatically turned off. This is the expected, successful end state for a session.

CANCELLED

The session ended before the timer expired. This is an abnormal termination and is logged with a failure reason.

Common cancellation reasons:

ReasonCause
force_ended_by_adminAdministrator manually ended the session
relay_off_prematurelyRelay lost power before session ended
reconciliation_timeoutBackground process detected relay was off
payment_reversedStripe reversed the payment after session started

Viewing Sessions

Session List

The Sessions page shows all sessions with filtering options:

FilterDescription
StatusACTIVE, COMPLETED, or CANCELLED
DeviceFilter by specific device
LocationFilter by physical location

Session Details

Click any session to see the full details:

FieldDescription
Session TokenUnique identifier for the session
DeviceName of the Shelly device
LocationWhere the device is located
Usage PlanWhich plan the guest selected
DurationConfigured session length (minutes)
Actual DurationTime between relay ON and relay OFF
Started AtWhen the grace period began
Ends AtWhen the session timer expires
StatusACTIVE, COMPLETED, or CANCELLED
Payment IDReference to the Stripe payment
Guest TokenToken for the guest's session page
Failure ReasonWhy the session was cancelled (if applicable)

Session Countdown Circle

The guest-facing session page shows a visual countdown circle with seven distinct states:

States

StateTriggerColor
LoadingInitial fetch while session data loadsGray
RunningActive session with time remainingPrimary color
FinishingActive session at 0 seconds remainingPrimary color
CompleteSession ended normallyGreen
InterruptedSession cancelled after startingAmber
Failed to StartSession cancelled before relay turned onRed
UnavailableDevice went offline during sessionRed

Polling Behavior

PhasePolling IntervalWhy
Initial loadEvery 2 secondsFast feedback during active session
Steady stateEvery 30 secondsReduce server load during long sessions
Finishing (< 60s remaining)Every 2 secondsPrecise end-time notification

Admin Recovery Actions

For active sessions that need manual intervention:

Force End

Ends the session immediately — turns the relay off and marks the session as COMPLETED.

When to use:

  • Guest has left but relay won't turn off automatically
  • Equipment malfunction requiring immediate shutdown
  • Guest requests early termination (with consent)

Mark as Failed

Logs the session as CANCELLED with a failure reason without sending a relay command.

When to use:

  • Technical error prevented session from starting
  • Payment was reversed mid-session
  • Equipment damage during session

Session Lifecycle (Full)

[1] Guest Payment
        │
        ▼
  Stripe Payment Intent created
  Status: PENDING
        │
        ▼
[2] Payment Confirmed
  Stripe webhook: payment_intent.succeeded
        │
        ▼
[3] Session Created
  DeviceSession created with status: ACTIVE
        │
        ▼
[4] Grace Period (delayMinutes)
  Relay state is checked but NOT activated
  ┌────────────────────────────────────┐
  │ Guest loads laundry / connects cable│
  │ Timer has not started yet           │
  └────────────────────────────────────┘
        │
        ▼
[5] Timer Starts
  Relay turns ON
  Countdown begins
  Guest sees countdown circle (polls every 2s)
        │
        ▼
[6] Finishing
  Remaining seconds = 0
  Waiting for relay OFF command
        │
        ▼
[7] Relay OFF
  Relay turns OFF
  Session marked COMPLETED

Background Processes

Startup Recovery

When Hygate starts, it scans for active sessions:

  1. Query all ACTIVE sessions
  2. For each session:
    • If expired (endsAt < now) → turn relay OFF, mark COMPLETED
    • If valid → verify relay is ON, log confirmation
      • If relay is OFF → mark CANCELLED (interrupted)

This prevents orphaned sessions after server restarts.

Session Cleanup (Every 5 Minutes)

A cron job runs every 5 minutes to expire stale sessions:

  1. Find all ACTIVE sessions where endsAt < now
  2. Turn relay OFF for each
  3. Mark as COMPLETED
  4. Retry if relay OFF fails

Session Reconciliation (Every 2 Minutes)

A reconciliation job runs every 2 minutes to catch state mismatches:

  1. Find all ACTIVE sessions where relay state does not match
  2. If relay is OFF but session is ACTIVE → mark CANCELLED
  3. If session is expired but ACTIVE → force completion
  4. Log all reconciliation actions

Role Permissions

ActionAdministratorOperator
View all sessionsYesYes
Force end a sessionYesNo
Mark as failedYesNo
View session detailsYesYes

Troubleshooting

Session Stuck on "Finishing"

  1. Go to Sessions
  2. Find the active session
  3. Click Force End

The reconciliation job also catches these every 2 minutes automatically.

Session Not Starting

CheckAction
Payment succeededCheck Payments for a SUCCEEDED record
Device not in maintenanceVerify device status is Active
Relay command succeededCheck audit logs for shelly_on_success
No conflicting sessionOnly one ACTIVE session per device

Session Cancelled Unexpectedly

CheckAction
Relay offlineCheck Shelly device connectivity
Power fluctuationCheck power supply to the Shelly device
Reconciliation logCheck audit logs for reconciliation events
Payment reversedCheck Stripe for chargebacks

Multiple Sessions on Same Device

Hygate prevents overlapping sessions. If payment fails because a session is already active, the guest sees a message indicating the device is in use.