Skip to content

Automatically switch to power-saver profile on low battery with a hook#4942

Closed
pomartel wants to merge 13 commits intobasecamp:devfrom
pomartel:power-saver-low-battery
Closed

Automatically switch to power-saver profile on low battery with a hook#4942
pomartel wants to merge 13 commits intobasecamp:devfrom
pomartel:power-saver-low-battery

Conversation

@pomartel
Copy link
Copy Markdown
Contributor

@pomartel pomartel commented Mar 9, 2026

UPDATE: I rewrote the PR to use a hook instead. Less code, cleaner approach.

The default behaviour for laptops is to use performance mode when plugged in and balanced when unplugged. With this PR, we add a hook that would automatically switch to power-saver on low battery (20% as the default).

Copilot AI review requested due to automatic review settings March 9, 2026 01:46
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds an automatic “switch to power-saver on low battery” mechanism for laptop installs by introducing a new systemd user timer/service and the corresponding script, plus wiring it into both fresh installs and migrations.

Changes:

  • Add omarchy-powerprofile-low-battery script that switches to power-saver when discharging below a threshold.
  • Add systemd user .service + .timer to run the check every 30 seconds.
  • Enable/install the timer on first run and via a migration for existing users.

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
migrations/1772383152.sh Copies the new systemd user units into ~/.config/systemd/user and enables the timer on laptops.
install/first-run/battery-monitor.sh Enables the new low-battery power-saver timer during first-run setup on battery-powered devices.
config/systemd/user/omarchy-powerprofile-low-battery.timer Defines the 30s systemd user timer for low-battery checks.
config/systemd/user/omarchy-powerprofile-low-battery.service Defines the systemd user oneshot service that runs the low-battery check script.
bin/omarchy-powerprofile-low-battery Implements the low-battery detection + profile switching logic.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@pomartel pomartel changed the title Power saver low battery Automatically switch to power-saver profile on low battery Mar 9, 2026
Copilot AI review requested due to automatic review settings March 9, 2026 13:53
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 3 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread config/omarchy/hooks/battery-monitor.sample Outdated
Comment thread config/omarchy/hooks/battery-monitor.sample Outdated
Comment thread migrations/1773061643.sh Outdated
Copilot AI review requested due to automatic review settings March 9, 2026 13:59
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 3 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread config/omarchy/hooks/battery-monitor.sample Outdated
Comment thread migrations/1773061643.sh Outdated
@pomartel pomartel changed the title Automatically switch to power-saver profile on low battery Automatically switch to power-saver profile on low battery with a hook Mar 9, 2026
@pomartel
Copy link
Copy Markdown
Contributor Author

pomartel commented Mar 9, 2026

We could simplify it further by hooking this up with the new battery-low hook. But I feel like switching to power-saver when there's only 10% battery remaining wouldn't make a big difference.

@pomartel
Copy link
Copy Markdown
Contributor Author

pomartel commented Mar 9, 2026

Now that I think about it, maybe sole responsability of omarchy-battery-monitor should be to trigger the hooks. The low battery notification could be fired in a hook too.

Or maybe I'm overthinking this! 🫠

@dhh
Copy link
Copy Markdown
Member

dhh commented Mar 10, 2026

I think default behavior remains as-is, but we should only have one hook. I'm fine having a hook that's called as often as this, though, but then we need to integrate the work from #4945 in that approach.

Copilot AI review requested due to automatic review settings March 10, 2026 14:06
@pomartel
Copy link
Copy Markdown
Contributor Author

@dhh Here are the changes I made:

  • omarchy-battery-monitor now has a single responsibility, which is to trigger the battery-monitor hook.
  • omarchy-hook now allows for unix-style .d directories to run multiple scripts for the same hook. It stays backward compatible with what we already have.
  • battery-low-notification, battery-low-sound.sample and battery-low-power-saver.sample are placed in battery-monitor.d and can be configured individually.

It's a bit more changes than what you asked for but I think it's more robust.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 8 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@dhh
Copy link
Copy Markdown
Member

dhh commented Mar 10, 2026

This is too much. I don't want the default implementation in a hook. Hooks are exclusively for extending the default setup with user-configured features. But the main battery warning needs to be in Omarchy proper still.

Copilot AI review requested due to automatic review settings March 10, 2026 14:52
@pomartel
Copy link
Copy Markdown
Contributor Author

pomartel commented Mar 10, 2026

@dhh Putting the battery warning in a hook would have allowed users to modify the default threshold (10%) or remove the notification altogether. But if you prefer it not to be user-configurable then I rolled back that change.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 7 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@pomartel pomartel closed this Apr 15, 2026
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.

3 participants