You can run the (very low on juice) background script, which will suspend the computer, rounded on 10 seconds:
# --- set idle time below (seconds)
idle_set = 1200
return int([l.strip().split().replace("packets:", "") for l in \
if " RX " in l])
data1 = get_packets()
t = 0
data2 = get_packets()
if data2 - data1 > 3000:
t = 0
t += 10
idletime = get_idle()
if all([idletime > idle_set, t > idle_set]):
subprocess.Popen(["systemctl", "suspend", "-i"])
data1 = data2
What it does
- Once per 10 seconds, it checks the current received amount of data, comparing it with 10 seconds ago (using
ifconfig). If it exceeds a certain amount, the "counter" is set to zero, else a0 seconds is added to the "stream" -idle time.
- Also once per 10 seconds it looks at the "general" idle-time, using
If both exceed the set time (in the head of the script), the computer is put to sleep.
How to set up
The script needs
sudo apt-get xprintidle
Copy the script into an empty file, save it as
- In the head section of the script, set the desired idle time
Test- rfun it by the command:
If all works fine, add it to Startup Applications.
This answer assumes traffic is via Ethernet connection. If not, the function
get_packets() possibly needs a small edit.