How to "allow force discharging" is supposed to work?
What is the issue? (required) I can't figure how the option "Allow force discharging" is supposed to work.
I thought I would have to define a low level battery target to work on battery, while plugged-in, until this level is reached, to then charge the battery. But obviously, it doens't work this way. It's works this way with the terminal command only.
Any help?
The terminal command "battery discharge XX" work well though.
What exactly did you do to produce the issue? (required) Steps to reproduce the behavior:
- Set the "Allow force discharging" option
Expected behavior (required) I don't know what to expect exactly, it's just not clear enough.
Screenshots (optional)
On this 1st screenshot, one sees the option is activated, but the mac is still shown as "plugged in".
Error logs
Additional context (optional) "battery discharge 30" output:
11/06/24-16:54:22 - Discharging to 30% from 80%
11/06/24-16:54:22 - 🔽🪫 Enabling battery discharging
Error: SMCWriteKey() = e00002bc
11/06/24-16:54:22 - Battery at 80% (target 30%)
Logs:
🖥️ Battery GUI logs:
{"percentage":"80","remaining":"unknown","charging":false,"discharging":false,"maintain_percentage":"80","battery_state":"80% (unknown remaining)","daemon_state":"smc charging disabled"}
Generate app menu percentage: 80 (discharge allowed, limited on)
Found image: /Applications/battery.app/Contents/Resources/battery-active-80-Template.png
Display percentage 80 based on 80
Refreshing interface update timer
Get active logo for 80
Limiter status message:
11/06/24-16:50:10 - Battery at 80% (attached; remaining), 12.144V, smc charging disabled
11/06/24-16:50:10 - Your battery is currently being maintained at 80%
Force discharge setting: boolean true
Executing PATH=/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin battery status_csv
Resetting interface timer speed
Battery status:
{"percentage":"80","remaining":"unknown","charging":false,"discharging":false,"maintain_percentage":"80","battery_state":"80% (unknown remaining)","daemon_state":"smc charging disabled"}
Setting interface refresh speed to 10 minutes
Executing PATH=/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin battery status_csv
Refreshing tray icon...
Battery status:
{"percentage":"80","remaining":"unknown","charging":false,"discharging":false,"maintain_percentage":"80","battery_state":"80% (unknown remaining)","daemon_state":"smc charging disabled"}
Executing PATH=/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin battery status
Force discharge setting: boolean true
Display percentage 80 based on 80
Get active logo for 80
Resetting interface timer speed
Refreshing interface update timer
Executing PATH=/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin battery status_csv
Found image: /Applications/battery.app/Contents/Resources/battery-active-80-Template.png
Generate app menu percentage: 80 (discharge allowed, limited on)
Limiter status message:
11/06/24-16:50:41 - Battery at 80% (attached; remaining), 12.145V, smc charging disabled
11/06/24-16:50:41 - Your battery is currently being maintained at 80%
Even the terminal discharge command doesn't really work as expected.
user@mac ~ % battery discharge 30
11/06/24-17:48:39 - Discharging to 30% from 80%
11/06/24-17:48:39 - 🔽🪫 Enabling battery discharging
Error: SMCWriteKey() = e00002bc
11/06/24-17:48:39 - Battery at 80% (target 30%)
11/06/24-17:49:39 - Battery at 80% (target 30%)
11/06/24-17:50:39 - Battery at 80% (target 30%)
11/06/24-17:51:40 - Battery at 80% (target 30%)
11/06/24-17:52:40 - Battery at 80% (target 30%)
11/06/24-17:53:40 - Battery at 80% (target 30%)
11/06/24-17:54:40 - Battery at 80% (target 30%)
11/06/24-17:55:40 - Battery at 80% (target 30%)
11/06/24-17:56:40 - Battery at 80% (target 30%)
11/06/24-17:57:40 - Battery at 80% (target 30%)
11/06/24-17:58:40 - Battery at 80% (target 30%)
11/06/24-17:59:40 - Battery at 79% (target 30%)
11/06/24-18:00:40 - Battery at 79% (target 30%)
11/06/24-18:01:40 - Battery at 79% (target 30%)
11/06/24-18:02:40 - Battery at 79% (target 30%)
11/06/24-18:03:40 - Battery at 79% (target 30%)
11/06/24-18:04:40 - Battery at 79% (target 30%)
11/06/24-18:05:40 - Battery at 79% (target 30%)
11/06/24-18:06:41 - Battery at 80% (target 30%)
As one can sees, the battery starts to get drained, and then, it's charged again to the 80% limits.
Got a new mac. This one doesn't have the SMC error, but the discharge behavior is the same. Once at 79%, it charges again.
I use battery charge X and then battery maintain X once I'm close to X. Once "maintain" has been set, it usually hovers around the desired value
Looking at the menu bar code: https://github.com/actuallymentor/battery/blob/e9993d4777e6fecae87a0762c27366b8072847f5/app/modules/interface.js#L61-L71 That calls the settings code: https://github.com/actuallymentor/battery/blob/e9993d4777e6fecae87a0762c27366b8072847f5/app/modules/settings.js#L9-L42 Then the main UI code: https://github.com/actuallymentor/battery/blob/e9993d4777e6fecae87a0762c27366b8072847f5/app/modules/battery.js#L91-L92 Finally the main daemon: https://github.com/actuallymentor/battery/blob/e9993d4777e6fecae87a0762c27366b8072847f5/battery.sh#L690-L698
What it does is simply discharging the battery first before starting the main logic. The menu text probably needs better wording.
This patch should force discharge the battery when reaches the upper percentage and charges again when reaches the lower.
--- a/battery.sh 2025-11-16 22:53:13
+++ b/battery.sh 2025-11-16 23:26:49
@@ -718,12 +718,18 @@
log "Charge at or above $upper_bound%"
if [[ "$is_charging" == "enabled" ]]; then
disable_charging
+ fi
+ if [[ "$subsetting" == "--force-discharge" ]] && [[ "$is_range" == true ]]; then
+ enable_discharging
fi
change_magsafe_led_color "green"
elif [[ "$battery_percentage" -lt "$lower_bound" && "$is_charging" == "disabled" ]]; then
log "Charge below $lower_bound%"
+ if [[ "$subsetting" == "--force-discharge" ]] && [[ "$is_range" == true ]]; then
+ disable_discharging
+ fi
enable_charging
change_magsafe_led_color "orange"