API Call Plugin for Before & After Printing

I've got my 3D printer on a remote power switch that's controlled via Home Assistant. The PI running Octoprint is powered 24/7.. Is there an octoprint plugin that can make REST API (or MQTT) calls to turn the printer on at the start of a print and then off when a print finishes?

This is what I envision my workflow to be.

Upload print to Octoprint
Click the print button (I like this to be manual)
Octoprint powers on printer
Octoprint connects to serial port
Octoprint prints
Octoprint turns off printer

If not then I'll just write the automation in Home Assistant and monitor the print job. What I don't know if I can trigger via Home Assistant is initiating the connection to the serial port.

If it's the TP-Link brand of SmartPlug devices then they publish an API which is simple to use. In NodeJS, it's about this simple:

const { Client } = require('tplink-smarthome-api');
const client = new Client();
const plug =   client.getDevice({host: '192.168.1.200'}).then((device) => {
  device.setPowerState(false);
});

I know how to use the home assistant API to turn things on and off. Is there a way to have OctoPrint make API calls to turn the printer on when I click the print button and turn it off after a print?

See http://docs.octoprint.org/en/master/events/index.html. When the printer is turned off, the connection will drop. You can't click the print button until the connection is restored so you can't do exactly what you want, but you can probably using the connecting event to turn the printer on when you hit connect. Turning off shouldn't be a problem.

1 Like