Disconnect printer via Event Manager

What is the problem?

I am using a script call in the Event manager at Event "print done" to turn off the 3d printer via a smart socket. Before that I would like to disconnect the printer via the Event manager.

What is the correct command for this?

And sorry, probably the solution is so simple....

What did you already try to solve it?

I have searched the manual, this forum and the internet and unfortunately found no solution

Systeminfo Bundle

octoprint-systeminfo-20220417202901.zip (9.0 KB)

Additional information about your setup

OctoPrint Version: 1.7.3
printer: SnapMaker 2 A350
browser: Chrome
operating system: raspberry os
home automation smart socket: homematic

I know that the tasmota plugin got this feature so I'm tagging @jneilliii - he probably knows how

I'm doing it via internal commands available in octoprint plugin environment. I'm not sure if OctoPrint's CLI has a disconnect command or not, but you could use it's API to do it with curl command.

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

1 Like

Thanks @jneilliii

Could you probalby post an example for such a curl command? I'm a newby with Web-Requests :see_no_evil:

Something like this I think (untested). You have to include an API key, typically generated from the Application Keys settings in OctoPrint.

curl -s -H "Content-Type: application/json" -H "X-Api-Key: YOUR_API_KEY" -X POST -d '{ "command":"disconnect" }' http://localhost:5000/api/connection

Thanks a lot, works!!

1 Like

Hi,

Unfortunately the solution does not work as desired. The disconnect via curl works very well from the command line. But when it is executed by the Event Manager, nothing happens.

I have a number of debug logs turned on that have something to do with events. There I can see that the event is triggering. But unfortunately I can't see from this why the disconnect doesn't work.

What else could I do to track down the error?

Thanks a lot
Sepp

Please upload them so we can see too.

Hi, sorry, yesterday it was late and I forgot to upload the package ...

In order to have an easy test possibility without having to print, I tried to set an event to "Connected", which should trigger the disconnent.

The event configuration looks like this:

events:
  subscriptions:
  - command: python3 /home/pi/ssh-paramiko/homematic-3DPrinter-off.py
    debug: false
    enabled: true
    event: PrintDone
    type: system
  - command: 'curl -s -H "Content-Type: application/json" -H "X-Api-Key:blabla"
      -X POST -d ''{ "command":"disconnect" }'' http://localhost:5000/api/connection'
    debug: true
    enabled: true
    event: PrintDone
    type: system
  - command: 'curl -s -H "Content-Type: application/json" -H "X-Api-Key:blabla"
      -X POST -d ''{ "command":"disconnect" }'' http://localhost:5000/api/connection'
    debug: true
    enabled: true
    event: Connected
    type: system

I noticed that in config.yaml in the curl command a line break is inserted before the "-X". As soon as I change something in the event manager, it is inserted again, even if I manually remove the line break in config.yaml.However, this does not seem to be the problem, because the command is displayed completely in the log.

This morning I discovered an error message in the log that had escaped me until now:

2022-04-26 06:46:42,258 - octoprint.events - WARNING - There was an error processing one or more placeholders in the following command: curl -s -H "Content-Type: application/json" -H "X-Api-Key:blabla" -X POST -d '{ "command": "disconnect" }' http://localhost:5000/api/connection

But there are no placeholders in the curl command. Or what is meant by this?

Thanks
Sepp

octoprint-systeminfo-20220426064722.zip (10.3 KB)

I saw this recently on another post in regard to event manager and curl commands. You need to escape the '{ "command": "disconnect" }' bit somehow so that it's not seen as a replacement placeholder for string formatting I think. I'll see if I can find that post.

Here's that post...user didn't specify which fixed it, but did mention they had to restart OP.

So something like ''{{ "command": "disconnect" }}''

Hi @jneilliii

it seems to work with '{{ "command": "disconnect" }}'. Thanks a lot!!

1 Like

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