Notifications
Clear all

RaspberryPi a clean remote power switch

Page 1 / 2

3Dietrich
(@3dietrich)
Active Member
Joined: 2 years ago
Posts: 8
Topic starter  

I have a RaspberryPi with Octoprint in my (Wifi) household. I turn on my printer (together with Octoprint) only when I want to print. Turning it on is very simple: power on. But when I switch it off, I have a problem which some of you surely know: To be correct, you have to shutdown RaspberryPi software first (via terminal or website), and if RaspberryPi is really in "off" state (how to check that?), only then I can turn off the power.

Exactly this I would like to have automated: I simply switch something physically or call Siri (how I'm doing with the remote socket so far) in the living room, this causes first the RaspberryPi to shut down and then the power turns off.

I know that it is also possible to just switch power off, so I did it for years. But it happens increasingly often that Octoprint starts in safe mode, which I think is due to the missing shutdowns.

I can imagine that many RaspberryPi users have this problem (or a solution), but I just can't find anything...


Quote
Will
 Will
(@will)
Noble Member
Joined: 1 year ago
Posts: 2017
 
Posted by: @3dietrich

I have a RaspberryPi with Octoprint in my (Wifi) household. I turn on my printer (together with Octoprint) only when I want to print. Turning it on is very simple: power on. But when I switch it off, I have a problem which some of you surely know: To be correct, you have to shutdown RaspberryPi software first (via terminal or website), and if RaspberryPi is really in "off" state (how to check that?), only then I can turn off the power.

You can shutout down from the command line, see the article ...

https://linuxhint.com/shutdown-raspberry-pi/

The details of where to add it and power management I'llleave to you 🙂

I was kidnapped by mimes.
They did unspeakable things to me.


ReplyQuote
Ron
 Ron
(@zander)
Famed Member
Joined: 2 years ago
Posts: 3045
 
Posted by: @3dietrich

I have a RaspberryPi with Octoprint in my (Wifi) household. I turn on my printer (together with Octoprint) only when I want to print. Turning it on is very simple: power on. But when I switch it off, I have a problem which some of you surely know: To be correct, you have to shutdown RaspberryPi software first (via terminal or website), and if RaspberryPi is really in "off" state (how to check that?), only then I can turn off the power.

Exactly this I would like to have automated: I simply switch something physically or call Siri (how I'm doing with the remote socket so far) in the living room, this causes first the RaspberryPi to shut down and then the power turns off.

I know that it is also possible to just switch power off, so I did it for years. But it happens increasingly often that Octoprint starts in safe mode, which I think is due to the missing shutdowns.

I can imagine that many RaspberryPi users have this problem (or a solution), but I just can't find anything...

There are special cables you can buy and add-on kits to achieve a safe shutdown of the PI. Just goto PiShop and look around, maybe search on safe shutdown.

The GUI of course has a shurdown option, and command line is shutdown now or sudo shutdown now, can't remember which.

It is considered poor judgement to traverse a chasm in 2 leaps.


ReplyQuote
3Dietrich
(@3dietrich)
Active Member
Joined: 2 years ago
Posts: 8
Topic starter  

Well, I know this stuff like terminal calling "shutdown ..", or a switch to get the same shutdown. Yes, "shutting down" raspi via WiFi is possible. But all the solutions keep the raspi on the main power. You have to come and switch it off yourself. That is not the solution I want.

I want to avoid terminal or going to the raspi, I want to shut down remotely. maybe by switching or, if possible, by calling "Alexa/Esp32/Siri switch off printer" (anyhow but easy) and it does

  1. shut down the raspi, then
  2. cut the energy (relay?) from mains power (to switch of raspi and printer)
  3. but still there is something I can switch raspi and printer on again (remotely of course)
This post was modified 2 months ago by 3Dietrich

ReplyQuote
Will
 Will
(@will)
Noble Member
Joined: 1 year ago
Posts: 2017
 

@3dietrich 

That sounds more like two controls. One turns on/off power to the RaspPi and the other issues a shut down command directly to the RaspPi.

The question is, what receives and operates on the command to turn the RaspPi power on, can't be the RaspPi because it's not on. Similarly, the RaspPi can't shut itself down and then shut off the power.

You could potentially introduce a delay long enough to shut it down if yo have a large enough capacitor.

I was kidnapped by mimes.
They did unspeakable things to me.


ReplyQuote
DaveE
(@davee)
Honorable Member
Joined: 1 year ago
Posts: 565
 

Hi @will et al,

  My experience of R-Pi is very short and out of date, but surely, assuming it is running a version of Linux related to Ubuntu, etc, which is also on PCs, etc., that do power down .. although their power supply is typically still (at least) partially live.

And on a PC, you normally hit the 'Power Off' software command, which causes it to sync its discs and other things to make everything tidy, as has required by all Unix derived systems, and then it pulls the power on itself.

If you close the R-Pi down tidily, which is 'normal' shutdown, then the only bit missing is a way to pull the power. 

I can't help feeling this has been addressed by someone already, but if not then I presume there is someway of adding a little piece of code to toggle a GPIO port, or similar, to release a power relay, as Linux finally 'signs off'. (A corresponding method to close the relay will be needed to power the system up.)

Of course, if the relay is switching mains power, then electrical safety considerations must be observed.

Just a thought .. might be practically impossible.

Best wishes all, Dave


ReplyQuote
3Dietrich
(@3dietrich)
Active Member
Joined: 2 years ago
Posts: 8
Topic starter  

yea, something like this. Thank you for your thoughts.

I also posted it in Suggest NEW Content hoping that @DroneBot Workshop might find something and make another great video 🙂


ReplyQuote
Ron
 Ron
(@zander)
Famed Member
Joined: 2 years ago
Posts: 3045
 

@davee Any shop selling Pi parts will sell a safe shutdown kit here is what a quick google turned up. https://learn.sparkfun.com/tutorials/raspberry-pi-safe-reboot-and-shutdown-button/all

Here is another solution https://embeddedcomputing.com/technology/open-source/development-kits/raspberry-pi-power-up-and-shutdown-with-a-physical-button

It is considered poor judgement to traverse a chasm in 2 leaps.


ReplyQuote
DaveE
(@davee)
Honorable Member
Joined: 1 year ago
Posts: 565
 

Hi Ron @zander ,

   Thanks for pointing these possibilities out. Unfortunately, I am not convinced they meet the requester's aspirations. It all depends upon the specification of what you are trying to achieve.

If you want to close the R-Pi down tidily, but happy for the power supply to be still drawing power from the mains, then the solutions you point to are applicable. In reality, all they do is add an extra button that runs the shutdown command - and that may be useful in the right circumstance.

The disadvantage with this scheme is many small power supplies, (e.g. many wall-wart types), still consume an appreciable amount of power, even when there is no power demand.

My interpretation of the requester's question, was to have a method which depowered everything. This implies a relay or equivalent, to depower the power supply unit, once the R-Pi was safely shutdown internally. This is more tricky, and suggestions from @will and myself attempted to suggest approaches to the problem.

Best wishes and take care my friends, Dave


ReplyQuote
Ron
 Ron
(@zander)
Famed Member
Joined: 2 years ago
Posts: 3045
 

@davee Absolutely correct, they do not meet his requirements but it is the important first step. If the Pi is not shut down properly then it is easy to corrupt it's 'disk'.

I don't know squat about Octoprint, but the mention of 'safe mode' suggests a similar issue there.

I think he will need at least a 3 step approach, first an orderly shutdown of the Pi, then maybe the same for the 3D printer, and finally kill the mains.

I doubt if siri is a good choice just because it's Apple and remember I own 5 Apple devices.

Perhaps Alexa or Google will already have some 'scripts' for this. Sending the 'sudo shutdown now' command to the Pi can very likely be done using ssh or similar. I have no idea about octoprint, but once both the Pi and 3D printer are off (a simple timer of say 5 mins) then turning off a remote plug is a piece of cake.

It is considered poor judgement to traverse a chasm in 2 leaps.


ReplyQuote
frogandtoad
(@frogandtoad)
Noble Member
Joined: 3 years ago
Posts: 1387
 

@3dietrich

Posted by: @3dietrich

Well, I know this stuff like terminal calling "shutdown ..", or a switch to get the same shutdown. Yes, "shutting down" raspi via WiFi is possible. But all the solutions keep the raspi on the main power. You have to come and switch it off yourself. That is not the solution I want.

I want to avoid terminal or going to the raspi, I want to shut down remotely. maybe by switching or, if possible, by calling "Alexa/Esp32/Siri switch off printer" (anyhow but easy) and it does

  1. shut down the raspi, then
  2. cut the energy (relay?) from mains power (to switch of raspi and printer)
  3. but still there is something I can switch raspi and printer on again (remotely of course)

If you really want such automation via Alexa or even Siri, then you probably want to integrate them with something like "Home Assistant" to handle the automation for you - You'd just need to add a smart switch to handle the power up and shutdown states of the pi.  MQTT can be installed on "Home Assistant", which will be used to send the commands to each of the the devices as well as receive acknowledgements of their status - This is a very versatile solution, imo.

Cheers


ReplyQuote
Ron
 Ron
(@zander)
Famed Member
Joined: 2 years ago
Posts: 3045
 

@frogandtoad Don't forget, the Pi has to have the 'sudo shutdown now' command issued from the command line. SSH might be doable, but it's a *nix box so orderly shutdown is required to avoid corrupted SD card. The power turn off is trivial, it's the software side that is a wee bit of a challenge.

It is considered poor judgement to traverse a chasm in 2 leaps.


ReplyQuote
frogandtoad
(@frogandtoad)
Noble Member
Joined: 3 years ago
Posts: 1387
 

@zander

Posted by: @zander

@frogandtoad Don't forget, the Pi has to have the 'sudo shutdown now' command issued from the command line. SSH might be doable, but it's a *nix box so orderly shutdown is required to avoid corrupted SD card. The power turn off is trivial, it's the software side that is a wee bit of a challenge.

Of course not, Ron, I did not forget that!
I posted my response with this as being one of the many solutions via an IOT smart home solution.

Ultimately, if I wasn't clear...  If you really want to incorporate a fully automated home network IOT solution, then as I suggested, Home Assistant, Node-RED (and many others), can and do integrate with Alexa, Siri, Mobile Phones, etc... via MQTT to automate anything.

Home Assistant for example can call/invoke a script on a local client machine (e.g:- pi), either directly via ssh, or via MQTT... either is possible... I suggest MQTT because it can also handle smart wall switches/power points for you, and MQTT can be configured to tell you when the device is offline - You should know that from recent discussions 😉

Anyhoo... the OP hasn't even acknowledged my suggestion, so I guess they have lost interest.

Cheers


ReplyQuote
3Dietrich
(@3dietrich)
Active Member
Joined: 2 years ago
Posts: 8
Topic starter  

@frogandtoad If "OP' means "TS" (Topic Starter): suggestion acknowledged.

Yes, this is a cool idea.

I think I already installed "Home Assistant" once and ended up in chaos, but maybe I should try again.


ReplyQuote
Ron
 Ron
(@zander)
Famed Member
Joined: 2 years ago
Posts: 3045
 

@3dietrich I re-read your OP and had to google octoprint. Turning off octoprint and turning off the Pi are one in the same. All you need to do is shutdown the Pi, there is no need to kill power to it, the Pi is the 'mains' switch in this case. I don't know about your 3D printer however, it may be you need it to be on a software controlled plug so the Pi shutdown script would look something like

1. Shutdown Octoprint

2. Turn off power to 3D printer

3. shutdown Pi

Unfortunately there is no way to have the Pi turn itself on without another computer being involved.

I think you need to rethink and restate your objectives as they appear to be in conflict.

Is it possible to plug the Pi and 3D printer into a WiFi capable power bar? Getting the Pi to restart might be an issue, and I have no clue what the stop and start rules are for a 3D printer, but at least the WiFi enabled power bar gives you a central point of power and a 'boot strap' type of ability albeit that will depend on the 3D printer and Pi detecting power on and performing the correct set of procedures.

Good luck.

It is considered poor judgement to traverse a chasm in 2 leaps.


ReplyQuote
Page 1 / 2