API command to load/unload filament

What is the problem?

I'm currently setting up octoprint within my home assistant dashboard. Together with the mqtt subscribe plugin I was able to get some basic commands working (heat tool, home all, etc). But I'm having problems with commands to load/unload the filament. Using /api/printer/tool with command extrude and a positive and negative value works, but only up to a value of 200 (minus or positive).

Ideally I'd like to press a load/unload button and the filament is loaded/unloaded until I send a stop command. I'm not sure whether I'm looking in the wrong section of the API documentation or I'm missing something here.

What did you already try to solve it?

tried to use /api/printer/tool with command extrude

Have you tried running in safe mode?

nope, don't think it is relevant to run in safe mode.

Did running in safe mode solve the problem?

nope, don't think it is relevant to run in safe mode.

Systeminfo Bundle

Since it is not an error per se, but rather a question about the API, I don't think it is needed.

Additional information about your setup

Octoprint: Version 1.8.6
Octopi Version: Version 0.18.0, running on Raspberry Pi 4 Model B Rev 1.1

I searched here in this forum, the API documentation and of course the internet, but couldn't find what I was looking for.

Any tips on how to solve this would be appreciated.

OctoPrint doesn't limit the commands you can send through /api/printer/tool, it should do exactly as you tell it.

My suspicion instead is that your printer is preventing the long extrusion. This is an option in Marlin so it could have been configured to be a limit of 200mm. Checking the terminal or enabling serial.log and checking that when you send the API command would tell you the answer.

1 Like

It seems you were right with your suspicion @Charlie_Powell.

2023-01-05 11:36:39,822 - Recv: ok
2023-01-05 11:36:39,825 - Send: G1 E-250 F300
2023-01-05 11:36:39,833 - Recv: echo: too long extrusion prevented
2023-01-05 11:36:39,833 - Recv: ok
2023-01-05 11:36:39,835 - Send: M82
2023-01-05 11:36:39,838 - Recv: ok

In order to get to the bottom of this, I just tried the load/unload fillament buttons within the octoprint control section and that doesn't work either. Printer is a anycubic vyper which otherwise just works perfectly.

2023-01-05 11:39:44,393 - Send: M117 Loading filament
2023-01-05 11:39:44,402 - Recv: ok
2023-01-05 11:39:44,403 - Send: M83
2023-01-05 11:39:44,421 - Recv: ok
2023-01-05 11:39:44,431 - Send: G1 E50 F60
2023-01-05 11:39:44,437 - Recv: ok
2023-01-05 11:39:44,441 - Send: M117 New Filament Loaded
2023-01-05 11:39:44,447 - Recv: ok

Just realized that this functionality comes from a plugin that hasn't been updated in 2 years......

But just to be clear, filament load and unload are not available via the API, correct? The only thing I can do is rerun the same command until the filament is out, which is fine, just a little bit more complex in the setup. I'll prepare an automation in home assitant and post the code here.

Ok, here is at least a starting point for this. Beware, this is far from perfect and should be used with care.

I'm using the mqtt subscribe plugin (you could also achieve this by directly calling the API in home assistant as well).

This enables us to send a mqtt command from home assistant, which will then trigger the API command to extrude the filament with a negative value, or removing the filament.

This is the script I'm using in home assistant:

In laymans terms:

  • check if nozzle temperature is above 228
  • if yes, then publish topic /vyper/filament/remove three times, since we're limited to 200.
  • if not, send mqtt command to heat the nozzle.
  • wait 5 minutes until the nozzle is above 228
  • publish topic /vyper/filament/remove three times, since we're limited to 200.
alias: Octoprint remove filament
sequence:
  - if:
      - condition: numeric_state
        entity_id: sensor.octoprint_tool_0_temperature
        above: 228
    then:
      - service: mqtt.publish
        data:
          topic: vyper/filament/remove
          payload: retract
      - service: mqtt.publish
        data:
          topic: vyper/filament/remove
          payload: retract
      - service: mqtt.publish
        data:
          topic: vyper/filament/remove
          payload: retract
    else:
      - service: mqtt.publish
        data:
          payload: "{\"temp\" : 230}"
          topic: vyper/temperature/tool
      - wait_for_trigger:
          - platform: numeric_state
            entity_id: sensor.octoprint_tool_0_temperature
            for:
              hours: 0
              minutes: 5
              seconds: 0
            above: 228
      - service: mqtt.publish
        data:
          topic: vyper/filament/remove
          payload: retract
      - service: mqtt.publish
        data:
          topic: vyper/filament/remove
          payload: retract
      - service: mqtt.publish
        data:
          topic: vyper/filament/remove
          payload: retract
mode: single
icon: mdi:printer-3d-nozzle-heat

The biggest "risk" here is to send the extract/retract commands without any other checks and I wasn't able to stop the extract/retract from my printer. So use with great care!

I'm doing this as a preparation for the installation of klipper on my vyper, because the LCD doesn't function anymore if installed.

Also, the speed for extract/retract is way slower than the load/unload filament function of the printer itself.

I would still prefer a functionality which is the same as the one on the printer: remove filament, add filament and stop. So if anyone has an idea on how to achieve this, I would appreciate it.

If anybody has any questions, hints or suggestions, please let me know.

second screenshot, since I'm a new user and can only include one media posting at a time.

On many gcode commands, you can specify a "feed" (F) parameter. Is there a way to do that here?

is that the feed rate you're talking about?

This is what I found in the API documentation:

extrude
Extrudes the given amount of filament from the currently selected tool. Additional parameters:
amount: The amount of filament to extrude in mm. May be negative to retract.
speed: Optional. Speed at which to extrude. If not provided, maximum speed for E axis from printer profile will be used. Otherwise interpreted as an integer signifying the speed in mm/min, to append to the command.

https://docs.octoprint.org/en/master/api/printer.html#issue-a-tool-command

Yes, that should be the one. The comment seems to indicate that you should check the printer profile to make sure the maximum speed for E is correct. Alternatively, you can see if you can send a value higher than the printer profile value.

1 Like

Nice, MQTT Publish plugin user. Interesting use case for sure, but curious why use that in HA vs just direct API commands to OP?

1 Like

I'll try that out as well, should be fairly easy I think.

@jneilliii : Thanks for the plugin first of all! As for the use case in HA. I already build a dashboard in HA to control some functionality so it made sense to enhance the dashboard to include this as well. In the end, I have to send the command to the API from somewhere. This way I just take my mobile with me to the 3d printer (located in a separate room in the basement) and can control everything from there.

I also use HA to send notifications about the status at 33%, 66% and finished, including screenshots from the webcam. HA is basically the brains for a lot of stuff in my home.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.