Home Assistant Controlling Octoprint through MQTT - Chapter 2
What I didn't mention in the previous post, was the struggle to get it working. I'm not a programmer or a savant that can pick up anything.
The next part is wiring up other buttons for different commands, and that means using more of the Octoprint API, as of this writing, here: https://docs.octoprint.org/en/master/api/
Current issues
Ongoing problem #1: I mentioned how I got connect to work. Using the same pseudo-code, it should be super easy to execute {"command":"disconnect"}. It even pops up the same area as the command: connect did...but it doesn't disconnect.
Ongoing problem #2: Extrude/Retract - this happens frequently when changing out filament, or in some cases...the print fails to start after homing on the corners. Before the homing occurred, it retracted. If I were to just start again, it would retract again! (The nozzle needs to be preheated, extruded, and then turned off.)
Ongoing problem #3: Preheat to 230/turn off - as I just mentioned in #2, necessary for changing filament over.
Turns out, I got them all to work by the end of this post!
Disconnecting Octoprint from the Printer
Probably not even necessary, but I did it. As before, in OctoPrint Settings, under MQTT Subscribe, you need to add this:
The three entries are "Topic", Rest API, and "REST Parameters" |
Topic can literally be anything. I matured my topics a little more, just in case I use a lot of MQTT in the future. First is the device, then the "plugins/mqttsubscribe" for the service, and then the action. /api/connection comes from the Octoprint API information, as does the disconnect format.
Painful reminder: if you do not match the formatting in your orange Disconnect, or the Topic in the purple MiniDisconnect, it will never work.
This was actually a big breakthrough for the rest of the commands. I defaulted to unique topics for each command, copy-pasted the "REST Parameter" directly into the orange box in Node Red - everything just worked.
Setting up Extrude/Retract in Octoprint MQTT Subscribe
Extrude has two lines for parameter, broken up by the comma |
Retract uses the same Extrude, but -10 to pull it back |
I don't know how to rig a button to *only* deliver one result. So I cheated, but it works...so...that's maybe okay.
Note the True/false go to the same place |
The blue template is going to use similar input_booleans. You'll need to create one each for Extrude and Retract in the input_boolean.yaml you made before.
From the /config/input_boolean.yaml |
You will also need to add a button that references the input_boolean.octoprint_mini_extrude, and one for retract - I didn't make them toggle, as you might want to extrude multiple times in a row, or retract multiple times.
Remove "Show State" as it will always just be "Extrude more", and not on/off |
I changed it to "Default Action" instead of Toggle, but...I don't think it really matters.
The blue template will look like this:
Event State Module for the Extrude function |
The orange template is going to be identical, except for the 10 vs. -10.
This should be the same, exact 4 lines in the Octoprint Subscribe REST Parameter |
The purple buttons are boring - the same format you used for the Connect/Disconnect. Just make sure you use the unique topics, and the same topic that you made for it in Octoprint MQTT Subscribe.
The Purple Module for Extrude 10 |
The Preheat Step
I'm going to take a shortcut here - you've already seen the Connect/Disconnect Mini flow.
The orange "Preheat 230" button, sets the nozzle to 230 degrees Celsius...ideal for my PETG filament.
For the "Preheat Off", Octoprint API needs a 0 instead of 230. |
Over in Octoprint Settings, for MQTT Subscribe, it'll look like this:
Done!
Large buttons, taking up lots of space. Ugly! |
Special Bonus Feature: Node Red Flow Overview
The last 5 blue buttons are ugly |
I'll include my job complete notification flow, when I figure out why it doesn't work anymore.
Comments
Post a Comment