Skip to content

battery: Add support for battery level related events #4208

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

markx86
Copy link
Contributor

@markx86 markx86 commented Jun 21, 2025

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
Copy link
Owner

Alexays commented Jun 22, 2025

LGTM, thanks!

@Alexays
Copy link
Owner

Alexays commented Jun 22, 2025

Can you add that to the battery man? 🙏

@S0nter
Copy link
Contributor

S0nter commented Jun 22, 2025

Related to #383

@markx86
Copy link
Contributor Author

markx86 commented Jun 22, 2025

Done!

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

markx86 commented Jun 22, 2025

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

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