Skip to content

battery: Add support for battery level related events - #4208

Merged
Alexays merged 3 commits into
Alexays:masterfrom
markx86:feat/battery-events
Aug 8, 2025
Merged

Alexays merged 3 commits into
Alexays:masterfrom
markx86:feat/battery-events

Conversation

@markx86

@markx86 markx86 commented Jun 21, 2025

Copy link
Copy Markdown
Contributor

The user can now specify commands to be executed when a specific battery level is reached in a certain state.
The events must be specified in the events object, and the keys in the object can be in the format

  • on-[status]-[state]
  • on-[status]-[capacity]
    where:
  • [status] can be discharging or charging
  • [state] is the name of one of the states specified in the states object
  • [capacity] is the battery percentage

For example, the following configuration will send a low battery notification when the battery reaches the warning and critical states while discharging and a full battery notification when the battery reaches 100% when charging.

 "battery": {
    "states": {
        "warning": 20,
        "critical": 10
    },
    "events": {
        "on-discharging-warning": "notify-send -u normal 'Low Battery'",
        "on-discharging-critical": "notify-send -u critical 'Very Low Battery'",
        "on-charging-100": "notify-send -u normal 'Battery is full'",
        },
    ...
}

@Alexays

Alexays commented Jun 22, 2025

Copy link
Copy Markdown
Owner

LGTM, thanks!

@Alexays

Alexays commented Jun 22, 2025

Copy link
Copy Markdown
Owner

Can you add that to the battery man? 🙏

@yerlotic

Copy link
Copy Markdown
Contributor

Related to #383

@markx86

markx86 commented Jun 22, 2025

Copy link
Copy Markdown
Contributor Author

Done!

@markx86
markx86 force-pushed the feat/battery-events branch from 0b5e057 to eae22f3 Compare June 22, 2025 15:47
@markx86

markx86 commented Jun 22, 2025

Copy link
Copy Markdown
Contributor Author

I rebased onto master and fixed the CI. I think it's ready merge, unless I missed something. @Alexays

@Alexays
Alexays merged commit 477f307 into Alexays:master Aug 8, 2025
@rieje

rieje commented Dec 8, 2025

Copy link
Copy Markdown

Users who use this feature might also want notifications for charging and uncharging but this doesn't seem to support that since it requires a state or capacity. For example, if a cable or port is problematic, it is useful to confirm on plugging the charging cable that the system is indeed charging.

Would it make sense to support this?

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.

4 participants