Octoprint reconnect after Printer 3D turn on

Hi,

I have some connected switch. My printers 3D are plugged on it.
After i turn on my printers, Octoprints were not connected automatically.

To resolve that :

a script octopiconnect.sh

/usr/bin/curl 'http://[IP_OCTOPI]/api/connection' -H 'X-Api-Key: API_KEY' -H 'Content-Type: application/json' --data-binary '{"command":"connect"}'

You need to get your Octoprint API Key for that

automations.yaml

   trigger:
     - platform: state
       entity_id: switch.creality_cr10
       to: 'on'
    action:
      - delay: '00:00:03'
      - service: shell_command.octocr10

in shell_commands.yaml

octocr10: /home/gano/.homeassistant/scripts/octopiconnect.sh
3 Likes

thank you!!! was looking for something just like this!

Hi, you can also use the "Rest Command Integration with code like this:

#Connect Printer Service
rest_command:
  octoprint_connect:
    url: "http://192.168.178.10:7575/api/connection"
    method: POST
    headers:
        X-Api-Key: !secret octoprint_apikey
        #accept: "application/json, text/html"
    payload: '{"command":"connect"}'
    content_type:  'application/json; charset=utf-8'

That’s a great idea. Personally I’d like it to be self-contained and I’ve been using an OctoPrint plugin called PortLister which automatically refreshes the available serial ports when a new device is detected (and if you have auto connect enabled, it will do that). If your printer’s USB to serial chip is not powered by the USB port (no serial port shows up until you turn on the mains power) you can also try that.