Octoprint automation

by af340, published

Octoprint automation by af340 Feb 22, 2018


Liked By

View All

Give a Shout Out

If you print this Thing and display it in public proudly give attribution by printing and displaying this tag.

Print Thing Tag


Thing Statistics

1888Views 196Downloads Found in 3D Printers


Octoprint automation for all 3d printers so useful for me enjoy ;)

Eng/Fr translation/traduction


Using Event/action and python script on raspberry pi 2/3 with python (or other distrib)

  • Automatically switch on/off light when connected/disconnected to octoprint UI
  • Automatically switch off printer when job finish at night
  • Manual action from octoprint UI to start/stop light and printer power
  • Optionnaly send text when job finished with total working time and job name
    (additional app needed)

If you need only 5/12V power to switch on/off your light, check also octoprint automation led light
In addition Relay model comes from https://www.thingiverse.com/thing:1630253

Utilisation des events et action octoprint sur raspberry pi 2/3 avec python (et autres distribs)

  • Allume/eteint automatiquement la lumiere sur connexion/déco de l'interface octoprint
  • Eteint automatiquement l'imprimante qd le job se termine la nuit
  • Action manuelle octoprint pour allumer/éteindre la lumière ou l'imprimante
  • En option: envoie sms qd le job se termine avec le temps total et le nom du job (nécessite app supplémentaire)

Supplément: Modèle Relay https://www.thingiverse.com/thing:1630253


Nota: When you click on links to various merchants on this site and make a purchase, this can result in this site earning a commission, Thank you in advance ;)

You can support me and buy your relay from here:


Python script using RPi.GPIO library
(pip install RPi.GPIO)

  • Copy Event and Action from config.yaml to your existing config.yaml
    (installed by default to .octoprint folder from raspberry pi)
  • Copy action.py and event.py into the folder ~/.octoprint/scripts


  • Automatically Start/stop light each time someone connect/exit to octoprint UI
  • Automatically Switch off printer power when the job is finished during night (interval of time)
  • Optionnal: send text with total working time and job name (need additionnal app)


  • Start/Stop printer and start/stop Light from action menu

Send text

Without home smartphone:
I'm developping a gsm module to communicate directly with the pi, with a sim card, octoprint will be able to send message to your phone when job is finished ,)

With Home smartphone:
For android, you can get as example this free app
You'll need to keep at home an old/unused phone with its sim card as a text server to communicate with your own smartphone.

Script python necessitant la librairie RPi.GPIO
(pip install RPi.GPIO)

  • Copier Event et Action de config.yaml dans votre fichier existant config.yaml
    (installer par défaut dans le répértoire .octoprint sous raspberry pi)
  • Copier action.py et event.py sans ~/.octoprint/scripts/


  • Allume/Eteint automatiquement la lumiere quand qq'un se connecte/deconnecte sur Octoprint

  • Eteint automatiquement l'imprimante qd le job se termine pendant la nuit (intervalle d'heure)

  • Optionnel: envoie sms avec temps total et nom du job terminé (Necessite application supplémentaire app)


  • Allume/éteint imprimante et Allume/éteint lumière depuis menu action

Si vous avez besoin de gérer une source de 5/12V uniquemenbt pour des leds, voir également octoprint automation led light

In addition Relay model comes from https://www.thingiverse.com/thing:1630253

You can support me and buy your relay from here:

Print Settings


Doesn't Matter


Doesn't Matter


Apply to all printers using octoprint

relay model comes from https://www.thingiverse.com/thing:957292

More from 3D Printers

view more

All Apps

Auto-magically prepare your 3D models for 3D printing. A cloud based 3D models Preparing and Healing solution for 3D Printing, MakePrintable provides features for model repairing, wall thickness...

App Info Launch App

Kiri:Moto is an integrated cloud-based slicer and tool-path generator for 3D Printing, CAM / CNC and Laser cutting. *** 3D printing mode provides model slicing and GCode output using built-in...

App Info Launch App
KiriMoto Thing App

With 3D Slash, you can edit 3d models like a stonecutter. A unique interface: as fun as a building game! The perfect tool for non-designers and children to create in 3D.

App Info Launch App

Hi and thanks for your tutorial !

I have installed a relay to power off my printer when the print is finish and also to power on and off with octoprint menu.
My problem is that when my orange pi lite is connected with the anet a8 mainboard with usb cable, the mainboard is supply by usb. So my printer is never off.
Today I didn't find solution. Can you help me ?

My raspberry pi is also connected to the mainboard to drive the printer with octoprint, but the relay switch off the printer, not the pi.
(we communicate in english even if we could in french ;))


Thanks for your answer.
I think I have found my problem. I have connected the 0V on my relay, and not the 12V !
If the general supply 0V is cut , there is always the 0V of USB.
I try to modify evening and I give you a feedback.

In English it's better, its can help other people which have the same problem than me

So here's .......... that's good news
I modified my yaml by taking inspiration from yours, added some lines and modified others
Now everything is ok for me it works fine
Your help has been invaluable and I thank you very much
Congratulations for this project and I hope other people here it's worth it
For my part it remains for me to see how integrated 2 printers in octoprint since I have 2 at my disposal
Again THANK YOU and good luck
Best regards

Good news! have fun ,)
Seems octoprint can handle several printers easily: https://www.youtube.com/watch?v=7Saa1HpLRoM

Can you provide me your yaml if you do not mind so I can compare and see what's wrong

In enclose my config with personal keys replaced with xxxxxxx
i'm not sure your issue comes from config, before updating your config with my event and action, your octoprint server worked properly?

Comments deleted.

Everything seems correct, the only difference with mine is the section order, event section comes after appearance for me
Normaly does not matter but you can still try

And also host variable comes into section server (missing for you):
firstRun: false

color: black
name: AF340 printer

Just a small question should I put the dash before action
example << - action: streamon >>

yes mandatory - action:

Thank you again for your help
That's exactly what I did but nothing works when I run octoprint with my browser
To be sure I did not corrupt my system I reinstall everything with a functional backup
I will keep you informed of the rest thanks

By cons I have another problem the two commands Start Video and Stop Video have disappeared from the menu

from you config.yaml , you have to add the example i provide, not replace your config.yaml with mine ,)

if you use the same action than me to start your streaming, the code is:

  • action: streamon
    command: /home/pi/.octoprint/scripts/webcam start
    confirm: false
    name: Start video stream
  • action: streamoff
    command: /home/pi/.octoprint/scripts/webcam stop
    confirm: false
    name: Stop video stream


Thanks a lot for your help
Actually it was only a question of rights, now the orders work
Thank you

Into config.yaml, i set the path to /home/pi/.octoprint/scripts, means you replace the path to /home/pi/Octoprint/scripts? (dot octoprint to Octoprint?)

Next, if this is what you did voluntarily (and copy the .py to the correct path), check you can execute the file:
move to the scripts folder and
sudo chmod +x event.py
same for action.py
you can also type: sudo chmod 775 action.py
(it will give right to exec the file)
you can also change the owner:
sudo chown pi:pi action.py (same for event.py)

Normally, it should solve your right issue.

I tried but unfortunately when I click on one of the four button it puts me << Command for custom: startanet failed with return code 126:
STDERR: / bin / sh: 1: /home/pi/OctoPrint/scripts/action.py: Permission denied >>