# SLEEP support development for CM4

**URL:** <https://forum.clockworkpi.com/t/sleep-support-development-for-cm4/14797>\
**Category:** uConsole\
**Created:** [November 2, 2024, 2:49am UTC](https://forum.clockworkpi.com/t/sleep-support-development-for-cm4/14797 "2024-11-02T02:49:01Z")\
**Posts on this page:** 14\
**Page:** 4

<div class="post-metadata">

**Author:** ![graynada](https://yyz1.discourse-cdn.com/flex029/user_avatar/forum.clockworkpi.com/graynada/32/10482_2.png) [@graynada](https://forum.clockworkpi.com/u/graynada)\
**Post date:** [February 4, 2025, 10:10am UTC](https://forum.clockworkpi.com/t/sleep-support-development-for-cm4/14797/61 "2025-02-04T10:10:22Z")

</div>

I had a play around with this too for KDE Wayland and didn’t get too much further.

- I bound the sleep.sh to a custom keyboard shortcut instead of the power button. For note I would ssh the scripts just to confirm it was not keyboard shortcut affecting the tests below.
- I did get kscreen-doctor to turn off the screen but the call never exits, despite my best efforts, and thus I couldn’t get the screen back on without rebooting. I have read this is a known issue and is fixed in Plasma 6 (I think)
- I opted for the dim/undim screen route, turn Bluetooth off/on, switch to powersave and was using that for a while
- I couldn’t get the killing processes to work as again despite my best efforts I must have always been killing something vital as once invoked I had to reboot to recover.

Since my latest install though I haven’t bothered with the sleep because despite everything i did I didn’t notice and real change in battery usage over stock KDE management

I would be interested to see what results people are getting from custom sleep over stock, if anyone has any data to share.

---

<div class="post-metadata">

**Author:** ![Hector\_Corea](https://yyz1.discourse-cdn.com/flex029/user_avatar/forum.clockworkpi.com/hector_corea/32/9126_2.png) [@Hector\_Corea](https://forum.clockworkpi.com/u/Hector_Corea)\
**Post date:** [February 4, 2025, 2:58pm UTC](https://forum.clockworkpi.com/t/sleep-support-development-for-cm4/14797/62 "2025-02-04T14:58:42Z")

</div>

Interesting, I suppose there is no workaround (for the time being) if you use KDE.

I decided to switch to X11 instead of Wayfire because the scaling on X11 is way better and uniform and it helps me read stuff better (I have [Presbyopia](https://healthjade.net/presbyopia/). )  
I was determined to use Wayland because I’ve read a bit about it and it seemed to be theoretically more efficient, based on its architecture, but I couldn’t really benchmark it so it was just a hunch.

In any case, without knowing how to map the Shellscript to the power button and without being able to exit the qsleep state through keyboard, this specific script is unusable in KDE. I’ll try to replicate your script (in KDE) based on what you mentioned you did

- Turn off screen
- Turn off WiFi
- Turn off BlueTooth
- Enter powersave

Not only because I want to save battery life, but because I want to be able to “turn off the device” in a quick way and still save the state of my work and avoid a rise of temperature if I have to put the uConsole inside a backpack.

This scenario is common for me. I’m fiddling with the uConsole, I have terminals and browsers open, maybe emacs, and my wife tells me she’s ready to go, so I would like to “turn off” and “turn it on” on a whim.

---

<div class="post-metadata">

**Author:** ![Hector\_Corea](https://yyz1.discourse-cdn.com/flex029/user_avatar/forum.clockworkpi.com/hector_corea/32/9126_2.png) [@Hector\_Corea](https://forum.clockworkpi.com/u/Hector_Corea)\
**Post date:** [February 4, 2025, 4:14pm UTC](https://forum.clockworkpi.com/t/sleep-support-development-for-cm4/14797/64 "2025-02-04T16:14:07Z")

</div>

Wait, but it is my understanding that hibernate is not supported on the CM4, and that’s why this script was created.

Sources:  
[Supespend and battery life - uConsole - clockworkpi](https://forum.clockworkpi.com/t/supespend-and-battery-life/10412)

Also, I decided to try `sudo systemctl hibernate`. I got this error: `Call to Hibernate failed: Sleep verb "hibernate" not supported`. I also tried the suspend variant and got the same error.

I tried to map a shortcut to the Hibernate action in Settings → Workspace → Shortcuts → Power Management, but I only got the screen to “turn off” (Mouse was still visible) and the behaviour was funky overall (Ctrl + Alt would return the screen back to normal, pressing the power button would bring the shutdown menu) so yeah… hibernate doesn’t really seem to be implemented.

---

<div class="post-metadata">

**Author:** ![graynada](https://yyz1.discourse-cdn.com/flex029/user_avatar/forum.clockworkpi.com/graynada/32/10482_2.png) [@graynada](https://forum.clockworkpi.com/u/graynada)\
**Post date:** [February 4, 2025, 5:22pm UTC](https://forum.clockworkpi.com/t/sleep-support-development-for-cm4/14797/65 "2025-02-04T17:22:05Z")

</div>

I went back and looked at my last code and what I did was link power saving to lockscreen. I set up a listener for change in state of lockscreen and then ran powersave settings on lock, and return to normal on unlock. I wasn’t doing anything to turn off the screen, just relying on the power settings for the lockscreen to take care of this.

I ended up using 2 scripts, a python one for the listener and bash for the power saving. I couldn’t get the power savings to be noticeably different to just locking screen but here is my code if it is of nay use

`lockread.sh`

```python
#!/usr/bin/env python3

import dbus
from dbus.mainloop.glib import DBusGMainLoop
import os

powersave_on = False

def screensaver_changed(state):
    global powersave_on
    """This method is called when the screensaver starts/stops (for some reason gets called twice for each change)"""
    screensaver = session_bus.get_object('org.freedesktop.ScreenSaver', '/ScreenSaver')
    active = screensaver.GetActive()
    print("ScreenSaver is " + ("on" if active else "off"))
    if active and not powersave_on:
        os.system("~/.config/myscripts/powersave.sh on")
        powersave_on = True
    elif not active and powersave_on:
        os.system("~/.config/myscripts/powersave.sh off")
        powersave_on = False

DBusGMainLoop(set_as_default=True)
session_bus = dbus.SessionBus()
session_bus.add_signal_receiver(screensaver_changed, 'ActiveChanged', 'org.freedesktop.ScreenSaver')

from gi.repository import GLib
loop = GLib.MainLoop()
loop.run()

```

`powersave.sh` you could add WiFi off and on here

```bash
#!/bin/bash

if [$1 = "on"]; then
    echo "powersave" | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
    bluetoothctl power off
elif [$1 = "off"]; then
    echo "ondemand" | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
    bluetoothctl power on
fi

```

---

<div class="post-metadata">

**Author:** ![Hector\_Corea](https://yyz1.discourse-cdn.com/flex029/user_avatar/forum.clockworkpi.com/hector_corea/32/9126_2.png) [@Hector\_Corea](https://forum.clockworkpi.com/u/Hector_Corea)\
**Post date:** [February 4, 2025, 5:38pm UTC](https://forum.clockworkpi.com/t/sleep-support-development-for-cm4/14797/66 "2025-02-04T17:38:38Z")

</div>

I might try it… when I fix the disaster I made hahaha.  
I changed the behaviour of the power button through KDE settings and linked it to a `shutdown now` shellscript.  
As soon as I did that, the uConsole turned off and now, whenever gdm finishes loading … I think the button event is called? I can’t get to the desktop because the uConsole turns off itself hahaha. ( suspect the shell is called)

I am currently looking for a way to interupt the load of GDM or maybe jump directly into TTY os that I can modify the script and comment the command, but I haven’t found a way to do so. If I can’t find a way to do it, then I will try to read the filesystem with my fedora laptop at home and edit the script.  
If even that laptop can’t read the filesystem (I tried on my phone but I couldn’t see any file per se) then I will just wipe out the card with Rex’s image again… I mean, it’s no big deal but I want to learn how to boot into terminal in cases of emergency where you can’t or should not load the UI at all despite having one.

But I think I will open a new thread and stop chnaging the subject of this topic even more.

---

<div class="post-metadata">

**Author:** ![graynada](https://yyz1.discourse-cdn.com/flex029/user_avatar/forum.clockworkpi.com/graynada/32/10482_2.png) [@graynada](https://forum.clockworkpi.com/u/graynada)\
**Post date:** [February 4, 2025, 6:21pm UTC](https://forum.clockworkpi.com/t/sleep-support-development-for-cm4/14797/67 "2025-02-04T18:21:37Z")

</div>

You will be able to read the file system, either the uSD or eMMC, on your Fedora laptop and modify the script

---

<div class="post-metadata">

**Author:** ![white-round-square](https://yyz1.discourse-cdn.com/flex029/user_avatar/forum.clockworkpi.com/white-round-square/32/10385_2.png) [@white-round-square](https://forum.clockworkpi.com/u/white-round-square)\
**Post date:** [February 4, 2025, 6:29pm UTC](https://forum.clockworkpi.com/t/sleep-support-development-for-cm4/14797/69 "2025-02-04T18:29:38Z")

</div>

> [@Hector\_Corea](#):
>
> Wait, but it is my understanding that hibernate is not supported on the CM4, and that’s why this script was created.

wow, i’m sorry, I couldn’t imagined that something can doesn’t support event hibernating in modern times.

my fault.

---

<div class="post-metadata">

**Author:** ![Hector\_Corea](https://yyz1.discourse-cdn.com/flex029/user_avatar/forum.clockworkpi.com/hector_corea/32/9126_2.png) [@Hector\_Corea](https://forum.clockworkpi.com/u/Hector_Corea)\
**Post date:** [February 4, 2025, 6:33pm UTC](https://forum.clockworkpi.com/t/sleep-support-development-for-cm4/14797/70 "2025-02-04T18:33:47Z")

</div>

I know right! haha, but it’s part of the fun I guess. 😂

---

<div class="post-metadata">

**Author:** ![white-round-square](https://yyz1.discourse-cdn.com/flex029/user_avatar/forum.clockworkpi.com/white-round-square/32/10385_2.png) [@white-round-square](https://forum.clockworkpi.com/u/white-round-square)\
**Post date:** [February 4, 2025, 6:35pm UTC](https://forum.clockworkpi.com/t/sleep-support-development-for-cm4/14797/71 "2025-02-04T18:35:22Z")

</div>

> [@Simple Screen off and Power-saving Service for uConsole](https://forum.clockworkpi.com/t/simple-screen-off-and-power-saving-service-for-uconsole/15612/2):
>
> Known issues In some cases, User input (mouse, keyboard) is required after pressing the power key in any S2Idle state. Others

---

<div class="post-metadata">

**Author:** ![Hector\_Corea](https://yyz1.discourse-cdn.com/flex029/user_avatar/forum.clockworkpi.com/hector_corea/32/9126_2.png) [@Hector\_Corea](https://forum.clockworkpi.com/u/Hector_Corea)\
**Post date:** [February 5, 2025, 10:26pm UTC](https://forum.clockworkpi.com/t/sleep-support-development-for-cm4/14797/72 "2025-02-05T22:26:22Z")

</div>

I have some questions

- What’s the right way to go? using `scaling_governor` or `scaling_max_freq`?
- Also, should I use only cpu0 and cpu1 or cpu\* (seeing my cpu folder has 4 cpu subfolders 0 …3)
- In which section should one write the over\_voltage\_min, arm\_freq\_min and gpu\_freq\_min lines.
- When do those values (previous line) go back to normal? Does the OS know they’re just for idle?

I’m trying to make my custom sh jus because, but I am curious as to why people uses different files and configs.

---

<div class="post-metadata">

**Author:** ![white-round-square](https://yyz1.discourse-cdn.com/flex029/user_avatar/forum.clockworkpi.com/white-round-square/32/10385_2.png) [@white-round-square](https://forum.clockworkpi.com/u/white-round-square)\
**Post date:** [February 5, 2025, 11:17pm UTC](https://forum.clockworkpi.com/t/sleep-support-development-for-cm4/14797/73 "2025-02-05T23:17:50Z")

</div>

> [@Hector\_Corea](#):
>
> I’m trying to make my custom sh jus because, but I am curious as to why people uses different files and configs.

because they want to write their own custom shell scripts 😂 🤣 😁

---

<div class="post-metadata">

**Author:** ![Hector\_Corea](https://yyz1.discourse-cdn.com/flex029/user_avatar/forum.clockworkpi.com/hector_corea/32/9126_2.png) [@Hector\_Corea](https://forum.clockworkpi.com/u/Hector_Corea)\
**Post date:** [February 6, 2025, 12:05am UTC](https://forum.clockworkpi.com/t/sleep-support-development-for-cm4/14797/74 "2025-02-06T00:05:45Z")

</div>

Hahaha seems like it’s a common practice 🤣

---

<div class="post-metadata">

**Author:** ![hpsaturn](https://yyz1.discourse-cdn.com/flex029/user_avatar/forum.clockworkpi.com/hpsaturn/32/8358_2.png) [@hpsaturn](https://forum.clockworkpi.com/u/hpsaturn)\
**Post date:** [July 3, 2025, 5:30pm UTC](https://forum.clockworkpi.com/t/sleep-support-development-for-cm4/14797/75 "2025-07-03T17:30:12Z")

</div>

Around this topic. Maybe someone knows if is possible suspending and hibernating with the new CM5 modules over the original uConsole hardware? I mean, only changing the CM4 module by the new CM5 module.

---

<div class="post-metadata">

**Author:** ![white-round-square](https://yyz1.discourse-cdn.com/flex029/user_avatar/forum.clockworkpi.com/white-round-square/32/10385_2.png) [@white-round-square](https://forum.clockworkpi.com/u/white-round-square)\
**Post date:** [July 3, 2025, 8:55pm UTC](https://forum.clockworkpi.com/t/sleep-support-development-for-cm4/14797/76 "2025-07-03T20:55:47Z")

</div>

> [@hpsaturn](#):
>
> Maybe someone knows if is possible suspending and hibernating with the new CM5

you can check this topic: [uConsole-Sleep v1.3](https://forum.clockworkpi.com/t/uconsole-sleep-v1-3/15612)

it’s not a real sleep, but people happy with it

[Previous page](https://forum.clockworkpi.com/t/sleep-support-development-for-cm4/14797.md?page=3)
