Home Assistant integration for smart plug session tracking with energy monitoring and scheduling.
Turns any switch with power/energy sensors (smart plugs, Shelly relays, in-wall switches) into a smart device tracker:
- Detects when device is running (active) or in standby
- Counts sessions/cycles and tracks energy per session
- Shows daily and total statistics
- Optional: Only allow operation at certain times (schedule)
- Optional: Control via binary_sensor (e.g., EPEX Spot tariff)
- Optional: Auto-off after X minutes
Use cases: Washing machine, dryer, sauna, air compressor, pump, etc.
A smart plug with:
- Switch entity
- Power sensor (W)
- Energy sensor (kWh)
HACS: Search for "Advanced Switches" → Install → Restart HA
Manual: Copy custom_components/advanced_switches to your config folder → Restart HA
Settings → Devices & Services → Add Integration → "Advanced Switches"
Choose operating mode:
- Simple Mode - Two states: OFF / ACTIVE (e.g., compressor, pump)
- Standby Mode - Three states: OFF / STANDBY / ACTIVE (e.g., washing machine, sauna)
| Parameter | Default | Description |
|---|---|---|
| Active Threshold (W) | 50 | Power above = active |
| On Delay (s) | 3 | Wait before OFF → ACTIVE |
| Off Delay (s) | 5 | Wait before ACTIVE → OFF |
| Min Active Duration (s) | 10 | Shorter cycles are ignored |
| Power Smoothing (s) | 0 | Moving average (0 = off) |
| Parameter | Default | Description |
|---|---|---|
| Standby Threshold (W) | 5 | Power above = standby |
| Active Threshold (W) | 1000 | Power above = active |
| On Delay (s) | 3 | Wait before state changes |
| Active/Standby Delay (s) | 5 | Wait for ACTIVE ↔ STANDBY |
| Session End Grace (s) | 120 | Prevents false session ends |
| Min Session Duration (s) | 60 | Shorter sessions are ignored |
| Power Smoothing (s) | 0 | Moving average (0 = off) |
| Session End on STANDBY | off | See below |
Controls when a session is counted as complete:
| Setting | Behavior | Use Case |
|---|---|---|
| OFF (default) | Session continues during ACTIVE↔STANDBY cycling, ends only at OFF | Sauna, oven (heating cycles) |
| ON | Each ACTIVE phase is a separate session | Washing machine, dishwasher |
Example - Washing Machine (ON):
Load 1: STANDBY → ACTIVE (30min) → STANDBY = Session 1 ✓
Load 2: STANDBY → ACTIVE (45min) → STANDBY = Session 2 ✓
→ 2 sessions counted
Example - Sauna (OFF):
ACTIVE (heating) → STANDBY → ACTIVE → STANDBY → ... → OFF
→ 1 session counted (entire usage)
| Parameter | Default | Description |
|---|---|---|
| Enable Schedule | off | Turn on scheduling |
| Start Time | 06:00 | Allowed from |
| End Time | 22:00 | Allowed until |
| Days | Mon-Sun | Allowed days |
| Control Sensor | — | Optional binary_sensor (e.g., EPEX Spot) |
Outside allowed times: switch turns off and blocks.
Control Sensor: You can select a binary_sensor to control when the switch is allowed. When the sensor is OFF, the device is blocked. Use this for dynamic electricity tariffs (EPEX Spot), presence detection, or any custom automation logic. Works standalone or combined with time schedule — if both are configured, both conditions must be met.
Turns off the switch automatically X minutes after it was turned on.
| Parameter | Default | Description |
|---|---|---|
| Enable Auto-Off | off | Turn on auto-off |
| Minutes | 60 | Turn off X minutes after switch turns on |
For noisy sensors (e.g., washing machine fluctuating 0.3-3W in standby):
- Set Power Smoothing to 30-60 seconds
- Smoothed value is used for state detection
- Peak power still uses raw values
Main:
sensor.<name>_state- off / standby / active / blockedbinary_sensor.<name>_active- true when activebinary_sensor.<name>_on- true when on (standby or active)
Statistics:
sensor.<name>_sessions_total- total countsensor.<name>_sessions_today- today's countsensor.<name>_energy_today- kWh todaysensor.<name>_energy_total- kWh total
Last Session:
sensor.<name>_last_session_durationsensor.<name>_last_session_energysensor.<name>_last_session_peak_power
Current Session:
sensor.<name>_current_session_durationsensor.<name>_current_session_energysensor.<name>_current_session_peak_power
Averages:
sensor.<name>_avg_session_durationsensor.<name>_avg_session_energy
Schedule:
binary_sensor.<name>_schedule_blockedbinary_sensor.<name>_schedule_turned_off
Auto-Off:
sensor.<name>_auto_off_remaining- countdown ("in 59 min" / "Inaktiv")
Other:
sensor.<name>_smoothed_power- diagnostic
Washing Machine:
- Standby Threshold: 1W
- Active Threshold: 10W
- Session End on STANDBY: ON (count each wash cycle)
- Power Smoothing: 30s
Sauna:
- Standby Threshold: 5W
- Active Threshold: 1000W
- Session End on STANDBY: OFF (heating cycles count as one session)
- Session End Grace: 120s
Compressor (daytime only):
- Active Threshold: 50W
- Schedule: 07:00-20:00, Mon-Fri
MIT