3

I typically put my laptop to sleep regularly, with two distinct cases:

  1. short periods (a few minutes) while I read/discuss something
  2. long periods (an hour or more) during lunch and commutes

I would like to know if there's a tool or script to decide, when I put the laptop to sleep, whether that sleep should be deep or s2idle, like making suspend_to_idle and suspend_to_deep set of commands.

Basically I could just write a script that toogles /sys/power/mem_sleep between these two options but a) that requires sudo and b) I'm not sure whether changes to the files are taken into account right away (I think so but I don't know where to check, so if someone knows, I'd appreciate that information).

EDIT: the rationale is obviously to use s2idle for the short-duration sleep periods to avoid the 15-30 seconds of sluggish behavior that occur when the laptop emerges from deep sleep while still using the latter to conserve battery during the longer sleep periods.

3
  • You say: I would like to know if there's a tool or script and then: I ended up writing a script to toggle /sys/power/mem_sleep. Isn't that the answer already? This looks like an answered question (that's why you don't get new answers too) and you should post the script you have as an answer under the question because people (including me) may like to use it. - I had no idea what these options were but figured it out in the end although I still have problems, where my s2idle is reset and I have to re-run the command at each startup.
    – cipricus
    Commented Aug 28, 2023 at 6:22
  • 1
    you're right, I'll make a reply Commented Aug 30, 2023 at 6:48
  • Great! But for reference I have to say that I have a lot of problems with this setting on a Mac: and they keep changing after kernel updates. You can see the history of this in the linked answer. But after the last update this setting doesn't work; the opposite to what that link tackles happens: the laptop wakes up instantly, no matter the setting. I prefer that to the opposite, but I'd like to be able to decide with your script. Thanks anyway.
    – cipricus
    Commented Aug 30, 2023 at 20:57

3 Answers 3

2

I ended up writing a script to toggle /sys/power/mem_sleep so I can confirm changes are taken into account immediately; it's a bit tedious but it works.

fcontent=$(cat /sys/power/mem_sleep)

if [ "$fcontent" = "s2idle [deep]" ]; then
        echo "s2idle" | sudo tee /sys/power/mem_sleep
else
        echo "deep" | sudo tee /sys/power/mem_sleep
fi;
1

As an alternative or complement to the main answer:

I have created two separate scripts (in ~/bin) and two corresponding launchers:

suspend_deep.sh:

#!/bin/sh

echo deep | sudo tee -a /sys/power/mem_sleep

suspend idle:

#!/bin/sh

echo s2idle | sudo tee -a /sys/power/mem_sleep

The launchers in ~/.local/share/applications:

[Desktop Entry]
Exec=pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY KDE_SESSION_VERSION=5 KDE_FULL_SESSION=true ~/bin/suspend_deep.sh
Icon=system-suspend
Name[en_US]=Suspend deep
Name=Suspend deep
Type=Application
Terminal=false

and:

[Desktop Entry]
Exec=pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY KDE_SESSION_VERSION=5 KDE_FULL_SESSION=true ~/bin/suspend_idle.sh
Icon=system-suspend
Name[en_US]=Suspend idle
Name=Suspend idle
Type=Application
Terminal=false

Compared to the switch, which simply changes the present state, this solution can be useful when the present state is not already known or doesn't work as expected, as it happened to me.

0

If your motherboard and kernel support both s2idle and s2ram, you can run these commands to trigger suspend immediately with your desired state.

for s2ram:

echo "mem" > /sys/power/state

for s2idle:

echo "freeze" > /sys/power/state

It might be different in your system. just check what are your options with:

cat /sys/power/state

But i could not find a way to make it happen without root previledges.

2
  • it requires priviledges, you can find the recommended way to do this in the two previous answers Commented Mar 19 at 10:19
  • @Silmathoron You're right. but that way only changes the suspend method. What I said triggers suspend just after the command.
    – medicamin
    Commented Mar 20 at 11:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .