Synopsis: I need a mechanism to start my openHAB server at given times.
I live in South Africa and here the government implemented a concept called Loadshedding - at a given schedule (which can change on a wink) the power for certain blocks of the grid is switched off for 2.5 hours at a time. This normally happens a few times per week, but if things go south with power generation, it can happen several times per day. Let’s call it a small 35 year long planning oversight by power generation parastatal.
I run my Openhab server on a Debian laptop that can run on battery mode just under 2 hours and then it goes into suspend mode. When the power comes back on, the laptop is unaware of this and keeps snoozing until I lift the lid.
I’m soon going on holiday and need my home automation more than ever, but no one will be home to lift the lid to wake up the laptop.
I have investigated:
Wake on LAN - BIOS on my laptop does not cater for it (Lenovo T510)
RTCWake - this may work, but I cannot seem to figure out a way to make this recurring? Once RTCWake woke up the laptop, it needs to be scheduled again.
I need a solution that:
at given intervals tries to wake up the laptop or,
at a given time wake it up (but only if there is power, otherwise it must try later again)
I can live with my home automation not being available for a few hours, but not for days on end. It must try and auto wake and start up at least every 6 hours.
I’ve wrecked my brain in trying to solve this problem - any advice will be appreciated.
Thanks in advance
Either an full-blown UPS, which can also tell your Rasperry, when there’s grid power and when there’s none there’s a neat little library “nut” for that:
Have a look at various UPSs, there’s almost certainly one available which is supported by NUT and lasts 3hours at last with an RPi. I use “Eaton Ellipse Eco 650USB” - which should suffice.
Bonus: if the power is out for longer than the UPS battery lasts, your Raspbian OS can shutdown properly by a simple NUT configuration - and when power is back, your Raspi boots your OH3-server normally back up again.
So no hassle - and all is good.
Or - there’s some powerbanks, which can be charged and discharged without a problem, meaning it will power your pi and if there’s an outage, they’ll still power your pi - until power is back again. But some have a bit too long of a paus in between both modes and your Pi will cold reboot. So if you rely on your home automation => go with an UPS and NUT to gracefully shutdown your Pi if power is out for longer.
In case you would like to go the risky way. Some thoughts about peaces that may help to create scripts.
You could do some trials with a crontab entry that makes use @reboot instead of fixed times.
This entry then needs to schedule the next wakeup.
An other cron entry or an at job at now+30minutes can be used to shutdown the computer e.g. half an hour later than now.
Wake up needs to be done anyway. Once it is woken up a check like
I would normally agree with @mstormi, but RPis are hard to get right now and it sounds like you’re on a short timeframe. For the sake of discussing options, I’m going to assume that you can’t get one.
Plan for the worst-case scenario, which is power going out multiple times in the day. Nothing else matters.
A typical UPS with a lead acid battery is quick to discharge and slow to recharge. If the power might go off multiple times in one day, you don’t want to drain the battery. Better to immediately cut power to preserve the UPS’s runtime. I’m guessing that this will be okay, since nothing else in your house will be working while the power is off.
If your laptop has a BIOS option to start when AC power is restored, then you could have a UPS immediately shut it down and then rely on the BIOS startup. However, I’m not sure if a laptop will have that setting. I’ve only ever used it with desktops, but I’ve never looked for it in a laptop.
You would need a UPS that can be controlled by a linux client over USB (either the manufacturer’s or Network UPS Tools) and that cuts power to the socket after shutting down the laptop, so that the laptop can sense when power is restored.
Most (all?) inexpensive UPSes will only cut power to the socket when their batteries are depleted. But then they won’t turn back on until the batteries have charged up sufficiently. That could be many hours later.
But here’s the thing:
If you want the fastest and easiest solution, get a better laptop or replace the battery. If it can last 6-8 hours, you shouldn’t have to worry about it at all.
It’s just Like to add that my server is hooked to a Eaton 5E 850 VÁ with 480 watt max load, and even at 17% load ( about 80 watts I believe), which is at right now, it only have around 35 minutes of battery power.
My server is an i3 7100, and has a bunch of hard drives, so the consumption is definitely on the higher side of things, but even if you decrease it, you’re barely talking about breaking the one hour threshold.
I’m not sure that a normal ups will be the answer…
Firstly, sorry for the radio silence of a few days, life happened, so did a critical production problem and we didn’t see daylight for a few days .
Secondly I appreciate all the replies and suggestions. I have a 1000W UPS that is driving a number of devices in the house when the power goes down, but this is not enough.
I have gotten the following concept right and will implement it within the next few days. It gives me external control of monitoring and switching on of the laptop. So I’m sharing it here for the benefit of others.
I managed to get WakeOnLAN enabled in the BIOS.
I use several ESP32 and similar devices in my home automation and now one of these devices will use the WOL library (here) to wake up the laptop:
When the power goes down, the laptop goes to sleep say after 1 hour (this allows enough time for OH3 to send me messages and for me to do things via OH3 whilst the power is off)
When the power comes back on, a relay kicks in which brings a pin on the ESP32 to high. The ESP32 detects that the power is on. It then sends a WOL command to the laptop, the laptop wakes up, OH3 starts and sends me a message that it is back and gives me a status of my home.
This brings me a bit more control since the ESP32 controller can check a number of things and do a number of retries which is slightly more resilient than the cron job suggested.
Sorta surprised that the T510 doesnt support WOL, i know the T500 did.
Never used RTCwake or know how its implemented but perhaps you could, for example, give the device a fixed IP via a DHCP reservation on your router and then have a script/task that runs regular pings to the device and if it stops responding, it sends a wake command? Something like that could work.