How to Shutdown Terramaster NAS with SSH keypair and shell_command

Hello,
I red quite a while about various possibilities to achieve my goal (ssh, UPS integration and add-on) and tried few attempts by myself, but I realized that probably I misunderstood the use of theese two last means.
In my particular scenario, I have an old style UPS, without any network or USB interface, powering a RPi5 running Home Assistant OS, the main modem/router and a Terramaster NAS that cannot be controlled anyway but through UI, UPS network or USB signals (no “echo psw…ssh poweroff” for istance).
As I mentioned in title, I was wondering if Home Assistant could act as a Network/USB UPS to send signals directly to the NAS to control it.
The objective is to gain the ability to eventually turn off NAS with an automation triggered by the loss of other devices connection as it would be in case of general power loss.
If this is possible and I didn’t get it, I’m dumb, so sorry and please help me understand what I didn’t.
Thanks :hugs:

APC UPS with USB connection.
How to connect your APC UPS to Rpi and Home Assistant using apcupsd!.

Or basically put this in your search engine… There are more…

site:community.home-assistant.io ups serial

Sorry, but if I understand correctly, in the scenario you just posted, the APC has USB. As I said, mine does not. I need Hassio to operate as an APC sending signals.

But thanks for the answer anyway

No serial either? You can get serial to usb boards.
If there’s no network, usb, or serial, You will need to get really creative automating it. Time to just get a different one. The MOV resistors that do most of the spike suppression wear out after a few years and they won’t protect you as well when too old.

1 Like

Thank you for interest! Sadly no, nothing that communicates outside the box. Even though old, last week we had several black outs in 2 days and the system performed perfectly. I know it will not last forever, but I would like to keep it going until it can.

If there is an indicator light on it, or a warning-shutting down buzzer, or some real world trigger you can sense with an esp or a PI gpio you can get that into HA and trigger something.
Like I said, tricky.

In my imagination the need for APC to send informations is not needed. I could tell home assistant to read the state of different entities and if those entities are all not availables, trigger a service call. So what I would need and asked for is Home assistant to connect directly to the nas and act as if it was one of the nas compatible APC that sends informations to NAS OS to turn itself off. As I said, this cannot be achieved with ssh.

1 Like

Addendum:
I’ve seen that Synology has an integration that allows few controls on Synology devices, including shutdown, so I guess it’s possible to call a Shutdown service from Home Assistant to Synology NAS, which is what I’d be looking for. But mine is a Terramaster NAS and I’m starting to guess that to reach the objective, a proper and at least basic Terramaster integration should be created.
At this point I find myself lucky posting the Topic in the right section.
Could a smart and dedicated dev build a generic integration, covering a wide range of protocols from different NAS brands, maybe symply recording those bloody usb signals and making them available to be shot from Home assistant to any NAS through USB or network? My knowledge level is near 0 so forgive me and wake me up if I’m daydreaming.
If the feature request is correct instead, please add this feature as in my opinion it would be very unexpensive to use “old style” UPSs, still in sale and very low budget compared to NAS compatible Network UPS, and let Home Assistant manage automations.
Thanks for any suggestion or (mild) insult

Addendum 2:
I forgot to mention that since Terramaster NAS can also work with SNMP servers, likely reading states of somewhat enity created ad hoc, I also tried understanding how to use SNMP server integration on Home Assistant for the purpose, again with no result.
If there was any way to get the job done using this environment, would anyone help teaching me how such a communication between home assistant and NAS could be established?
Thanks again

What is the specific model for the UPS you are trying to setup?

Thanks for the answer.
Probably I didn’t explain myself, but if you read carefully, I already wrote everything.
I don’t need to set up an UPS since it has nothig to be set up, it’s just a 300w battery with 2 220v AC outputs attached to the main power line.
As I wrote some time already in this topic, what I would need and asked for is Home assistant to connect directly to the NAS and act as if it was one of the NAS compatible APCs that sends informations to NAS OS to turn itself off. As I said, this cannot be achieved with ssh, but probably by using SNMP server, meaning that Home assistant could act as a SNMP server miming a SNMP capable ups, so that the NAS could read some state of some entity and decide it’s time to turn off.
Sorry if I didn’t made myself clear, I’m not english and not using translators, I probably mistook explaining something.
Thanks again

So you you don’t have a proper UPS and need to have battery state sent to Home assistant.

You need to look into a ESP or other type PCB that allows you to read the voltages of the batteries to then send that data into your home assistant instance. Someone with more experience will be best to answer in this regard.

I use an APC UPS via its serial to usb cable plugged into my Synology NAS that is running as a server for NUT intergration to pull that data from into my home assistant instance at this time.

It then uses the Synology integration to tell it when it should shut down and I use the Hass agent on the main PC to send a shut down command as well, when power is restored the HA instance sends a wake on lan command to the PC if it has not turned on via bios setting set to power on which is also set on all primary devices.

Again, no. Please read all above before.
Thanks

I did read… this is why I asked for a specific model, we need data to work with, since you did not state exactly what one you had I worked with reply you made to my question.

Probably my english is rusting, sorry for that. But try not to think about using any communication between UPS and Home assistant and UPS and NAS.

So your entire post is redundant, just set the device to power on when power is restored and use a smart plug with power monitoring with a timer to tell devices when to power off, the only issue with this setup is that you can’t do safe shutdown in the case of a NAS and you risk data loss for anything that is pending to be written at the time of sudden shutoff.

That’s what I want to do and that’s the problem. However I still don’t know how to make Home assistant turn of the NAS and in which way they can communicate

Without a data line you can’t, solutions were provided.

You need to look into a ESP or other type PCB that allows you to read the voltages of the batteries to then send that data into your home assistant instance. Someone with more experience will be best to answer in this regard.

The NAS is tied via the integration and if there is no integration use a smart plug tied to the timer of the main plug being used for the detection of power loss.

edit: a quick look up for Terramaster NAS’s gives this post

1 Like

I would think about a ping to a device of your choice that is not under the UPS protection, if ping fail, this is the condition to trigger the NAS shutdown. Homeassistant provide a ping integration. Ping (ICMP) - Home Assistant

Now you must find a way to remote control your NAS, the simplest way is ssh or telnet. Or you can reverse the http api being called when you do the shutdown from it’s management web interface. If you could make a script to achive the shutdown, then you have all you need to create an automation in Homeassistant that power off your NAS and can, eventually, power off HA itself.

I understand that is not a complete and a step by step how to, but the tickyest part is the NAS one, and without the phisical device itself it’s not possibile to help further.

Maybe you can have a look at this post to start : How to log in to the SSH terminal? - TerraMaster Official Forum

Federico