Skip to content

fix: command UPS output shutdown before host poweroff to enable unattended recovery#513

Open
MarcFinns wants to merge 4 commits into
hassio-addons:mainfrom
MarcFinns:fix/ups-output-not-cycling-on-shutdown
Open

fix: command UPS output shutdown before host poweroff to enable unattended recovery#513
MarcFinns wants to merge 4 commits into
hassio-addons:mainfrom
MarcFinns:fix/ups-output-not-cycling-on-shutdown

Conversation

@MarcFinns

@MarcFinns MarcFinns commented May 25, 2026

Copy link
Copy Markdown

Summary

Fixes #512

When shutdown_host is true, the shutdownhost script called bashio::host.shutdown without first issuing upsdrvctl shutdown. This meant the UPS output never cycled off/on after host shutdown, so the host would not reboot automatically after a power outage — including the case where AC returns while the host is shutting down.

  • shutdownhost: add new ups_power_cycle_on_shutdown option that calls upsdrvctl shutdown (via NUT's POWERDOWNFLAG check) before handing off to bashio::host.shutdown. The UPS offdelay countdown gives HAOS sufficient time to complete shutdown before the UPS cuts output.
  • config.yaml: add ups_power_cycle_on_shutdown option (default false for backward compatibility) and schema entry
  • translations/en.yaml: new file providing UI labels and descriptions for all configuration options
  • DOCS.md: document the new option, its requirements (offdelay, ondelay, BIOS power-on-after-AC-restore), and how it works
  • Dockerfile: remove pinned apt package versions that break the build when Debian repository moves to newer versions

Behaviour

  • shutdown_host: false — unchanged, only the app stops
  • shutdown_host: true, ups_power_cycle_on_shutdown: false — unchanged, host shuts down but UPS output does not cycle (default)
  • shutdown_host: true, ups_power_cycle_on_shutdown: true — host shuts down, UPS output cycles off then on, host reboots automatically via BIOS AC-restore

Test plan

  • Triggered FSD with ups_power_cycle_on_shutdown: false — host shuts down, UPS output does not cycle (backward-compatible behavior preserved)
  • Triggered FSD with ups_power_cycle_on_shutdown: true — host shuts down cleanly, UPS output cuts after offdelay (120s), restores after ondelay (180s) with AC present, host reboots automatically
  • Verified UI renders translated labels and descriptions for all options including the new toggle
  • Verified POWERDOWNFLAG check (upsmon -K) correctly gates the upsdrvctl shutdown call
  • Verified Dockerfile builds successfully without pinned package versions

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Optional UPS power-cycle during shutdown: when enabled, the system can instruct a UPS to cut and restore output as part of the shutdown sequence.
  • Documentation
    • User documentation and English translations added for the new UPS shutdown power-cycle option, including operational notes and requirements.
  • Chores
    • Build/runtime setup simplified by removing pinned package versions in the build process.

MarcFinns and others added 3 commits May 25, 2026 08:48
When shutdown_host is true, the shutdownhost script was calling
bashio::host.shutdown without first issuing upsdrvctl shutdown.
This meant the UPS output never cycled off/on, so the host never
received a power-restore event and would not reboot after a power
outage — including the "power race" case where AC returns while the
host is shutting down.

Fix: check for the NUT POWERDOWNFLAG (via upsmon -K) and run
upsdrvctl shutdown before handing off to bashio::host.shutdown.
The UPS offdelay (default 120 s) gives the host sufficient time to
complete its shutdown before the UPS cuts output.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add a new opt-in config option that commands the UPS to cycle its output
before host shutdown, enabling fully unattended recovery after a power
outage. When enabled, upsdrvctl shutdown is called if the NUT POWERDOWNFLAG
is set, starting the UPS offdelay countdown before handing off to
bashio::host.shutdown.

- shutdownhost: gate upsdrvctl shutdown on ups_power_cycle_on_shutdown config
- config.yaml: add option (default false) and schema entry
- DOCS.md: document the new option, requirements, and how it works
- translations/en.yaml: add UI labels and descriptions for all config options

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Pinned exact Debian package versions break the build whenever the
repository moves to a newer version. Use unpinned package names and
suppress the hadolint DL3008 warning explicitly.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented May 25, 2026

Copy link
Copy Markdown

Need an answer fast? Review this PR in Change Stack to ask focused questions about the PR or a changed range.

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 15464301-885e-49e6-bb2c-92f11ee00005

📥 Commits

Reviewing files that changed from the base of the PR and between 11720c1 and c15c521.

📒 Files selected for processing (1)
  • nut/rootfs/usr/bin/shutdownhost
🚧 Files skipped from review as they are similar to previous changes (1)
  • nut/rootfs/usr/bin/shutdownhost

Walkthrough

Adds an optional ups_power_cycle_on_shutdown setting, implements a pre-shutdown UPS output cycle (checks POWERDOWNFLAG via upsmon -K and may call upsdrvctl shutdown), updates Dockerfile dependency pins, and adds docs and English translations describing the feature and required driver/BIOS behavior.

Changes

UPS Power Cycling on Shutdown

Layer / File(s) Summary
Configuration Schema and Defaults
nut/config.yaml
New ups_power_cycle_on_shutdown boolean option added to defaults and schema (default: false).
Shutdown Host Power Cycling Logic
nut/rootfs/usr/bin/shutdownhost
Shutdown script conditionally checks POWERDOWNFLAG via upsmon -K and invokes upsdrvctl shutdown (logs non-zero exit) before calling host shutdown when the option is enabled.
Documentation and User-Facing Text
nut/DOCS.md, nut/translations/en.yaml
DOCS.md documents the new option, POWERDOWNFLAG flow, required offdelay/ondelay driver params and BIOS expectations; English translations add configuration labels and network port text.
Dockerfile Dependency Updates
nut/Dockerfile
Builder and app stage apt-get installs use unpinned package names instead of explicit version pins for build/runtime dependencies.

Sequence Diagram

sequenceDiagram
  participant shutdownhost as shutdownhost script
  participant upsmon as upsmon
  participant upsdrvctl as upsdrvctl
  participant Host as Host/BIOS

  shutdownhost->>upsmon: run `upsmon -K` (check POWERDOWNFLAG)
  upsmon-->>shutdownhost: return POWERDOWNFLAG set / not set
  alt POWERDOWNFLAG set
    shutdownhost->>upsdrvctl: run `upsdrvctl shutdown` (trigger offdelay/ondelay)
    upsdrvctl-->>shutdownhost: exit status (0 or non-zero)
    shutdownhost->>Host: call `bashio::host.shutdown`
  else POWERDOWNFLAG not set
    shutdownhost->>shutdownhost: log skip UPS output shutdown
    shutdownhost->>Host: call `bashio::host.shutdown`
  end
Loading

🎯 2 (Simple) | ⏱️ ~12 minutes

Suggested labels

bugfix

Suggested reviewers

  • frenck

Poem

I’m a rabbit in the server room, ears alert and bright,
I twitch my whiskers, flip the switch, then watch the dark turn light,
Off goes the power, then on again — the BIOS lifts the veil,
The host awakes, the logs proclaim: automation tells the tale. 🐰⚡

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately summarizes the main change: adding UPS output shutdown capability before host poweroff to enable unattended recovery after AC restoration.
Linked Issues check ✅ Passed The PR implementation fully addresses issue #512: it adds the ups_power_cycle_on_shutdown option to shutdownhost script with POWERDOWNFLAG checking, config.yaml schema support, documentation, and translations to enable UPS output cycling before host shutdown.
Out of Scope Changes check ✅ Passed All changes are scoped to the PR objectives: the UPS power cycle feature, Dockerfile dependency unpinning to fix builds, documentation, configuration schema, and translations. No unrelated changes detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@nut/rootfs/usr/bin/shutdownhost`:
- Line 16: The script currently runs upsdrvctl shutdown without checking its
result; wrap the upsdrvctl shutdown invocation in an error check so failures are
detected, capture stderr/exit code and emit a clear diagnostic (e.g., via
logger/syslog or echo) including the exit status and output, and ensure the
script returns a non‑zero code or takes a compensating action when upsdrvctl
fails; locate the upsdrvctl shutdown call in the shutdownhost script and replace
the unconditional call with a conditional that logs the error and propagates
failure.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 07a4f6e9-587e-4e75-9185-a6e8a2364dec

📥 Commits

Reviewing files that changed from the base of the PR and between 44d166e and 11720c1.

📒 Files selected for processing (5)
  • nut/DOCS.md
  • nut/Dockerfile
  • nut/config.yaml
  • nut/rootfs/usr/bin/shutdownhost
  • nut/translations/en.yaml

Comment thread nut/rootfs/usr/bin/shutdownhost
Capture and log the exit code of `upsdrvctl shutdown` so a failure to
cycle UPS output is surfaced in the add-on log. The host shutdown still
proceeds regardless, since failing to cut UPS power must not block the
host from powering down.

Addresses CodeRabbit review feedback on hassio-addons#513.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@MarcFinns

Copy link
Copy Markdown
Author

Friendly ping — this PR is ready for review when a maintainer has a moment. 🙏

Quick status:

  • Fixes HAOS host shuts down on FSD but UPS output is never powered off #512 (HAOS does not power-cycle the UPS on FSD, so the host never reboots after AC returns).
  • CodeRabbit's one actionable comment (error handling around upsdrvctl shutdown) has been addressed in c15c521.
  • New behavior is opt-in via ups_power_cycle_on_shutdown (default false), so existing setups are unaffected.

@frenck if you could enable the CI workflows to run and take a look when convenient, that would be much appreciated. Happy to make any changes you'd like.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HAOS host shuts down on FSD but UPS output is never powered off

1 participant