Laptop wakes from sleep if bluetooth is enabled

If that still doesn’t work try adding this to the suspend script:

systemctl stop bluetooth.service

Add this to the resume script:

systemctl start bluetooth.service

Haven’t tried this yet, but wanted to say… something new and weird is now happening. The laptop won’t suspend again after I modified my resume script per your specifications above. I see this when I check the status of the suspend script:

● bluetooth-suspend.service - Bluetooth module suspend helper
   Loaded: loaded (/etc/systemd/system/bluetooth-suspend.service; enabled; vendor preset: disabled)
   Active: inactive (dead)

Aug 03 11:18:38 merlin-xiaomi-1 systemd[1]: Started Bluetooth module suspend helper.
Aug 03 11:19:11 merlin-xiaomi-1 systemd[1]: Started Bluetooth module suspend helper.
Aug 03 11:21:12 merlin-xiaomi-1 systemd[1]: Started Bluetooth module suspend helper.
Aug 03 11:21:43 merlin-xiaomi-1 systemd[1]: Started Bluetooth module suspend helper.
**Aug 03 11:21:43 merlin-xiaomi-1 bluetooth-suspend.sh[2807]: modprobe: ERROR: could not remove 'btintel': Resource temporarily unavailable**
Aug 03 11:22:19 merlin-xiaomi-1 systemd[1]: Started Bluetooth module suspend helper.

Try this instead:

sudo systemctl disable bluetooth-resume.service
sudo systemctl stop bluetooth-resume.service

Create:

/etc/systemd/system/bluetooth-reload.service
[Unit]
Description=Reload bluetooth driver after system resume
After=hibernate.target suspend.target hybrid-sleep.target

[Service]
Type=oneshot
TimeoutSec=15
ExecStart=/usr/sbin/modprobe btusb

[Install]
WantedBy=hibernate.target suspend.target hybrid-sleep.target

Save the file with root permissions, and then make it executable:

sudo chmod +x /etc/systemd/system/bluetooth-reload.service
sudo systemctl enable bluetooth-reload.service

Reboot

(Edited)

1 Like

This new systemd unit file does not require a separate script.

Reboot after those changes.

OK, hopefully it’s good now.

It works!!! Thank you so much, tbg. I did 10 tests using you last version, and 9 out of the 10 worked perfectly. One time the bluetooth did not resume, I think because of the speed at which I was suspending and resuming in succession causing the script to hang up, but I think thats an edge case that shouldn’t happen in normal use. In that instance, I was able to bring bluetooth back by either resuspending and resuming or running sudo modprobe btusb.

Would you like for me to create a consolidated solution post with all our scripts in it for others to benefit from? Or if you want to add the suspend script to yours we could mark at the solution.

@mandog I also wanted to let you know that I investigated your solution as well. On one of the laptops (Xiaomi Notebook Pro), Bluetooth Resume was not available in the BIOS, and I couldn’t control it from there. In that instance, tbg’s solution was the best. I am going to check our Lenovo laptops, because I bet your solution will be the best in those instances.

Yes please consolidate all the scripts together once we are finished for reference.

Do you want the suspend script to have support for hibernate and hybrid sleep as well, if so I will give you an example to update your systemd unit file.

I will post an example of another unrelated suspend script I wrote to add in hibernate and hybrid sleep. If you wish to change simply modify your script accordingly.

[Unit]
Description=WiFi network connection suspend helper
WantedBy=sleep.target
#WantedBy=hibernate.target
#WantedBy=hybrid-sleep.target

[Service]
Type=simple
ExecStart=-/usr/bin/wifi-suspend.sh

[Install]
WantedBy=suspend.target
#WantedBy=hibernate.target
#WantedBy=hybrid-sleep.target

Uncomment the relevant lines above if you want the script to run on hibernate and hybrid-sleep.

1 Like

In my suspend service, should I be using WantedBy instead of Before? ie. Before=sleep.target iswhat my current script says.

I would stick with what you have currently and test the changes.

Thanks to tbg for this great solution. Here’s a round up of everything that we went over for anyone who doesn’t want to read through this giant sprawling thread. tbg, feel free to repost this round up if you want to get proper credit for the solution. :wink:

You’ll need to create three script files:

/etc/systemd/system/bluetooth-reload.service

[Unit]
Description=Reload bluetooth driver after system resume
After=hibernate.target suspend.target hybrid-sleep.target

[Service]
Type=oneshot
TimeoutSec=15
ExecStart=/usr/sbin/modprobe btusb

[Install]
WantedBy=hibernate.target suspend.target hybrid-sleep.target

/etc/systemd/system/bluetooth-suspend.service

[Unit]
Description=Bluetooth module suspend helper
Before=sleep.target
WantedBy=hibernate.target
WantedBy=hybrid-sleep.target

[Service]
Type=simple
ExecStart=-/usr/bin/bluetooth-suspend.sh

[Install]
WantedBy=sleep.target
WantedBy=hibernate.target
WantedBy=hybrid-sleep.target

/usr/bin/bluetooth-suspend.sh

#!/bin/bash
modprobe -r btusb

Next, you’ll need to run the following list of commands.

sudo chmod +x /etc/systemd/system/bluetooth-reload.service
sudo chown root:root /etc/systemd/system/bluetooth-reload.service
sudo chmod +x /etc/systemd/system/bluetooth-suspend.service
sudo chown root:root /etc/systemd/system/bluetooth-suspend.service
sudo chmod +x /usr/bin/bluetooth-suspend.sh
sudo chown root:root /usr/bin/bluetooth-suspend.sh
sudo systemctl enable bluetooth-suspend.service
sudo systemctl start bluetooth-suspend.service
sudo systemctl enable bluetooth-reload.service
sudo systemctl start bluetooth-reload.service

reboot (probably not necessary, but just in case)

If for some reason your bluetooth does not return after suspend, it can be resolved by either running sudo modprobe btusb or by re-suspending and re-resuming.

1 Like

Not necessary in the least. The important thing is that the solution is out there now, and your Bluetooth is working.

This could probably be reduced to 2 or even 1 systemd unit file to accomplish this. I kind of prefer to use the external script in addition to the systemd file. The reason I prefer to do it
that way is you never know how complicated the scripting will get as you progress to finding a solution. A simple fix fix might be acommplished with only one file for suspend and resume, but I’ve never tried that myself.

Thanks for posting the full solution.

1 Like

@tbg suddenly the suspend service/script is no longer working even after a reboot, and I’m trying to find what the source might be.

Here is the status of the suspend service:

● bluetooth-suspend.service - Bluetooth module suspend helper
   Loaded: loaded (/etc/systemd/system/bluetooth-suspend.service; enabled; vendor preset: disabled)
   Active: inactive (dead)

Aug 15 17:23:08 merlin-xiaomi-1 systemd[1]: /etc/systemd/system/bluetooth-suspend.service:5: Unknown lvalue 'WantedBy' in section 'Unit'
Aug 15 17:23:09 merlin-xiaomi-1 systemd[1]: /etc/systemd/system/bluetooth-suspend.service:4: Unknown lvalue 'WantedBy' in section 'Unit'
Aug 15 17:23:09 merlin-xiaomi-1 systemd[1]: /etc/systemd/system/bluetooth-suspend.service:5: Unknown lvalue 'WantedBy' in section 'Unit'
Aug 15 17:23:11 merlin-xiaomi-1 systemd[1]: /etc/systemd/system/bluetooth-suspend.service:4: Unknown lvalue 'WantedBy' in section 'Unit'
Aug 15 17:23:11 merlin-xiaomi-1 systemd[1]: /etc/systemd/system/bluetooth-suspend.service:5: Unknown lvalue 'WantedBy' in section 'Unit'
Aug 15 17:23:11 merlin-xiaomi-1 systemd[1]: Started Bluetooth module suspend helper.
Aug 15 17:23:51 merlin-xiaomi-1 systemd[1]: /etc/systemd/system/bluetooth-suspend.service:4: Unknown lvalue 'WantedBy' in section 'Unit'
Aug 15 17:23:51 merlin-xiaomi-1 systemd[1]: /etc/systemd/system/bluetooth-suspend.service:5: Unknown lvalue 'WantedBy' in section 'Unit'
Aug 15 17:24:20 merlin-xiaomi-1 systemd[1]: /etc/systemd/system/bluetooth-suspend.service:4: Unknown lvalue 'WantedBy' in section 'Unit'
Aug 15 17:24:20 merlin-xiaomi-1 systemd[1]: /etc/systemd/system/bluetooth-suspend.service:5: Unknown lvalue 'WantedBy' in section 'Unit'

Very strange did this happen after a kernel or other update. You might want to test different kernels to see if there’s one that might be working for you if things have changed.

stranger and stranger… manually turning off bluetooth doesn’t work anymore either. I guess it is a new issue… The laptop wakes from suspend every single time. I did update to the latest version of 4.17 along with the other Manjaro updates…

That is not good news if turning off Bluetooth no longer will prevent the suspend issue. Did you try disabling the Bluetooth service as well. I would suggest testing kernel 4.18 as well as the 4.14 LTS kernel. There are also other methods to fully disable Bluetooth.

You can create a file:

/etc/modprobe.d/bluetooth.conf

Add the following line to the file.

install bluetooth /bin/false

That should totally disable all Bluetooth modules from starting. That along with disabling the Bluetooth service may be required.

The other possibility is that your laptop has developed the more common problem of your wifi modules preventing proper sleep functions. The way to test for that is to unload your wifi modules before sleeping to see if things improve. If the wifi modules are now interfering you will need to add them to the scripts to unload/load.

I would also check to see if there is a bios update for your laptop. Sorry that things have gone south on you. Hopefully you can get it sorted.

1 Like

fwiw, shortly after I made my last post, updates seem to have reversed whatever was going on. I’m not currently having any issues as long as I use the script/instructions up above.

Awesome, I just posted another couple of systemd suspend/resume units if you want to see them. I was thinking of posting them here for you as I was thinking of your issue.

In your case adding the bluetooth.service could help as well.

The solution I use disables bluetooth before sleep and restores on wake using a script in /usr/lib/systemd/system-sleep/

The contents of the script /usr/lib/systemd/system-sleep/suspend-bt.sh is:

#!bin/bash

if [ "${1}" == "pre" ]; then
systemctl stop bluetooth && systemctl disable bluetooth

elif [ "${1}" == "post" ]; then
systemctl enable bluetooth
sleep 1s
systemctl start bluetooth
fi

The script should of course be set to root:root and 700 permissions.

I found it was necessary to wait a second before starting bluetooth otherwise the desktop tray (KDE plasma 5 tray icon) would not appear. Stops the laptop from waking in my bag due to a bluetooth mouse waking up.

1 Like

This is the only solution (and simplest) that worked for me. I'm running Pop!_OS, thank you!

Using a script in /usr/lib/systemd/system-sleep/ is no longer recommended on Arch based systems. The Archwiki advises against this, as this method has been deprecated. A service is the currently recommended method to accomplish this with Arch/Manjaro.

This method was regularly recommended on Debian based systems in the past, but even they no longer recommend this method.

Perhaps report your solution on the Pop!_OS forum as this method is not appropriate on Arch/Manjaro.

Necrobumping posts that are over a year old is also not recommended. This thread is over a year old and I have written many other services that can accomplish this task that may work better than the old service given on this thread. A more efficient way to disable a bluetooth device with a service would be using the device ID:

I have a thread with many more modern services here:

Disabling bluetooth via the device ID helps to conserve battery power on a laptop, so it is probably the better type of service for a laptop.

Forum kindly sponsored by Bytemark