Ubuntu wakes up immediately after suspend -> how to fix it

Since I suddenly encountered this issue, probably after an update. I tried many solutions but none worked.

But then I found this, and it solved the problem for me.
I thought it would be a good idea to share it here:

The following is quoted from forementioned website.
In howto on Jun 18, 2016 by theoryl Tagged: acpi, linux, suspend, ubuntu

Sometimes when you try to suspend the Ubuntu operating system, it wakes up immediately.
This is often because certain devices are in “awake” state.
To fix it, first you need to find out which device it is.

acpitool -w

You might see output like the following:

Device	S-state	Status	Sysfs node
1. P0P1	S4	*disabled
2. GLAN	S4	*disabled
3. XHC	S4	*enabled

To disable ‘XHC’, do:

echo 'XHC' > /proc/acpi/wakeup

with superuser privilege.

The text mentioned XHC but in my case it were two other PCI devices (XHCI and RP05) that prevented suspend so change the command accordingly to whatever is appropriate in your case.

EDIT: if you don't have 'acpitool' installed you can get the same output using:

cat /proc/acpi/wakeup

To make this change permanent, add forementioned command to /etc/rc.local like this

cat <<\EOF  |sudo tee /etc/rc.local
#!/bin/sh -e
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
# In order to enable or disable this script just change the execution
# bits.
# By default this script does nothing.

echo 'XHC' > /proc/acpi/wakeup

exit 0

sudo chmod a+x /etc/rc.local