Control relay by GPIO ports in OSMC

Good morning, I have the raspberrys ready to use them on a server with 2 hard drives connected by usb and two others for client use.
I do not want the hard drives to always be connected to the server and I have thought about controlling the 230v power supply through a relay connected to the GPIO of the raspberry, the idea is to put an addon or something similar to be able to control the relays but through the KODI system itself, I have seen some addon but it is only to control executions through push buttons, is there any option to control the relays with an addon?

Thanks a lot!!!

There is a Kodi add-on called Kodi Callbacks that allows for you to set triggered events such as running a script when a screensaver turns on and off.

Hi, thank you very much, I like it, but I can not control the GPIO port, I have installed python for it, but I can not do that functions correctly, when using the gpio readall command, for example, it gives me as unrecognized.
Some tutorial to install bein everything I need.

Thank you!!!

I think this is what you are looking for. A tutorial on how to download and compile it is found in the link dillthedog posted in that thread…

Is the Raspberry Pi “the server” or is it a different machine?

Either way, I can’t help but think that there are better ways of approaching this, even if you are sure you need to power down the drives.

Remember that you’ll probably need to unmount the drives before switching them off, and have you considered simply getting the disks to spin down, rather than switching them off at the mains?

1 Like

this simple python2 code could do the job as workaround

Hello, thank you very much everyone for the answers, I clarify that I am not a programmer, therefore I feel my language and my way of explaining things hahaha, I try not to offend anyone hahaha, after this:

Thanks darwindesign everything is already installed and I can already control GPIO outputs with python, basically.
But I would like to integrate the control in the OSMC menu

dillthedog, yes, the server is a raspberry, and I think the best way to avoid a disc wear is to remove the voltage 230v or 12v, they are a lot of movies and the server is always on, but we are almost never watching movies. I don’t like the idea that the hard drive is always with 12v.

Thanks harryberlin but I have no idea what to do with the code, it’s a python file, .py, an addon, I don’t know, you explain it to me.
Thank you.

The most harmful thing to a drive (or any electronics) is a power spike. Using a relay to just click the power off/on is very likely to create a spike. So I think your idea would shorten the life of your drives, not increase it.

Plus you have the high possibility to corrupt the filesystem.

Just leave the drives on and let them spin down when not in use. That will give you the best drive life.

1 Like