Turn on 3D printer, print, then turn it off
-
This is the script I use to print something on my 3D printer via TRIGGERcmd. It turns the printer on, prints the object, then turns it off again.
#!/bin/bash -v tcmd --computer "octopi" --trigger "3d printer smart plug on" sleep 10 # wait for the printer to boot octoprint-cli connection connect octoprint-cli print select $1.gcode octoprint-cli print start # Loop until print job is finished while true; do # Retrieve job status job_state=$(octoprint-cli print status | head -n 1) # Check if the job is finished if [[ $job_state == "Printer Operational" ]]; then echo "Print job finished." break fi # Wait for the next check sleep 10 done tcmd --computer "octopi" --trigger "3d printer smart plug off"
My /root/.TRIGGERcmdData/commands.json file looks like this:
[ {"trigger":"Reboot","command":"shutdown -r","ground":"background","voice":"reboot","allowParams": "false"}, {"trigger":"3d printer smart plug on","command":"echo","ground":"background","voice":"plug on","allowParams": "false"}, {"trigger":"3d printer smart plug off","command":"echo","ground":"background","voice":"plug off","allowParams": "false"}, {"trigger":"Start 3d print","command":"su - pi /home/pi/print.sh","ground":"background","voice":"print","allowParams": "true"}, {"trigger":"apt update","command":"apt-get -y update","ground":"background","voice":"update","allowParams": "false"} ]
It uses two Alexa routines - one to turn my Wyze smart plug on, and one to turn it off (to turn the 3D printer on/off). This is a screenshot of the "off" routine:
This article explains how to setup the Alexa routine.
This video shows me printing something via TRIGGERcmd.