Page 1 of 2

Remote UPS for Raspberry

Posted: Friday 11 April 2014 16:47
by bizziebis
Today I installed a APC Back-UPS ES Power-Saving 700VA 230V, BE700G-GR to my Synology DS413.
973577_LB_00_FB_EPS_1000.jpg
973577_LB_00_FB_EPS_1000.jpg (43.37 KiB) Viewed 23718 times
It's possible to enable UPS server on the Synology and use it on the Raspberry. If you connect the Raspberry's powersupply to the UPS, you can safely shut down the system when the battery is almost empty.

On the raspberry you need to install NUT

Code: Select all

sudo apt-get install nut
edit the monitoring config

Code: Select all

sudo nano /etc/nut/upsmon.conf
Scroll down to the part MONITOR

Code: Select all

# MONITOR [email protected] 1 upsmon secretpass slave
# MONITOR myups@localhost 1 upsmon pass master  (or slave)
and add below:

Code: Select all

MONITOR [email protected] 1 monuser secret slave
Change the IP to the IP of your NAS. All the other info suitable for every Synology NAS

Save the file and quit nano

Edit nut configuration

Code: Select all

sudo nano /etc/nut/nut.conf
Change MODE=none into

Code: Select all

MODE=netclient
Save the file and quit nano

Start monitoring the remote UPS server

Code: Select all

sudo /etc/init.d/nut-client start
With the default settings the Raspberry will check the UPS status every 5 seconds. If it detects that the UPS is running on battery (when main power has failed), it will continue to monitor. If the connection is lost after that (NAS powered down) it will monitor for another 15 seconds before the Raspberry will shut down.

I have my Synology DS413, Raspberry and DSL router connected to the APC. It should keep everything running for al least 15 minutes when the power is down. :mrgreen:

Re: Remote UPS for Raspberry

Posted: Tuesday 10 February 2015 20:29
by advfr
Dear bizziebis, you've made my day :D

Thanks a lot for this great info, just applied @ home !

Just another info than may be usefull for others...

You can check if the link with the UPS is good with: upsc [email protected]
(replace with your NAS IP addr.)

and there is a little mistake in your post at "Edit nut configuration", nano is missing in the command ;)

Merci beaucoup :!:

Have a great day !

Re: Remote UPS for Raspberry

Posted: Tuesday 10 February 2015 21:00
by bizziebis
Oops you are right.. I fixed it ;)

Nice to see the guide was usefull!

Reminds me to run this setup again for my new installed system..

Re: Remote UPS for Raspberry

Posted: Tuesday 10 February 2015 23:37
by ThinkPad
Nice tutorial, thanks for writing!

Re: Remote UPS for Raspberry

Posted: Wednesday 11 February 2015 0:22
by antwan
Nice tutorial for the wiki!

Re: Remote UPS for Raspberry

Posted: Monday 12 October 2015 22:03
by McMike
Hi,
thanks for that great tutorial. I just forgot to enter the allowed clients IP-adresses at the Synology, but once I did, everything worked.

Just one question. After the connection to the Synology is lost (it shut down before battery was empty) the Raspi will also shut down. However... what happens if the UPS doesn't shut down completely and regular power comes back on again so that there never was a full outage on the backup-site of the system? How can the Raspi start up again automatically?

Maybe a stupid question, but I am a bit confused.

Thanks
Michael

Re: Remote UPS for Raspberry

Posted: Tuesday 20 October 2015 14:33
by happer66
Great guide, thanks!
I somewhat imagined it would be alot harder than this... ;)
(Using a ReadyNAS Pro + APC Back-UPS RS 1500G)

Cheers!

Re: Remote UPS for Raspberry

Posted: Friday 23 October 2015 10:05
by stlaha2007
McMike wrote:Hi,
thanks for that great tutorial. I just forgot to enter the allowed clients IP-adresses at the Synology, but once I did, everything worked.

Just one question. After the connection to the Synology is lost (it shut down before battery was empty) the Raspi will also shut down. However... what happens if the UPS doesn't shut down completely and regular power comes back on again so that there never was a full outage on the backup-site of the system? How can the Raspi start up again automatically?

Maybe a stupid question, but I am a bit confused.

Thanks
Michael
Only way to Startup your Pi is by hand. Remove USB-cable/Charger and insert it again.

Please keep in mind its not a PC and therefor your Pi is missing two things:
- BIOS
- Powerswitch

I can think of other options, however needs some enginering.

Sent from my D6503 using Tapatalk

Re: Remote UPS for Raspberry

Posted: Saturday 24 October 2015 22:48
by jannl
Off course a Pi has a bios, how do you think it starts reading the sd-card for instance? May be not as complex as a pc but still.

As soon as my ups gets power again, my pi also restarts. Only problem is that the ups gets it power back before my nas switches the ups off.

Verstuurd vanaf mijn GT-I9300 met Tapatalk

Re: Remote UPS for Raspberry

Posted: Friday 07 October 2016 20:30
by PuckStar32
Thanks for this! Just bought a UPS and configured it.
Questions:
How can I check if the nut service is still running and ok?
Is it automatically started again after a reboot of the pi?

Re: Remote UPS for Raspberry

Posted: Monday 10 October 2016 10:23
by bluepi
I do the same thing and then fetch the details into Domoticz with virtual utility switches..

Code: Select all

#!/bin/bash


#sudo service nut-server status | grep "upsd is running"
setvoltage=`upsc rphs | grep "battery.voltage:" | awk '{print $NF}'`
setruntimesec=`upsc rphs | grep "battery.runtime:" | awk '{print $NF}'`
setruntimemin=`echo $(($setruntimesec / 60))`
setinputvolt=`upsc rphs | grep "input.voltage:" | awk '{print $NF}'`
setbatterycharge=`upsc rphs | grep "battery.charge:" | awk '{print $NF}'`

IDX_Voltage="219"
IDX_Runtime="220"
IDX_Input="221"
IDX_Battery="222"

curl -s "http://127.0.0.1:8080/json.htm?type=command&param=udevice&idx="$IDX_Voltage"&nvalue=0&svalue="$setvoltage""
curl -s "http://127.0.0.1:8080/json.htm?type=command&param=udevice&idx="$IDX_Runtime"&nvalue=0&svalue="$setruntimemin""
curl -s "http://127.0.0.1:8080/json.htm?type=command&param=udevice&idx="$IDX_Input"&nvalue=0&svalue="$setinputvolt""
curl -s "http://27.0.0.1:8080/json.htm?type=command&param=udevice&idx="$IDX_Battery"&nvalue=0&svalue="$setbatterycharge""

exit 0
and just run in cron every few mins

This lets me know the service is up and if there are any changes to the UPS.. then I control every device on my network from Domoticz.

So if battery level is down to 5 mins it then start shutting down systems like wifi (POE) and other systems, before turning itself off. Once all other systems are off the battery run time on the UPS goes up quite a lot and it will wait until the UPS get down to 3 mins before turning itself off. However the power does have to be off for some time before it shuts down.

Re: Remote UPS for Raspberry

Posted: Monday 10 October 2016 12:51
by remb0
I have the same UPS and will use it for my nas and PI.
but I will lett domoticz be the server, en the synology the client.

by a power failure nas must shutdown, but my PI must be up as long as possible.
so I can control my home, and the PI can inform me.

other reason is that my Nas goes off in the night.

is that possible?

Re: Remote UPS for Raspberry

Posted: Thursday 13 October 2016 22:04
by McMike
I need urgent help, please.

I installed the NUT client as shown some time ago. Everything was running fine so far. We had some short single power outages but the APC kept all systems alive. Now yesterday we had two outages within 10 minutes or so. Both times the APC backed up the NAS and all network equipment including my raspberry pi.

After the power came back on the second time, all my home control (running on pi) was dead. Tonight after many tests i figured out that the pi somehow thinks the battery is low and immediately after regular boot up I get an automated shutdown. I managed to log in via SSH just one time real fast and was able to see the broadcast messages:
Broadcast message from nut@nobodypi2 (somewhere) (Thu Oct 13 21:52:34 2016):

Executing automatic power-fail shutdown

Broadcast message from nut@nobodypi2 (somewhere) (Thu Oct 13 21:52:34 2016):

Communications with UPS [email protected] established

Broadcast message from nut@nobodypi2 (somewhere) (Thu Oct 13 21:52:34 2016):

Auto logout and shutdown proceeding
Now how can I disable the NUT client within the just two seconds or so after boot to fix that? I have no idea what happened since the battery is up and running and also the Synology works fine.

Thanks a lot.
Michael

Re: Remote UPS for Raspberry

Posted: Friday 14 October 2016 6:48
by bizziebis
You can copy the command

Code: Select all

sudo service nut-client stop
Paste it quickly and press Enter

Some terminal programs give you the possibility to enter a command which will be executed automatically upon login. For example JuiceSSH for Android. You can run a 'Snippet' after login. You could cooy above command in it and try to connector a couple of times.

Re: Remote UPS for Raspberry

Posted: Friday 14 October 2016 7:04
by jannl
@rembo why control your home when having a power outage? My synology is the server here. Pi shutsdown first and nas later and kills the ups. Only problem is the pi does not reboot when the power returns before the nas does a shutdown.

Re: Remote UPS for Raspberry

Posted: Friday 14 October 2016 9:17
by McMike
jannl wrote:@rembo why control your home when having a power outage? My synology is the server here. Pi shutsdown first and nas later and kills the ups. Only problem is the pi does not reboot when the power returns before the nas does a shutdown.
I am also not controlling my home during power outage however would like the pi to perform certain things upon power outage (send push message etc.). I have same setup. Synology is NUT server. UPS is keeping the whole network-stuff alive (also the pi running as a home control center). Upon low batt the pi is supposed to shutdown first and on almost no batt the Synology will shut down. If power outage still goes on, the switch / router / etc. will simply switch off on empty UPS batt. So everything is supposed to be save. Same "problem"... pi would not come on again if power returns before total UPS shutdown but that would be ok.

However the double outage must have caused the NUT-Server (Synology) to send a "low batt warning" to the pi and the pi shut down. Now whenever the pi reboots (although network is operational) the pi still "thinks" that the batt is low and initiates an emergency shutdown right away. This afternoon I will try to reboot the NAS, maybe the NUT server on the Synology is stuck and sending low batt warnings although there is none. If that doesn't help I will try to stop the nut-service on pi during the few seconds I have before the shutdown starts... I just didn't know the exact command to do that.

Re: Remote UPS for Raspberry

Posted: Friday 14 October 2016 9:25
by jannl
Question: how do you send a push message when your neighbourhood has a poweroutage?

Just before mu Pi does its shutdown, I set the virtual switch that controls the automatic shutdown to the normal state, so that on a reboot the Pi first checks the NAS for UPS before shutting itself down.

Furthermore, I have the NAS kill the UPS, so everything gets power when the main is restored.

The Pi sends a pushover message and an e-mail upon ups offline and just before shutdown, I wonder if I also get those when the main is actually off in the neighbourhood, works when only the power in the house gets killed (router etc on ups).

May be you should not check on low-battery but on ups online or offline.

Re: Remote UPS for Raspberry

Posted: Saturday 15 October 2016 17:28
by remb0
I will try to send a pushnotification indeed. only when my power is down due my own fault :P
when the whole neighbourhood is down it is not possible, i understand.

Re: Remote UPS for Raspberry

Posted: Saturday 22 October 2016 11:26
by PuckStar32
Can someone please help me?
I want to know:
1. Is the nut service automatically started again after a reboot of the pi? Or must I configure that somewhere?
2. How can I check (manually) if the nut service is currently running?
3. How can I setup that the pi shutsdown BEFORE the NAS. Because what I want is:
Power outage -> NAS sends signal to pi3 that UPS running on battery -> pi should shutdown immediately -> After 5minutes the NAS should shut down the UPS and go in Safe mode itself.

With what the topic starter mentions this is not possible now because the pi will just wait until the NAS goes into Safe Mode before shutting down, but then the UPS battery will be emtpy.

Can anyone help me with this please?

Re: Remote UPS for Raspberry

Posted: Tuesday 06 December 2016 9:54
by D1M0N
PuckStar32 wrote:Can someone please help me?
I want to know:
1. Is the nut service automatically started again after a reboot of the pi? Or must I configure that somewhere?
2. How can I check (manually) if the nut service is currently running?
3. How can I setup that the pi shutsdown BEFORE the NAS. Because what I want is:
Power outage -> NAS sends signal to pi3 that UPS running on battery -> pi should shutdown immediately -> After 5minutes the NAS should shut down the UPS and go in Safe mode itself.

With what the topic starter mentions this is not possible now because the pi will just wait until the NAS goes into Safe Mode before shutting down, but then the UPS battery will be emtpy.

Can anyone help me with this please?
UP your question...

I have Nas4free + NUT service. If voltage is lost, my computer is turned off after 10 minutes WinNUT. after it is turned off the server over 20 min.
I want to monitoring voltage condition through DOMOTICZ.

ps sorry for bad english, im from Ukraine ))