Link: https://wiki.debian.org/SystemdSuspendSedation
$ sudo nano /etc/systemd/system/suspend-sedation.service
[Unit]
Description=Hibernate after suspend
Documentation=https://bbs.archlinux.org/viewtopic.php?pid=1420279#p1420279
Documentation=https://bbs.archlinux.org/viewtopic.php?pid=1574125#p1574125
Documentation=https://wiki.archlinux.org/index.php/Power_management
Documentation=http://forums.debian.net/viewtopic.php?f=5&t=129088
Documentation=https://wiki.debian.org/SystemdSuspendSedation
Conflicts=hibernate.target hybrid-sleep.target
Before=sleep.target
StopWhenUnneeded=true
[Service]
Type=oneshot
RemainAfterExit=yes
Environment="ALARM_SEC=1800"
Environment="WAKEALARM=/sys/class/rtc/rtc0/wakealarm"
ExecStart=/usr/sbin/rtcwake --seconds $ALARM_SEC --auto --mode no
ExecStop=/bin/sh -c '\
ALARM=$(cat $WAKEALARM); \
NOW=$(date +%%s); \
if [ -z "$ALARM" ] || [ "$NOW" -ge "$ALARM" ]; then \
echo "suspend-sedation: Woke up - no alarm set. Hibernating..."; \
systemctl hibernate; \
else \
echo "suspend-sedation: Woke up before alarm - normal wakeup."; \
/usr/sbin/rtcwake --auto --mode disable; \
fi \
'
[Install]
WantedBy=sleep.target
enable it: sudo systemctl enable suspend-sedation