I am using XFCE and in Settings Manager->Power Manager->Laptop Lid I have set the condition: When laptop lid is closed and On battery - to Hibernate.
However if the lid is closed and the power goes off the laptop stays on. The only way to hibernate it in this situation is to open the lid and close it again - then it hibernates.
I want to make it automatically hibernate when the power goes off (if the lid is closed) without the need of human intervention.
Another problem I am facing actually is that currently after the lid close (with power off) the PC actually “does something” (which I don’t know if it is hibernation or shutdown) but after powering it on it starts the whole boot up process and I don’t know why.
This means system must briefly power on to perform hibernation. So far systemd upstream was reluctant to implement it, because if system powers on in your rucksack and fails to hibernate it can damage itself. I had such case once.
So your alternatives are
use hybrid-suspend. It performs suspend and hibernation at the same time, so while it takes longer to finish, but it combines fast resume and persistent store.
Sorry, I misunderstood you, I assumed system is suspended on lid close.
One possibility is to add ACPI even handler for AC OFF event. See https://wiki.archlinux.org/index.php/Acpid for example. Whether Xfce power manager supports it I do not know; it is probably better asked on their forums.
Thank you, I will try with acpid. However there seems to be a bug. I remember when I used 12.2 on the same laptop, the hibernation worked exactly as I want it. Now I don’t even understand why the system boots as from initial startup when I press the power on button (after it has been hibernated manually).