You can use "!=" or completely remove ATTR{capacity}=="95", and check the charge in script instead!
]]>Did you forget to do udevadm control --reload as root after writing the rule?
Yes, I did. But as I run it now with battery at 55%, the system still not hibernates, which bares the question whether it is because the rule runs only on = instaed of <=.
]]>If that really doesn't work, try to remove ATTR{status} from the rule (as I see "Unknown" in your udev info), and instead of systemd provide your own script.
In the script you determine whether ac is on or not and then hibernate.
looking at device '/devices/LNXSYSTM:00/LNXSYBUS:00/PNP0A08:00/device:00/PNP0C09:00/PNP0C0A:00/power_supply/BAT0':
KERNEL=="BAT0"
SUBSYSTEM=="power_supply"
DRIVER==""
ATTR{type}=="Battery"
ATTR{power_now}=="0"
ATTR{alarm}=="2045000"
ATTR{capacity}=="97"
ATTR{status}=="Unknown"
ATTR{voltage_now}=="12471000"
ATTR{energy_now}=="40080000"
ATTR{model_name}=="42T5233"
ATTR{manufacturer}=="Panasonic"
ATTR{technology}=="Li-ion"
ATTR{cycle_count}=="0"
ATTR{energy_full_design}=="51830000"
ATTR{voltage_min_design}=="10800000"
ATTR{serial_number}==" 1954"
ATTR{energy_full}=="40900000"
ATTR{present}=="1"
and I wrote the rule
/etc/udev/rules.d/85-autohibernate.rules
## SLEEP/HIBERNATE IF BATTERY IS LOW
SUBSYSTEM=="power_supply", ATTR{type}=="Battery", ATTR{status}=="Discharging", ATTR{capacity}=="95", RUN+="/usr/bin/systemctl suspend"
but it does not sleep on or below 95%.
]]>:find /sys|grep BAT
On my system there is BAT1 entry and battery sends udev event on discharging by 1 percent.
]]> looking at device '/devices/LNXSYSTM:00/LNXSYBUS:00/PNP0A08:00/device:00/PNP0C09:00/ACPI0003:00/power_supply/AC':
KERNEL=="AC"
SUBSYSTEM=="power_supply"
DRIVER==""
ATTR{type}=="Mains"
ATTR{online}=="1"
looking at parent device '/devices/LNXSYSTM:00/LNXSYBUS:00/PNP0A08:00/device:00/PNP0C09:00/ACPI0003:00':
KERNELS=="ACPI0003:00"
SUBSYSTEMS=="acpi"
DRIVERS=="ac"
ATTRS{hid}=="ACPI0003"
ATTRS{path}=="\_SB_.PCI0.LPC_.EC__.AC__"
looking at parent device '/devices/LNXSYSTM:00/LNXSYBUS:00/PNP0A08:00/device:00/PNP0C09:00':
KERNELS=="PNP0C09:00"
SUBSYSTEMS=="acpi"
DRIVERS=="ec"
ATTRS{hid}=="PNP0C09"
ATTRS{path}=="\_SB_.PCI0.LPC_.EC__"
looking at parent device '/devices/LNXSYSTM:00/LNXSYBUS:00/PNP0A08:00/device:00':
KERNELS=="device:00"
SUBSYSTEMS=="acpi"
DRIVERS==""
ATTRS{path}=="\_SB_.PCI0.LPC_"
looking at parent device '/devices/LNXSYSTM:00/LNXSYBUS:00/PNP0A08:00':
KERNELS=="PNP0A08:00"
SUBSYSTEMS=="acpi"
DRIVERS=="pci_root"
ATTRS{hid}=="PNP0A08"
ATTRS{path}=="\_SB_.PCI0"
looking at parent device '/devices/LNXSYSTM:00/LNXSYBUS:00':
KERNELS=="LNXSYBUS:00"
SUBSYSTEMS=="acpi"
DRIVERS==""
ATTRS{hid}=="LNXSYBUS"
ATTRS{path}=="\_SB_"
looking at parent device '/devices/LNXSYSTM:00':
KERNELS=="LNXSYSTM:00"
SUBSYSTEMS=="acpi"
DRIVERS==""
ATTRS{hid}=="LNXSYSTM"
ATTRS{path}=="\"
The thing is that "ATTR{type}=="Mains" stays as "Mains even on battery, only ATTR{online}=="1" changes to "0".
How would a dev rule look in this case?
Also, I noticed your rule would kick in only if the battery is at 1%, so if I change it to 3%, it will kick in only if the battery value is at 3, but not below.
]]>This for example:
## SLEEP IF BATTERY IS LOW
SUBSYSTEM=="power_supply", ATTR{type}=="Battery", ATTR{status}=="Discharging", ATTR{capacity}=="1", RUN+="/usr/bin/systemctl hibernate"
That way you even don't need acpid at all.
]]>battery)
if [[ $(acpi|grep "Discharging, 1%") ]]; then
systemctl hibernate
fi
;;
This works perfectly for me. You can replace 1% for any remaining charge level you like.
]]>So, the final result should be something like that?
#!/bin/sh
function payload() {
while [ true ]; do
if grep -q 1 /sys/class/power_supply/AC/online; then
exit 0
fi
AVG=`cat /sys/devices/platform/smapi/BAT0/remaining_percent`
if [ "$AVG" -le "92" ]; then
hibernate
fi
date
sleep 1
done
}
source path/to/daemon-functions.sh
Where should I place the finished daemon file? I imagine it supposed to be in some specific location if it's to be run from rc.conf
]]>I haven't found that myself. Looks promissing, but am I supposed to replace "checkforterm" with the script for my battery?
Exactly and, if you want, how frequent the daemon should check the battery (sleep 1).
]]>Ha, bummer then.
But I tried this, and it works:
#!/bin/sh if grep -q 1 /sys/class/power_supply/AC/online; then exit 0 fi AVG=`cat /sys/devices/platform/smapi/BAT0/remaining_percent` if [ "$AVG" -le "92" ]; then hibernate fi
But how to I make a daemon out of it?
Here is the first result looking for "bash daemon" on google http://blog.apokalyptik.com/2008/05/09/ … ripts-get/
]]>But I tried this, and it works:
#!/bin/sh
if grep -q 1 /sys/class/power_supply/AC/online; then
exit 0
fi
AVG=`cat /sys/devices/platform/smapi/BAT0/remaining_percent`
if [ "$AVG" -le "92" ]; then
hibernate
fi
But how to I make a daemon out of it?
]]>