Hi !
I have purchased a UPS that is hooked to my Truenas Scale server (from which HAOS is running as a VM), my Pfsense router and my main access point.
Sadly, that UPS does not have a serial or USB port to use any kind of NUT integration or communicate a power loss.
I’d like to still initiate some shutdown commands (mostly for the Truenas server and the Pfsense routers, but a “clean” HA shutdown would be nice too) if I lose power for longer than 5min for example, to avoid a cold shutdown of those appliances if the batteries run out on the UPS.
2 issues :
Sensor
The first being that I can only think of one thing that could help me achieve this: a smart plug that has power consumption functionality. My idea being to plug the UPS to that, and if no power is received on the plug, then it launches an automation/script to send shutdown commands to the relevant devices/machines.
Is this a reliable source? I have some Tuya ones that work relatively well, using Localtuya integration, so outbound internet connection in case of power outage should not (in theory) be an issue.
Order of commands
Now that is the tricky part: Which order of commands am I supposed to follow?
I would assume send command to shutdown Truenas server first > then Pfsense > then HA since:
a) I would lose all communication between devices without a router, or
b) I would not be able to send commands at all if the first thing I do is shutting down HA itself.
So are those commands sent simultaneously? If I send a command to shut down the server where my VM running HA is hosted, will it have time to send other commands before shutting HA off (I assume so but eh). Same question for Pfsense (altho as long as those first 2 receive the commands I’m not too particular on the rest).
I haven’t even started thinking about the restart part, I don’t think that’s even doable without an actual Network UPS communication, so locking down those 2 first parts are where I’m leading first.
Any help or ideas are highly appreciated, I simply lack experience on that part and would love to pick anyone’s brain on the subject!
A smart plug won’t work, as it will cease to be powered once grid power goes off, and so will cease to send updates.
If your UPS has zero communication possibilities, my only idea would be to have some ESP device detecting a (potential) led going on when the UPS loose power.
Ah! it wouldnt report power at 0 but just go offline, I see my mistake there indeed…
The unit has a small screen (haven’t installed it yet), it looks like it has a slot for some serial and usb at the back but that arent installed (like a blocked off plastic panel that probably has the connections for higher-end models of the same brand I assume…)
Here is the model (from the purchase website):
I couldnt quite find my exact model on the manufacturer’s website. It seems they have other models with those USB connections and a proprietary windows app (bummer…) but it could be worth opening the thing and checking the board then ? https://www.upsawp.com/en/productshow.php?pid=LI-UPS-A400
They do mention having connection:
● Optional USB & RJ45 ports
● Unattended safety shutdown: system alarm and auto Power-On / Off by USB interface communicating with PC
“optional” which was never an option when I bought it of course… I was expecting to receive it with it.
It’s possible that the RJ45 option is RS232. If you’re lucky they might have populated the serial components without putting the connector on.
You could also try an Opto-Isolator connected to the Mains or even display board, preferrable over connecting straight to the display board (and mains!) i feel.
Here is my best attempt at taking a picture of the motherboard. I wasn’t able to find any connector labelled RJ45 or RS232, but I did find a 4-pin connector labelled USB1 as shown below:
Here is the full image of the board for reference (the white connector to the right of the one labelled USB1 did not seem to have any label, but I could be wrong.
Even if you manage to wire that USB port, the software is Windows only, so that will mean having a windows machine up 24/7…
But yeah, maybe NUT supports it, somehow…
That’s a good point… And I have not been very successful so far at finding a USB cable with that crimped connector on the other end on Aliexpress and equivalents…
The windows machine i can probably deal with, just thru an extra VM on the server altho it’s a complete waste, surely i’ll find some use for it.
Now in terms of order of operations, does anyone have an idea? Obviously testing is the best way of doing so, but if I can start the right way… might as well.
Sending shutdown commands:
1/ Truenas server > Router > HA if I’m lucky and its still alive?
2/ Doesn’t matter since it’s all at the same time in a script?
3/ Depends on how the commands are sent maybe? thru shell or integration etc?
Note that the alternative is returning this 100$ unit and purchasing the 300$ APC one, which I’d rather avoid… I know it’s mission-critical devices so it’s worth it, but the negotiation with the wife isn’t as easy
The easiest is probably to put the router outside the UPS and have that go powerless.
That way you can use a simple ping sensor on something else on the network and use this as the “if there is a powerloss” sensor.
You should either get the optional port or a better UPS.
Making up a sensor will just cause more issues, like what happens if the router reboots and the sensor gets triggered in that time, then you will have a HA that is shutdown and the UPS is still running, so no message gets send to start it up again.
An alternative approach might be to use an ESP with some kind of power sensor or CT Clamp that registers the power somewhere in the net, and that itself is powered by the UPS.
For redundancy, to preclude false signals due to the ESP itself failing somehow, it would be best to have two of those ESPs fully independent.
If the power is lost you will get a signal from both the ESPs that can be used as a trigger for your shutdown script.
While the power plug you mentioned in the beginning wouldn’t report zero power when the loss of power happens, it would drop off the network. Just depends on what type of plug and how often it checks in with home assistant. I know Zwave will report that the device is dead if it isn’t heard from in a period of time. You could then act on that. You could also run an automation to “ping” that device every minute or so to see if it is still powered up.
I think you might need to draw a network diagram and see what each node’s reliance of each other is.
TrueNAS hosts your HA, so when you send it the shutdown command it will shut down HA as well.
If the Pfsense is connected to the UPS:
UPS on battery
(optional) Wait for Low Battery
Send shutdown command to TrueNAS (and HA)
Pfsense shuts down
This is how NUT does it.
You can swap TrueNAS and Pfsense and it would still work basically the same. The network will only go down once you’ve sent the shutdown command so it will go through.
You could always put a dumb network switch in between them - your router isn’t needed unless it’s doing routing between subnets etc.
There are pre built PCBs built for AC voltage measurement, usually around $4, could easily integrate with an analog input if you are comfortable working with AC line voltages. Then you would have a history of power quality also. I’d still return it and get a cyberpower, they integrate well with NUT and then you would have current, voltage, and battery sensors built in.