Skip to content

Conversation

Acharab
Copy link

@Acharab Acharab commented Oct 2, 2025

battery monitoring script to provide richer notifications, avoid duplicate alerts, and automatically adjust power profiles- Replace simple threshold/flag logic with LOW (30%) and CRITICAL (10%)
thresholds and a /tmp/battery_warn.tmp file to track last alert state.

  • Consolidate battery percentage/state retrieval into helper functions.
  • Add play_sound() to play alert sounds via paplay when available.
  • Add send_notification() wrapper that sends formatted desktop notifications with metadata and calls play_sound().
  • Add set_power_profile() integration with powerprofilesctl to switch between balanced, power-saver, and performance profiles based on battery level and charging state.
  • Implement main logic to:
    • send a critical alert and switch to power-saver at or below CRITICAL,
    • send a low alert and switch to balanced at or below LOW,
    • clear state and restore performance profile when charging or OK.
  • Misc: clean up formatting and comments, remove old notification flag file approach, and round battery percentage extraction.

These changes reduce repeated alerts, improve user feedback (sound + rich notifications), and conserve power automatically when battery is low.

battery monitoring script to provide richer notifications,
avoid duplicate alerts, and automatically adjust power profiles- Replace simple threshold/flag logic with LOW (30%) and CRITICAL (10%)
  thresholds and a /tmp/battery_warn.tmp file to track last alert state.
- Consolidate battery percentage/state retrieval into helper functions.
- Add play_sound() to play alert sounds via paplay when available.
- Add send_notification() wrapper that sends formatted desktop
  notifications with metadata and calls play_sound().
- Add set_power_profile() integration with powerprofilesctl to switch
  between balanced, power-saver, and performance profiles based on
  battery level and charging state.
- Implement main logic to:
  - send a critical alert and switch to power-saver at or below CRITICAL,
  - send a low alert and switch to balanced at or below LOW,
  - clear state and restore performance profile when charging or OK.
- Misc: clean up formatting and comments, remove old notification flag
  file approach, and round battery percentage extraction.

These changes reduce repeated alerts, improve user feedback (sound +
rich notifications), and conserve power automatically when battery is
low.
@Acharab Acharab changed the title feat(battery): add advanced, profiles, sounds feat/battery-enhanced-monitoring-and-power-profiles Oct 2, 2025
@@ -1,36 +1,110 @@
#!/bin/bash
#!/bin/bash
Copy link

Choose a reason for hiding this comment

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

Fix first two lines :)

@woopstar
Copy link

woopstar commented Oct 3, 2025

Can also be enhanced with the PR from #1962

Acharab and others added 2 commits October 3, 2025 11:56
Allow LOW and CRITICAL thresholds to be passed as positional arguments
(default to 30 and 10) so waybar or other wrappers can override them.
Replace a fixed /tmp temp file with a user-specific runtime state file at
/run/user/$UID/omarchy_battery_notified to avoid permission and collision
issues across users and to conform to XDG runtime dir semantics.

Update notification checks and writes to use NOTIFICATION_FLAG and
remove it when battery is OK or charging. Keep existing behavior of
sending low/critical notifications and setting power profiles, but make
state handling more robust and configurable.
Fixed: path set to /run/user/$UID/omarchy_battery_notified
Fix: made tresholds dynamic and can be accessed by waybar: "custom/battery": {
    "exec": "path 25 15",
    "interval": 60
}
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.

2 participants