Skip to main content

Getting rtcwake working on Bluefin

#!/bin/bash
# User systemd setup for auto suspend/wake on Bluefin

#Please run these two commands manually:

#1. First, create the sudo rule:
echo "$(whoami) ALL=(ALL) NOPASSWD: /usr/bin/rtcwake" | sudo tee /etc/sudoers.d/rtcwake-nopasswd
#bash
#2. Then set the correct permissions:
sudo chmod 440 /etc/sudoers.d/rtcwake-nopasswd
#bash
#After you've run those commands, we can test if passwordless sudo works:
sudo rtcwake -m show
#❯ sudo rtcwake -m show
#alarm: off

# Create user service directory

mkdir -p ~/.config/systemd/user

# Create helper script for suspend + rtcwake
mkdir -p ~/bin
cat > ~/bin/rtc-suspend.sh << 'EOF'
#!/bin/bash
# Helper script to suspend and set RTC wake time
# Usage: rtc-suspend.sh "wake_time_description"

if [ $# -ne 1 ]; then
echo "Usage: $0 'wake_time_description'"
echo "Example: $0 '15:00 today'"
exit 1
fi

wake_time="$1"
wake_timestamp=$(date -d "$wake_time" +%s)

if [ $? -ne 0 ]; then
echo "Error: Invalid time format '$wake_time'"
exit 1
fi

echo "Setting RTC wake for: $(date -d @$wake_timestamp)"

# Set the RTC wake time first (before suspend)
sudo rtcwake -m no -t $wake_timestamp

if [ $? -eq 0 ]; then
echo "RTC wake time set successfully"
# Small delay then suspend
sleep 2
systemctl suspend
else
echo "Error: Failed to set RTC wake time"
exit 1
fi
EOF

chmod +x ~/bin/rtc-suspend.sh

# Create the morning suspend service (9 AM - 3 PM)
cat > ~/.config/systemd/user/morning-suspend.service << 'EOF'
[Unit]
Description=Suspend system at 9 AM until 3 PM
After=graphical-session.target

[Service]
Type=oneshot
Environment=PATH=/usr/local/bin:/usr/bin:/bin:%h/bin
ExecStart=%h/bin/rtc-suspend.sh "15:00 today"
Restart=no

[Install]
WantedBy=default.target
EOF

# Create the evening suspend service (9 PM - 5 AM)
cat > ~/.config/systemd/user/evening-suspend.service << 'EOF'
[Unit]
Description=Suspend system at 9 PM until 5 AM tomorrow
After=graphical-session.target

[Service]
Type=oneshot
Environment=PATH=/usr/local/bin:/usr/bin:/bin:%h/bin
ExecStart=%h/bin/rtc-suspend.sh "05:00 tomorrow"
Restart=no

[Install]
WantedBy=default.target
EOF

# Create timer for 9 AM suspend
cat > ~/.config/systemd/user/morning-suspend.timer << 'EOF'
[Unit]
Description=Trigger morning suspend at 9 AM
Requires=morning-suspend.service

[Timer]
OnCalendar=*-*-* 09:00:00
Persistent=true
AccuracySec=1min

[Install]
WantedBy=timers.target
EOF

# Create timer for 9 PM suspend
cat > ~/.config/systemd/user/evening-suspend.timer << 'EOF'
[Unit]
Description=Trigger evening suspend at 9 PM
Requires=evening-suspend.service

[Timer]
OnCalendar=*-*-* 21:00:00
Persistent=true
AccuracySec=1min

[Install]
WantedBy=timers.target
EOF

echo "Setting up user systemd services..."

# Reload user systemd daemon
systemctl --user daemon-reload

# Enable the services
systemctl --user enable morning-suspend.timer
systemctl --user enable evening-suspend.timer
#systemctl --user enable wake-notification.service

# Start the timers
systemctl --user start morning-suspend.timer
systemctl --user start evening-suspend.timer

# Enable lingering so services run when not logged in
sudo loginctl enable-linger $USER

echo ""
echo "=== SETUP COMPLETE ==="
echo ""
echo "Your system will now:"
echo " • Suspend at 9:00 AM and wake at 3:00 PM"
echo " • Suspend at 9:00 PM and wake at 5:00 AM"
echo ""
echo "Active hours:"
echo " • 5:00 AM - 9:00 AM (4 hours)"
echo " • 3:00 PM - 9:00 PM (6 hours)"
echo ""
echo "=== TESTING ==="
echo "Test your RTC wake capability first:"
echo " sudo rtcwake -m mem -s 30 # 30-second test"
echo ""
echo "Test the helper script:"
echo " ~/bin/rtc-suspend.sh '$(date -d '+2 minutes' +'%H:%M today')'"
echo ""
echo "=== MONITORING ==="
echo "Check timer status:"
echo " systemctl --user list-timers"
echo ""
echo "View service logs:"
echo " journalctl --user -u morning-suspend.service"
echo " journalctl --user -u evening-suspend.service"
echo ""
echo "=== CONTROL ==="
echo "Disable (stop automatic suspend):"
echo " systemctl --user stop morning-suspend.timer evening-suspend.timer"
echo " systemctl --user disable morning-suspend.timer evening-suspend.timer"
echo ""
echo "Re-enable:"
echo " systemctl --user enable morning-suspend.timer evening-suspend.timer"
echo " systemctl --user start morning-suspend.timer evening-suspend.timer"
echo ""
echo "=== TROUBLESHOOTING ==="
echo "If suspend doesn't work, check:"
echo " 1. Your user can suspend: 'systemctl suspend'"
echo " 2. RTC wake works: 'sudo rtcwake -m mem -s 30'"
echo " 3. User lingering is enabled: 'loginctl show-user $USER'"
echo ""
echo "Common issues on Bluefin:"
echo " • May need to add user to 'wheel' group for suspend permissions"
echo " • Some hardware doesn't support RTC wake from suspend"
echo " • Check BIOS/UEFI settings for wake-on-RTC support"



Comments

Popular posts from this blog

Install Windows 11 on Virt-Manager

 Virt-Manager will have been installed in base install.  But to enable it (make sure SVM, or whatever virtualization is called in your BIOS is enabled). From https://computingforgeeks.com/install-kvm-qemu-virt-manager-arch-manjar/ sudo pacman -S qemu-full virt-manager virt-viewer dnsmasq vde2 bridge-utils openbsd-netcat dmidecode ip tables libguestfs edk2-ovmf swtpm Then enable and start libritd.service sudo systemctl enable libvirtd.service sudo systemctl start libvirtd.service sudo micro /etc/libvirt/libvirtd.conf Set the UNIX domain socket group ownership to libvirt, (around line 85 ) unix_sock_group = "libvirt" Set the UNIX socket permissions for the R/W socket (around line 102 ) unix_sock_rw_perms = "0770" Add your user account to libvirt group.   sudo usermod -a -G libvirt $(whoami) newgrp libvirt Restart libvirt daemon. sudo systemctl restart libvirtd.service Section below is quoted directly from https://linustechtips.com/topic/1379063-windows-11-in-virt-mana...

Base Install

This blog is for my notes on setting up Arch from scratch to my liking. I use KDE Plasma as my desktop and my computers have a NVIDIA GPU (my Asus laptop also has an additional integrated GPU). I am not going to cover downloading the ISO, putting it on a USB, booting from the USB or running the Archinstall installer (selecting the Plasma desktop). Get WIFI running iwctl station wlan0 connect xxxxxxx May need:  sudo mkfs -t ext4 /dev/nvme1n1 if you have btrfs on old installation When running the arch installer: 1. Don't have a /home partition added!  2. Don't forget desktop! 3. Install both linux and linux-zen kernels 4. Add additional packages:  wget git micro duf base-devel kde-applications to log in the first time it may be helpful to create /usr/lib/modprobe.d/nvidia.conf with "options nvidia_drm modeset=1 fbdev=1"   (although cachyos-settings will overwrite later) Apparmor  Add the following kernel parameters to your Boot Manager, see  Boot Manage...

Fedora Install Notes

  Many of the steps in setting up Fedora are the same as I do for Arch.  My preferred install is Fedora Rawhide.  You are better off with the default "Gnome" desktop than trying the KDE spin (seems to be the best integrated experience with few/no hardware/GPU issues). Helpful notes to me: Initial "get started" installs: sudo dnf in R bat btrfs-assistant cmake duf fastfetch fish fontawesome-fonts-all freetype-devel fribidi-devel gnome-extensions-app gnome-tweaks htop inxi java-latest-openjdk-devel jetbrains-mono-fonts kitty kmymoney lftp libcurl-devel libjpeg-turbo-devel libpng-devel libtiff-devel llvm-devel meson micro onedrive python3-colorama python3-ipykernel python3-pip python3-pyquery sqlitebrowser tcl8-devel tk8-devel typescript xsane zsh Snapper: do rollback: Use sudo snapper ls to list all available snapshots and their corresponding numbers. Note the number of the snapshot you want to revert to. Open a terminal and use the following command: sudo snapper ro...