References
https://www.howtoraspberry.com/2020/11/how-to-monitor-ups-with-raspberry-pi
https://www.howtoraspberry.com/2021/05/how-to-configure-an-orderly-shutdown/
https://blog.fosketts.net/2015/06/03/automated-ups-monitoring-for-vsphere-with-nut-and-raspberry-pi-cheap/
https://www.reddit.com/r/homelab/comments/5ssb5h/ups_server_on_raspberry_pi/
https://wiki.ledhed.net/index.php?title=Raspberry_Pi_NUT_Server
For detailed NUT config and low battery warnings
Starting with a Raspberry Pi new image
sudo raspi-config
- enable ssh
- change hostname to
ups
Install Nut tools
1
2
3
sudo apt-get update
sudo apt-get upgrade
sudo apt-get update && sudo apt-get install nut nut-client nut-server
Edit /etc/nut/ups.conf and add the snippet below to the end of the file
1
2
3
4
5
6
7
8
9
[qnapups]
driver = usbhid-ups
port = auto
desc = "CyberPower AVR UPS"
pollinterval = 15
override.battery.charge.low = 30
override.battery.charge.warning = 5
override.battery.runtime.low = 180
Edit /etc/nut/upsd.conf and add the snippet below to the end of the file
1
MAXAGE 25
Edit /etc/nut/upsd.users and add the snippet below to the end of the file
1
2
3
4
5
[admin]
password = 12345
upsmon master
instcmds = ALL
actions = SET
Edit /etc/nut/upsmon.conf and add the snippet below to the end of the file
1
2
3
LISTEN {current-ip-address} 3493
MONITOR qnapups@localhost 1 admin 123456 master
Also in the same file above set
1
DEADTIME 25
Edit /etc/nut/nut.conf and set MODE value
1
MODE=netserver
Reboot!
Install Webserver
1
sudo apt install apache2 nut-cgi
Edit /etc/nut/hosts.conf and add the snippet below to the end of the file
1
MONITOR qnapups@localhost "Server UPS"
1
2
/etc/nut $ sudo a2enmod cgi
systemctl restart apache2
Edit /etc/nut/upsset.conf and uncomment (remove #)
1
### I_HAVE_SECURED_MY_CGI_DIRECTORY
Browse to
1
http://ups.localdomain/cgi-bin/nut/upsset.cgi
1
2
USR: admin
PWD: 123456
1
http://ups.localdomain/cgi-bin/nut/upsstats.cgi
Qnap as UPS Slave to Raspberry Pi NUT server
https://forum.qnap.com/viewtopic.php?t=60166
your upsname must be named qnapups, and user “admin” with password “123456” must be allowed to connect.The user/password pair can be changed manually on the QNAP. The UPS name can not be changed (at least I was not able to find way how to change it) but you can change the username/password manually in
/etc/config/ups/upsmon.conf
To generate data as JSON, exported as JSON object in webpage
upsstats-single.html file contents
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
<!-- upsstats template file -->
<!--
This is upsstats-single.html, a template for monitoring a single
host. This mode is selected by adding "host=<host>" to the
upsstats.cgi URL.
Such URLs are generated automatically when using the HOSTLINK
command.
See upsstats.html(5) for more information on template files.
-->
<!-- change this to TEMPF if you don't like Celsius. -->
@TEMPC@
@UPSSTATSPATH upsstats.cgi@
@UPSIMAGEPATH upsimage.cgi@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
@REFRESH@
<title>@HOSTDESC@ : @VAR ups.model@ on @HOST@</title>
<!-- LINK REL="stylesheet" TYPE="text/css" HREF="http://localhost/nut/nut.css" / -->
</head>
<body BGCOLOR="#808080" TEXT="#00FC00" LINK="#0000EE" VLINK="#551A8B">
<table BORDER="1" ALIGN="CENTER" CELLSPACING="0" CELLPADDING="10" BGCOLOR="#000000">
<tr>
<th COLSPAN="20">Network UPS Tools upsstats @VERSION@ - @HOSTDESC@ - @VAR ups.model@ on @HOST@</th>
</tr>
<tr>
<th>@DATE %a %b %d %X %Z %Y@</th>
@IFSUPP ambient.temperature@
<th>Ambient</th>
@ELSE@
@IFSUPP ambient.humidity@
<th>Ambient</th>
@ENDIF@
<th>Battery</th>
<th>Input</th>
<th>Output</th>
<th>Load</th>
</tr>
<tr>
<td BGCOLOR="#000000" VALIGN="TOP">
<table BORDER="0"> <!-- table 2 -->
<tr>
<th ALIGN="RIGHT">UPS Model:</th>
<td>@VAR ups.model@</td>
</tr>
<tr>
<th ALIGN="RIGHT">Status:</th>
<td>@STATUS@</td>
</tr>
@IFSUPP battery.runtime@
<tr>
<th ALIGN="RIGHT">Runtime:</th>
<td>@RUNTIME@</td>
</tr>
@ENDIF@
@IFSUPP ups.temperature@
<tr>
<th ALIGN="RIGHT">UPS temp:</th>
<td>@UPSTEMP@ @DEGREES@</td>
</tr>
@ENDIF@
@IFSUPP battery.voltage@
<tr>
<th ALIGN="RIGHT">Battery: </th>
<td>@VAR battery.voltage@ V@IFSUPP battery.current@, @VAR battery.current@ A</td>
@ENDIF@
<tr>
<th VALIGN="TOP" ALIGN="RIGHT">Input: </th>
<td>
@IFSUPP input.L2-L3.voltage@
@VAR input.L1-L2.voltage@ V<br>
@VAR input.L2-L3.voltage@ V<br>
@VAR input.L3-L1.voltage@ V<br>
</td>
</tr>
@ELSE@
@IFSUPP input.L2-N.voltage@
@VAR input.L1-N.voltage@ V<br>
@VAR input.L2-N.voltage@ V<br>
@VAR input.L3-N.voltage@ V<br>
</td>
</tr>
@ELSE@
@IFSUPP input.voltage@
@VAR input.voltage@ V<br>
</td>
</tr>
@ENDIF@
@IFSUPP input.L2.current@
<tr>
<th>
<td>
@VAR input.L1.current@ A<br>
@VAR input.L2.current@ A<br>
@VAR input.L3.current@ A<br>
</td>
</tr>
@ELSE@
@IFSUPP input.current@
<tr>
<th>
<td>
@VAR input.current@ A
</td>
</tr>
@ENDIF@
@IFSUPP input.frequency@
<tr>
<th>
<td>
@VAR input.frequency@ Hz
</td>
</tr>
@ENDIF@
<tr>
<th VALIGN="TOP" ALIGN="RIGHT">Output: </th>
<td>
@IFSUPP output.L2-L3.voltage@
@VAR output.L1-L2.voltage@ V<br>
@VAR output.L2-L3.voltage@ V<br>
@VAR output.L3-L1.voltage@ V<br>
</td>
</tr>
@ELSE@
@IFSUPP output.L2-N.voltage@
@VAR output.L1-N.voltage@ V<br>
@VAR output.L2-N.voltage@ V<br>
@VAR output.L3-N.voltage@ V<br>
</td>
</tr>
@ELSE@
@IFSUPP output.voltage@
@VAR output.voltage@ V
</td>
</tr>
@ENDIF@
@IFSUPP output.L2.current@
<tr>
<th>
<td>
@VAR output.L1.current@ A<br>
@VAR output.L2.current@ A<br>
@VAR output.L3.current@ A<br>
</td>
</tr>
@ELSE@
@IFSUPP output.current@
<tr>
<th>
<td>
@VAR output.current@ A
</td>
</tr>
@ENDIF@
@IFSUPP output.frequency@
<tr>
<th>
<td>
@VAR output.frequency@ Hz
</td>
</tr>
@ENDIF@
</table> <!-- table 2 -->
</td>
@IFSUPP ambient.temperature@
@IFSUPP ambient.humidity@
<td ALIGN="CENTER" VALIGN="TOP" BGCOLOR="#000000">
<table BORDER="0"><tr>
<td ALIGN="CENTER">Temperature<br>@IMG ambient.temperature tempmin=0 tempmax=50 width=90@</td>
<td ALIGN="CENTER">Humidity<br>@IMG ambient.humidity width=90@</td>
</tr></table>
</td>
@ELSE@
@IFSUPP ambient.temperature@
<td ALIGN="CENTER" VALIGN="TOP" BGCOLOR="#000000">
<table BORDER="0"><tr>
<td ALIGN="CENTER">Temperature<br>@IMG ambient.temperature tempmin=0 tempmax=50@</td>
</tr></table>
</td>
@ELSE@
@IFSUPP ambient.humidity@
<td ALIGN="CENTER" VALIGN="TOP" BGCOLOR="#000000">
<table BORDER="0"><tr>
<td ALIGN="CENTER">Humidity<br>@IMG ambient.humidity@</td>
</tr></table>
</td>
@ENDIF@
<td ALIGN="CENTER" VALIGN="TOP" BGCOLOR="#000000">
<table BORDER="0"><tr>
@IFSUPP battery.charge@
@IFSUPP battery.voltage@
<td ALIGN="CENTER">Charge<br>@IMG battery.charge width=90@</td>
<td ALIGN="CENTER">Voltage<br>@IMG battery.voltage width=90@</td>
@ELSE@
@IFSUPP battery.charge@
<td ALIGN="CENTER">Charge<br>@IMG battery.charge@</td>
@ELSE@
<td ALIGN="CENTER">Voltage<br>@IMG battery.voltage@</td>
@ENDIF@
</tr></table>
</td>
<td ALIGN="CENTER" VALIGN="TOP" BGCOLOR="#000000">
<table BORDER="0"><tr>
@IFSUPP input.L2-L3.voltage@
<td ALIGN="CENTER">L1-L2<br>@IMG input.L1-L2.voltage width=68@</td>
<td ALIGN="CENTER">L2-L3<br>@IMG input.L2-L3.voltage width=68@</td>
<td ALIGN="CENTER">L3-L1<br>@IMG input.L3-L1.voltage width=68@</td>
@ELSE@
@IFSUPP input.L2-N.voltage@
<td ALIGN="CENTER">L1-N<br>@IMG input.L1-N.voltage width=68@</td>
<td ALIGN="CENTER">L2-N<br>@IMG input.L2-N.voltage width=68@</td>
<td ALIGN="CENTER">L3-N<br>@IMG input.L3-N.voltage width=68@</td>
@ELSE@
<td ALIGN="CENTER"><br>@IMG input.voltage@</td>
@ENDIF@
</tr></table>
</td>
<td ALIGN="CENTER" VALIGN="TOP" BGCOLOR="#000000">
<table BORDER="0"><tr>
@IFSUPP output.L2-L3.voltage@
<td ALIGN="CENTER">L1-L2<br>@IMG output.L1-L2.voltage width=68@</td>
<td ALIGN="CENTER">L2-L3<br>@IMG output.L2-L3.voltage width=68@</td>
<td ALIGN="CENTER">L3-L1<br>@IMG output.L3-L1.voltage width=68@</td>
@ELSE@
@IFSUPP output.L2-N.voltage@
<td ALIGN="CENTER">L1-N<br>@IMG output.L1-N.voltage width=68@</td>
<td ALIGN="CENTER">L2-N<br>@IMG output.L2-N.voltage width=68@</td>
<td ALIGN="CENTER">L3-N<br>@IMG output.L3-N.voltage width=68@</td>
@ELSE@
<td ALIGN="CENTER"><br>@IMG output.voltage@</td>
@ENDIF@
</tr></table>
</td>
<td ALIGN="CENTER" VALIGN="TOP" BGCOLOR="#000000">
<table BORDER="0"><tr>
@IFSUPP output.L2.power.percent@
<td ALIGN="CENTER">L1<br>@IMG output.L1.power.percent width=68@</td>
<td ALIGN="CENTER">L2<br>@IMG output.L2.power.percent width=68@</td>
<td ALIGN="CENTER">L3<br>@IMG output.L3.power.percent width=68@</td>
@ELSE@
@IFSUPP output.L2.realpower.percent@
<td ALIGN="CENTER">L1<br>@IMG output.L1.realpower.percent width=68@</td>
<td ALIGN="CENTER">L2<br>@IMG output.L2.realpower.percent width=68@</td>
<td ALIGN="CENTER">L3<br>@IMG output.L3.realpower.percent width=68@</td>
@ELSE@
<td ALIGN="CENTER"><br>@IMG ups.load@</td>
@ENDIF@
</tr></table>
</td>
</tr>
</table>
<script type="application/json">
{
"Date": "@DATE %d %m %y %X %Z@",
"battery" : {
"chargePercent" : @VAR battery.charge@,
"voltageDc" : @VAR battery.voltage@
},
"input" : {
"voltage": @VAR input.voltage@
},
"output": {
"voltageAc": @VAR output.voltage@
},
"ups": {
"model": "@VAR ups.model@",
"loadPercent": @VAR ups.load@,
"runtime": "@RUNTIME@",
@IFEQ ups.status OL@ "status": "ONLINE"
@ELSE@@IFEQ ups.status OB@ "status": "BATTERY"
@ENDIF@ }
}
</script>
</body>
</html>