TRIGGERcmd
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    Turn on 3D printer, print, then turn it off

    Raspberry Pi
    1
    1
    241
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • RussR
      Russ
      last edited by Russ

      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:

      c24702c1-cfa3-4427-9cf8-94970ca99625-image.png

      This article explains how to setup the Alexa routine.

      This video shows me printing something via TRIGGERcmd.

      Russell VanderMey

      1 Reply Last reply Reply Quote 0
      • First post
        Last post