How to send remote commands to second Pi from OctoPrint

I've got two additional Raspberry Pi computers which I use in conjunction with my OctoPrint installation. Since I needed the ability to remotely shutdown one of them from OctoPrint, I thought I'd show how.

Requirements

In order to do this, it will be useful to install the Gcode System Commands plugin in order to associate a named GCODE command to a command line.

Instructions

  1. In a remote terminal session to OctoPrint:
ssh-keygen -t rsa -b 2048     # Press Enter for each of the prompts
ssh-copy-id pi@pisense.local  # Substitute for the hostname of the remote Raspi
ssh -t pi@pisense.local "ls"  # Practice a test command (no pw required)
  1. In a web session with OctoPrint, Settings -> Gcode System Commands -> +

OCTO900 -> /usr/bin/ssh -t pi@pisense.local "sudo poweroff"

Press Save to save the setting.

  1. Back in the remote shell to the OctoPrint server:
nano ~/.octoprint/config.yaml

Edit/add the controls section:

controls:
- children:
  - command: OCTO900
    name: PiSense OFF
  name: Custom Events
  type: section

Restart OctoPrint. Note the new section and button on the Control tab.

21%20PM

Review

Using a shared key, the OctoPrint-related Raspberry can now run remote commands on the second Raspberry Pi as controlled by a button on the interface.

I have a similar problem I can't find an answer to yet. I created a system that at the beginning of the print through an Adafruit Servohat on my Octprint Pi, uses a servo to deploy and then retract a brass brush to clean off the extra filament hanging off of the extruder. I can control it easily through a couple of simple python scripts, but I can NOT find how I pass those python commands out of Octoprint to the Pi. Help?

The documentation would probably help:

https://docs.octoprint.org/en/master/events/index.html

https://docs.octoprint.org/en/master/features/custom_controls.html

Gcode system commands plugin: