Home Assistant Power Outage Automation
January 2, 2026 · View on GitHub
Automatically turn on lights when a power outage is detected using a UPS battery status sensor in Home Assistant.
Overview
This automation pattern uses a UPS (Uninterruptible Power Supply) as a power outage detector. When the UPS switches from "Online" (OL) to "On Battery" (OB), it triggers a boolean sensor that can then be used to control lights or other devices.
Prerequisites
Hardware Requirements
- UPS with network monitoring - Must report status to Home Assistant (via NUT, APC, etc.)
- Smart lights on UPS power - The lights you want to control must:
- Be connected to power through the UPS (so they have power during outages)
- Be smart-enabled (either smart bulbs or regular lights on a smart plug)
- The smart plug/bulb must also be powered by the UPS
Why This Setup?
During a power outage, your smart home hub (Home Assistant) and network equipment need to stay powered to execute automations. Similarly, the lights you want to turn on must have power available. By connecting both your HA server and target lights to a UPS, the automation can function during outages.
UPS Battery Backup
├── Home Assistant server
├── Network switch/router
├── Smart plug → Light (e.g., lamp)
└── (Optional) Other critical devices
Components
Entities Required
| Entity | Type | Purpose |
|---|---|---|
sensor.server_ups_status_data | Sensor | UPS status from NUT integration (reports OL/OB) |
input_boolean.power_outage | Input Boolean | Helper to track outage state |
binary_sensor.power_outage_detected | Binary Sensor | (Optional) Template sensor based on the boolean |
light.nymane | Light | Target light to turn on during outages |
UPS Status Codes
- OL = Online (mains power available)
- OB = On Battery (power outage detected)
Setup Instructions
1. Create the Input Boolean Helper
In Home Assistant, go to Settings → Devices & Services → Helpers and create:
- Name: Power Outage
- Entity ID:
input_boolean.power_outage
2. Create the Automations
Automation 1: Power Outage Detected
Triggers when UPS switches to battery power.
alias: Power outage in progress
description: ""
triggers:
- trigger: state
entity_id:
- sensor.server_ups_status_data
to:
- OB
conditions: []
actions:
- action: input_boolean.turn_on
target:
entity_id: input_boolean.power_outage
mode: single
Automation 2: Power Restored
Triggers when UPS returns to mains power.
alias: Power outage over
description: ""
triggers:
- trigger: state
entity_id:
- sensor.server_ups_status_data
to:
- OL
from:
- OB
conditions: []
actions:
- action: input_boolean.turn_off
target:
entity_id: input_boolean.power_outage
mode: single
Automation 3: Turn On Light During Outage
Triggers when the power outage boolean turns on.
alias: Nymane on when power out
description: ""
triggers:
- trigger: state
entity_id:
- binary_sensor.power_outage_detected
to:
- "on"
conditions: []
actions:
- action: light.turn_on
target:
entity_id: light.nymane
mode: single
Optional Enhancements
Additional Helper Sensors
You can create template sensors to track:
- Power outage started - Timestamp when outage began
- Power outage duration - Time elapsed since outage started
- Power outage ended - Timestamp when power was restored
Alternative Detection Methods
Instead of relying on a single UPS sensor, you can group multiple UPS binary sensors together for more robust detection across multiple UPS units.
Architecture Diagram
┌─────────────────────────────────────────────────────────┐
│ Power Grid │
└─────────────────────┬───────────────────────────────────┘
│
▼
┌───────────────┐
│ UPS │
│ (Battery) │
└───────┬───────┘
│
┌─────────────┼─────────────┐
│ │ │
▼ ▼ ▼
┌─────────┐ ┌──────────┐ ┌──────────┐
│ HA │ │ Router │ │ Smart │
│ Server │ │ Switch │ │ Plug │
└────┬────┘ └──────────┘ └────┬─────┘
│ │
│ ┌──────────────┐ │
└───►│ NUT Sensor │ ▼
│ (OL → OB) │ ┌────────┐
└──────┬───────┘ │ Lamp │
│ └────────┘
▼
┌────────────────┐
│ input_boolean │
│ power_outage │
└───────┬────────┘
│
▼
┌────────────────┐
│ Automation: │
│ Turn on light │
└────────────────┘
Troubleshooting
UPS Sensor Shows "Unavailable"
- Check that NUT (Network UPS Tools) integration is properly configured
- Verify the UPS is communicating with your server
- Check USB/network connection to the UPS
Lights Don't Turn On
- Verify the smart plug/light is powered by the UPS
- Check that the entity IDs match your setup
- Test the automation manually in Developer Tools
License
MIT License - Feel free to adapt for your own Home Assistant setup.