Setup Relay Control on a new Raspberry Pi 3 B for OctoPi

Predefined relay numbering
Relay # – GPIO / wPi # – Function – BCM
1 – 21 – Printer Power – 5
2 – 22 – General Lights – 6
3 – 26 – External Fans – 12
4 – 23 –  – 13
5 – 27 –  – 16
6 – 24 –  – 19
7 – 28 –  – 20
8 – 29 –  – 21

Login to Raspberry Pi

sudo su root
cd /usr/local/bin
touch printer_on.sh
touch printer_off.sh
touch lights_on.sh
touch lights_off.sh
touch fans_on.sh
touch fans_off.sh
sudo chmod a+rx *.sh

This creates 6 files and sets them to executable.

The following blocks of code go write into these newly created files.

printf '#!/bin/bash\ngpio mode 21 out\ngpio write 21 0' >> printer_on.sh
printf '#!/bin/bash\ngpio mode 21 out\ngpio write 21 1' >> printer_off.sh
printf '#!/bin/bash\ngpio mode 22 out\ngpio write 22 0' >> lights_on.sh
printf '#!/bin/bash\ngpio mode 22 out\ngpio write 22 1' >> lights_off.sh
printf '#!/bin/bash\ngpio mode 26 out\ngpio write 26 0' >> fans_on.sh
printf '#!/bin/bash\ngpio mode 26 out\ngpio write 26 1' >> fans_off.sh

edit octoPi Config to add some system actions

nano /home/pi/.octoprint/config.yaml
 - action: printer_on
 command: printer_on.sh
 name: Printer On
 - action: printer_off
 command: printer_off.sh
 confirm: Are you sure you want to turn off the printer?
 name: Printer Off
 - action: lights_on
 command: lights_on.sh
 name: Lights On
 - action: lights_off
 command: lights_off.sh
 name: Lights Off
 - action: fans_on
 command: fans_on.sh
 name: Fans On
 - action: fans_off
 command: fans_off.sh
 name: Fans Off
events:
 enabled: true
 subscriptions:
 - command: printer_on.sh
 event: Startup
 type: system
 - command: printer_off.sh
 event: PrintDone
 type: system

Reboot the octoPi server to get all the changes into the system.

If your camera isn’t working correctly open /boot/octopi.txt and adjust the camera_usb_options

for me these are the correct settings camera_usb_options=”-y -r 640×480 -f 15″
more info and settings here https://github.com/foosel/OctoPrint/wiki/Webcams-known-to-work