Why Home Assistant Won’t Save Automations After UPS Install
If your Home Assistant automations suddenly stop saving after you install a UPS, the most likely cause is that the UPS triggers a rapid power blip or ground-loop that corrupts the SQLite database mid-write, or the UPS’s USB/network connection causes the system to hang during the save. This article explains the exact mechanisms, how to diagnose it, and how to fix it so your automations save reliably again.
Background: How Home Assistant Stores Automations
Home Assistant (HA) stores automations in a YAML file (automations.yaml) or in its internal database, depending on your configuration and version. When you click “Save� in the automation editor, HA writes the entire automation list to disk. This write operation is not atomic by default—it creates a temporary file, writes the data, then renames it over the old file. If the system loses power or crashes during that window, the file can be left partially written or the database can become corrupted.
Installing a UPS (uninterruptible power supply) is meant to prevent power loss, but it can introduce new electrical and communication issues that actually increase the risk of write failures.
How a UPS Can Interfere with Saving
There are several distinct ways a UPS can cause save failures, and they often occur together:
- Power blips during transfer: Cheaper UPS units (standby or line-interactive) have a transfer time of 4–10 milliseconds when switching from utility power to battery. If the switch happens while HA is writing to disk, the voltage sag can cause the system to lock up or the storage to glitch.
- Ground loops and electrical noise: A UPS can create a ground potential difference between the HA device and other connected equipment (like a router or USB hub). This can cause random resets or USB disconnects, which may interrupt the save process.
- USB/Network communication issues: Many UPS units connect to the HA device via USB or network to report battery status. If the UPS’s monitoring software or driver causes a kernel panic or a hang, the HA process may freeze mid-save.
- Battery mode voltage distortion: When running on battery, some UPS units output a modified sine wave that can cause power supplies to behave erratically, especially if the HA device has a sensitive power supply.
All of these can lead to the same symptom: you edit an automation, click “Save�, and nothing happens—or you get an error like “Unable to save� or the page just reloads without your changes.
Diagnosing the Exact Cause
Before changing anything, confirm that the UPS is actually the culprit. Follow these steps:
- Check the HA logs: Go to Settings → System → Logs. Look for errors around the time you tried to save. Common messages include
sqlite3.OperationalError: database is lockedorOSError: [Errno 28] No space left on device. - Test with the UPS unplugged: Temporarily power the HA device directly from wall power (no UPS). Try saving an automation. If it works, the UPS is involved.
- Test on battery power: Unplug the UPS from the wall (simulate a power outage) and try saving while on battery. If it fails only on battery, the issue is likely the battery output quality.
- Check the UPS communication: If you have the UPS connected via USB, disconnect it and try saving. If it works, the USB connection is causing the problem.
Fixing the Save Issue
Once you know the cause, apply the appropriate fix:
- For power blips: Replace the UPS with a double-conversion (online) model that has zero transfer time. This is the most reliable fix but costs more.
- For ground loops: Use a power strip with surge protection that has a common ground, or connect all equipment to the same UPS output bank. Avoid running long USB cables between the UPS and HA device.
- For USB communication issues: Disable the UPS monitoring software or use a network-based UPS (like a SNMP card) instead of USB. You can also try a different USB port or a powered USB hub.
- For battery mode distortion: If the UPS outputs a modified sine wave, switch the HA device to a UPS that outputs a pure sine wave, or use a separate battery backup for the HA device only.
- For database corruption: If the database is already corrupted, stop HA, back up the
.dbfile, and runsqlite3 home-assistant_v2.db ".recover"(or restore from a backup).
Preventing Future Save Failures
Even after fixing the immediate issue, take these steps to make your setup more resilient:
- Enable the HA backup integration: Schedule automatic backups so you can restore if corruption occurs.
- Use an external database: Move the HA database to a separate machine (like a Raspberry Pi with a good SD card) or a network storage that has its own UPS.
- Adjust the write behavior: In
configuration.yaml, you can setrecorder:withcommit_interval: 30to reduce the frequency of writes, but this doesn’t affect automation saves. - Install a quality SD card or SSD: Many HA devices run on SD cards that are prone to corruption during power loss. An SSD or high-endurance SD card reduces the risk.
- Use a pure sine wave UPS: If you’re buying a new UPS, choose one with pure sine wave output—it’s safer for all electronics.
Common Misconceptions
One common misconception is that a UPS will always protect against data loss. In reality, a UPS only helps if it provides clean, continuous power. A cheap UPS can cause more problems than it solves, especially with sensitive devices like a Raspberry Pi running Home Assistant. Another misconception is that the save failure is caused by the UPS’s battery being low—this is rarely the case; it’s almost always a power quality or communication issue.
Also, some users think that reinstalling Home Assistant will fix the problem. While a fresh install may temporarily work, if the UPS is still causing power glitches, the issue will return.
Frequently Asked Questions
Why does my Home Assistant freeze after installing a UPS?
This is usually caused by a ground loop or USB communication issue. The UPS’s USB connection can cause a kernel panic or a hang. Try disconnecting the USB cable and see if the freezing stops. If it does, use a network-based UPS instead.
Can a UPS damage my Home Assistant device?
Yes, a poorly designed UPS can send voltage spikes or distorted power to your device, especially when switching to battery. This can cause hardware damage over time. Use a quality UPS with pure sine wave output and surge protection.
Do I need a UPS for Home Assistant?
It’s recommended if you live in an area with frequent power outages, because a sudden power loss can corrupt the database and cause you to lose your configuration. However, a UPS is not a substitute for regular backups.
How do I know if my UPS is the problem?
Unplug the UPS and run HA directly from wall power for a day. If the save issue disappears, the UPS is the culprit. You can also check the HA logs for errors that occur at the same time as the UPS’s transfer events.
What is the best UPS for Home Assistant?
Look for a UPS with pure sine wave output, a USB or network connection that works with HA’s built-in UPS integration, and enough capacity to run your HA device for at least 10 minutes. Avoid modified sine wave models.
Can I use a UPS with a Raspberry Pi running HA?
Yes, but be aware that the Pi is sensitive to power quality. Use a UPS with a USB port that can communicate with the Pi, and consider using a powered USB hub to avoid ground loops.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.