I have a standard GPIO triggered relay which switches the mains power to my printer on or off. I have two bash scripts in /usr/local/bin that I call to run things. I've set it up so that it gracefully disconnects from the printer before it pulls the power, as that keeps OctoPrint happy.
printer_on.sh
#!/bin/bash
gpio export 17 out
gpio export 18 out
gpio -g write 17 0
gpio -g write 18 0
printer_off.sh
#!/bin/bash
wget -q --header='Content-Type: application/json' --header='X-Api-Key: ABC123ABC123ABC123ABC123ABC123AB' --post-data='{ "command":"disconnect" }' --timeout=10 --tries=1 "http://127.0.0.1/api/connection"
sleep 3
gpio export 17 out
gpio export 18 out
gpio -g write 17 1
gpio -g write 18 1
& my config.yaml has this section added
system:
actions:
- action: pon
command: sudo printer_on.sh
name: Printer Power On
- action: poff
command: sudo printer_off.sh
confirm: Are you sure you want to turn off the printer?
name: Printer Power Off
I use it either via menu items under the main Power menu, or via the Automatic Shutdown plugin, as I have changed OctoPrint Settings -> OctoPrint / Server -> Commands -> Shutdown System to sudo printer_off.sh
as that means that my printer automatically powers down after it finishes the print.
This all works well on my OctoPi, in both 1.3.6 (stable) & 1.3.7 (stable). However, calling wget in a bash script from OctoPrint to disconnect the printer from OctoPrint, before the GPIO triggers the relay & cuts the power, seems like a really, really, dirty hack.
I know that I can easily make both the disconnect and the GPIO calls from my config.yaml, by changing it to look like this:
system:
actions:
- action: pon
command: gpio -g write 17 0; gpio -g write 18 0
name: Printer Power On
- action: poff
command: disconnect; gpio -g write 17 1; gpio -g write 18 1
confirm: Are you sure you want to turn off the printer?
name: Printer Power Off
which works beautifully, but I just can't find out how to disconnect the printer in the OctoPrint Settings -> OctoPrint / Server -> Commands -> Shutdown System settings field.
If the Shutdown System settings field points it to my hacky old bash script with sudo printer_off.sh
it works exactly as it's supposed to, but if I change it to disconnect; gpio -g write 17 1; gpio -g write 18 1
it does nothing at all.
What am I missing, & what is the best practice way of doing what I'm trying to do. Thanks.