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
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
So my read is the UPS part is irrelevant. What you’re really looking for is the option to shutdown your NAS from HA. Does your NAS not have SSH?
Yes! You got it! Thanks!
My NAS has ssh, the problem seems, as I breefly mentioned, that it’s not possible to ssh login to NAS OS (Terramaster TOS 5.1) without user interaction, thus no automation is possible.
I tried creating:
shell_command:
shutdown_tnas: echo YOURTNAS_ADMIN_PASSWORD | ssh -i /config/ssh/id_rsa -o 'StrictHostKeyChecking=no' -p 9222 admin@YOUR_TNAS_IP sudo -S poweroff
and various modifications of this code using my credentials, but calling shell_command service never worked, giving back login errors in logs. I could replicate the problem and paste the code if needed, but searches made a while ago brought me to someone else’s conclusion that it’s a TOS security limitation. Further research would be needed…
I also tried to understand how to make HA act as a SNMP server (which should be possible somehow), since TOS should be able to monitor it and react consequently, but I couldn’t find anything about such configuration hence a way to make it work either. Also, for this to work, HA should have to be able to change the states of SNMP server entities while running and, again, I don’t know if it’s even possible. Again further research would be needed…
That’s why I was asking for a direct integration or another, possibly the simplest, way to tell the damn NAS to shut off remotely.
As you correctly stated, in my circumstance UPS has nothing to do with this job, it just has to keep router, NAS and RPi5 (HA) running while the “power off” automation is launched by HA and NAS shuts off. Once the job is done and NAS is off, the UPS can quietly die and hopefully resurrect as soon as AC is back, it doesn’t matter. Any battery with sufficient juice can do that.
Moreover, creating trigger conditions to eventually lanch a “shutdown NAS service call” within an automation is easy indeed on HA. I can monitor any plug, switch, light etc. connected to HA to tell that my home main power supply is gone, so, in my ignorant opinion, there’s no need for a smart UPS. Literally everything controlled by HA that’s not under UPS (and that then goes off as soon as AC goes off) can be monitored for this purpose directly by HA.
So what I actually need and asked for since the beginning (my english must have rot lately) is: once power has gone, HA red that all conditions were met (different devices unavailables), and triggered the automation I wrote to protect fragile devices such as NAS, what kind of service, if existing, can lauch a Power off signal to NAS without using ssh?
I think this is the best explanation I can give, so
thanks everyone for help,
but a lot more thanks to you and to those who took time to read and understand.
P.s. Sorry for late reply, I couldn’t post more than 5 in few hours since it’s my first day.
P.p.s. building a mechanical finger to physically push the power button on command would require way more than just further research for me and probably cost more than a compatible network APC, so this solution won’t be considered untill further research tells I’m wrong.
This is something that could turn out to be useful, but I wouldn’t know how since it’s just reading TOS sensors, no active interaction is involved. Maybe someone more skilled than me could know something more
The phisical finger statement let me think about a device that i know as “finger bot”, but i don’t know if its true name. There are many versions, wifi or zigbee, and you can create a custom padding with some plaster if the gap between the actuator and NAS power button is too wide.
However, i suggest to leave the SNMP server idea and focus on Terramaster OS. The link i poste previously state that IS possible to connect già SSH the NAS. Note that the procedure is different for TOS 5. Please ala check if SSH should be enabled from the TOS management interface.
I suggest you do some test from your pc and when you’ll find the correct login procedure, you can configure SSHD on the NAS to accept connection without password from a pc that provide a know public key (so called “SSH key based auth”), and even istruct “sudo” command to perform the “poweroff” without a password. But all of this is “advanced” Unix stuff, not an Homeassistant problem. Don’t mean to be rude, my apologize in advance.
Federico
Tried that, as I said, it didn’t work. TOS 5.1 apearently won’t let me automatically login. I regularly use linux ssh on different systems and I thought that would have made things easier. Sure enough I can ssh login from ubuntu terminal to TOS cli and act sudo as much as I want, but I cannot create a service to shut it down automatically.
I’d like to keep autentication on since the system is partly exposed to the web.
I didn’t know about finger-bots, but they actually exist. If noone finds a software solution, you got it.
Thanks
Basically create a script on pi that ssh into server and shuts it down. Run script from an automation. Sounds like you also need to add device to monitor power that works with HA
Do you mean like this?
shell_command:
shutdown_tnas: echo YOURTNAS_ADMIN_PASSWORD | ssh -i /config/ssh/id_rsa -o 'StrictHostKeyChecking=no' -p 9222 admin@YOUR_TNAS_IP sudo -S poweroff
or another method?
Ahhh but this is wonderful. If you can login you can configure ssh key login only for root. Take a look at this https://www.sectigo.com/resource-library/what-is-an-ssh-key to better understand how it work.
If you can enable key login for root user, than you can achive your result. If you can’t do that for root, you can try with the “admin” account and configure “sudo” to accept the poweroff command without asking for the password.
How to Run sudo Without Password
Federico
Thanks for your help! I must say I already gave keys a try, but I followed poor non specific instructions and that could be the reason it didn’t work. Your instructions are surely more accurate. As soon as I can I’ll study them and try again.
Thank you so much!
Edit: after the first excitement, I found out and remembered why it didn’t work, and that’s because TOS appearently only accepts username and password ssh login.
Sorry, thanks for the effort and forgive me, I tried so many times in so many different ways I cannot recall them all toghether.
Would you mind posting the output the connection to the NAS using “ssh -vvv user@ip”?
Federico
Yes, but I have to edit config.yaml and restart, but I just started HA back up and update and I have to sleep few hours…
As soon as I can I’ll set up what needed and send you logs.
Thank you very much!!!
You can do it from your PC. The thing I’m looking for is indipendent from the source. Basically, when you start a new connection, ssh client and server must exchange various information, since they had to find common set of parameters before estahlishing the connection. During this phase (handshake) the server will print all the accepted login method. And also will do the client, print the list of proposed login method.