[SOLVED] [somehow] I'd like Linux Mint to ask me what to do when battery gets critically low

Please post suggestions for improvement of Cinnamon on:
https://github.com/linuxmint/Cinnamon
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
sverx
Level 2
Level 2
Posts: 73
Joined: Mon Oct 02, 2017 4:58 am

[SOLVED] [somehow] I'd like Linux Mint to ask me what to do when battery gets critically low

Post by sverx »

It happens to me to overlook that my laptop battery depletes. When I was running Kubuntu I got used to notifications but I still have to set them on my new Linux Mint laptop.

But I've seen there's a Power Management option - "What to do when battery is critically low", choices are "Hibernate" or "Do nothing".

Reading this topic, it seems to me I can add other options there. I'd like an option "Ask what to do".

I seem to understand I should edit /usr/share/cinnamon/cinnamon-settings/modules/cs_power.py adding a line there (I added the 3rd line):

Code: Select all

critical_options = [
("hibernate", _("Hibernate")),
("interactive", _("Ask what to do")),
("nothing", _("Do nothing"))
]
I was wondering if that's everything I need to do. Would then a window appear? That would be wonderful, as I might then choose to Hibernate, or to just save my work and shut down the laptop... or quickly run for the charger, plug the power source... and simply answer then "do nothing".

Will it work or am I missing something? :)
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 2 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
revian

Re: I'd like Linux Mint to ask me what to do when battery gets critically low

Post by revian »

sverx wrote:It happens to me to overlook that my laptop battery depletes. When I was running Kubuntu I got used to notifications but I still have to set them on my new Linux Mint laptop.

But I've seen there's a Power Management option - "What to do when battery is critically low", choices are "Hibernate" or "Do nothing".

Reading this topic, it seems to me I can add other options there. I'd like an option "Ask what to do".

I seem to understand I should edit /usr/share/cinnamon/cinnamon-settings/modules/cs_power.py adding a line there (I added the 3rd line):

Code: Select all

critical_options = [
("hibernate", _("Hibernate")),
("interactive", _("Ask what to do")),
("nothing", _("Do nothing"))
]
I was wondering if that's everything I need to do. Would then a window appear? That would be wonderful, as I might then choose to Hibernate, or to just save my work and shut down the laptop... or quickly run for the charger, plug the power source... and simply answer then "do nothing".

Will it work or am I missing something? :)
It looks like that will prompt the system "ask you what to do". However, What would it ask? I mean, where does the system get the options? Would it ask "do you want to shutdown?" or would it ask "Do you want mustard on your hot dog?". I may be wrong, but it just seems that you have to tell it what to ask you.

I changed mine to read:

Code: Select all

    critical_options = [
        ("nothing", _("Do nothing")),
        ("hibernate", _("Hibernate")),
        ("shutdown", _("Shutdown immediately"))
    ]
That way the system will give me those three options to choose from. But, if you tell the system to "Ask me what to do", what will it ask?
sverx
Level 2
Level 2
Posts: 73
Joined: Mon Oct 02, 2017 4:58 am

Re: I'd like Linux Mint to ask me what to do when battery gets critically low

Post by sverx »

mmm... that's exactly how it appears in the options for the power button

Code: Select all

POWER_BUTTON_OPTIONS = [
    ("blank", _("Lock the screen")),
    ("suspend", _("Suspend")),
    ("shutdown", _("Shutdown immediately")),
    ("hibernate", _("Hibernate")),
    ("interactive", _("Ask what to do")),
    ("nothing", _("Do nothing"))
]
so I was under the impression I would get the same effect. :?

Would I?
revian

Re: I'd like Linux Mint to ask me what to do when battery gets critically low

Post by revian »

sverx wrote:mmm... that's exactly how it appears in the options for the power button

Code: Select all

POWER_BUTTON_OPTIONS = [
    ("blank", _("Lock the screen")),
    ("suspend", _("Suspend")),
    ("shutdown", _("Shutdown immediately")),
    ("hibernate", _("Hibernate")),
    ("interactive", _("Ask what to do")),
    ("nothing", _("Do nothing"))
]
so I was under the impression I would get the same effect. :?

Would I?
Yes, but you see, there are several options there.. there are no such options in the critical battery power list. You could try what you are suggesting and see what happens.. the worst that could happen is the system throws an error and you can just revert your changes. Also, keep in mind, that if you choose anything other than "Shutdown immediately", the battery will continue to drain while you are looking for a place to plug in the power cord (this is why I added "Shutdown immediately").

I think your suggestion to add "Ask me what to do" will at least let you know that the battery is critically low, so it will have some benefit even if it doesn't offer many options.
sverx
Level 2
Level 2
Posts: 73
Joined: Mon Oct 02, 2017 4:58 am

Re: I'd like Linux Mint to ask me what to do when battery gets critically low

Post by sverx »

Yeah, I will try. I was just wondering if anyone had already done the same.
We'll see :D
revian

Re: I'd like Linux Mint to ask me what to do when battery gets critically low

Post by revian »

sverx wrote:Yeah, I will try. I was just wondering if anyone had already done the same.
We'll see :D
I hadn't done this until I saw your thread. So, thank you for posting your question. I always wondered why there was no option to Shutdown Immediately. I am on battery power right now, so I'll see what happens.

EDIT:
I just had a thought.. I will add "Shutdown immediately" and "Ask me what to do", that way I'll be prompted when the battery is critically low and I'll have the option to shutdown too. This way the system won't just shutdown if I'm in the middle of a long text or something.
revian

Re: I'd like Linux Mint to ask me what to do when battery gets critically low

Post by revian »

My battery just reached its critically low point and the laptop went into hibernate mode even though I had the setting set to "Ask me what to do". So, from what I can tell, it doesn't matter what you put into that /usr/share/cinnamon/cinnamon-settings/modules/cs_power.py file, the laptop will hibernate anyway. I'm thinking that the file is just a python interface to the actual power app and the power app itself doesn't have any other options besides hibernate or do nothing.
sverx
Level 2
Level 2
Posts: 73
Joined: Mon Oct 02, 2017 4:58 am

Re: I'd like Linux Mint to ask me what to do when battery gets critically low

Post by sverx »

Funny. According to the topic I linked to in the first post here, it worked with "Shutdown".

I'll run a few tests tomorrow, but it occurred to me to think that I instead should work on expanding Cinnamon power management applet so that it also have options to notify when battery is low and again notify when it's critical, similarly to what happens on Kubuntu (it gives you TWO alerts and on the second one you've got 60 seconds before the Hibernate/Shutdown takes place - plugging in the power would cancel the shutdown)
revian

Re: I'd like Linux Mint to ask me what to do when battery gets critically low

Post by revian »

sverx wrote:Funny. According to the topic I linked to in the first post here, it worked with "Shutdown".

I'll run a few tests tomorrow, but it occurred to me to think that I instead should work on expanding Cinnamon power management applet so that it also have options to notify when battery is low and again notify when it's critical, similarly to what happens on Kubuntu (it gives you TWO alerts and on the second one you've got 60 seconds before the Hibernate/Shutdown takes place - plugging in the power would cancel the shutdown)
Having two separate alerts would be nice, I wish someone would update Mint Cinnamon edition to have two alerts.. and to actually allow shutdown instead of hibernate.
sverx
Level 2
Level 2
Posts: 73
Joined: Mon Oct 02, 2017 4:58 am

Re: I'd like Linux Mint to ask me what to do when battery gets critically low

Post by sverx »

Wait a second... IT WORKS! :D

OK, apart from that change, I also had to tweak some parameters using dconf-editor. In branch "org.cinnamon.settings-daemon.plugins.power"
dconf.png
I changed percentage-critical to 5 and percentage-action to 4, but it's essential to set use-time-for-policy at false (unselected checkbox). As you can see, critical-battery-action is set to interactive, just like button-power (as I had set that the notebook power button should ask me what I'd like to do).

OK, so a few seconds after battery charge went down to 5%, a notification appeared on the top right of the screen, and a sound effect was reproduced (it was very low, but you can change the volume and/or the sound effect itself in Preferences > Sound > sound effect tab ). I didn't plug the charger and instead kept on waiting. A few seconds after battery charge went down to 4%, the "Shut down the system now?" dialog appeared, with all the options buttons below the question. I plugged in the charger and simply gave 'cancel' to the request.

Well, I would say that until they do something better (and I hope they will!), I can survive with this solution :)

I hope this will help other too!
revian

Re: I'd like Linux Mint to ask me what to do when battery gets critically low

Post by revian »

sverx wrote:Wait a second... IT WORKS! :D

OK, apart from that change, I also had to tweak some parameters using dconf-editor. In branch "org.cinnamon.settings-daemon.plugins.power"

dconf.png

I changed percentage-critical to 5 and percentage-action to 4, but it's essential to set use-time-for-policy at false (unselected checkbox). As you can see, critical-battery-action is set to interactive, just like button-power (as I had set that the notebook power button should ask me what I'd like to do).

OK, so a few seconds after battery charge went down to 5%, a notification appeared on the top right of the screen, and a sound effect was reproduced (it was very low, but you can change the volume and/or the sound effect itself in Preferences > Sound > sound effect tab ). I didn't plug the charger and instead kept on waiting. A few seconds after battery charge went down to 4%, the "Shut down the system now?" dialog appeared, with all the options buttons below the question. I plugged in the charger and simply gave 'cancel' to the request.

Well, I would say that until they do something better (and I hope they will!), I can survive with this solution :)

I hope this will help other too!
Ah, ok, now I think I see why I never got the interactive response upon critical battery percentage. I'll uncheck the use-time-for-policy option and try it again.

Thank you for relaying that information! :D
Locked

Return to “Cinnamon”