cmroche / OctoPrint-HomeAssistant

Home Assistant plugin for OctoPrint, enabling MQTT discovery of you device and sensors
112 stars 18 forks source link

Send more commands to OctoPrint? #63

Closed garyt72 closed 2 years ago

garyt72 commented 3 years ago

Thanks so very much for this - I've really enjoyed using it and it has made OctoPrint even better with the fast responsive integration with HomeAssistant.

Is it possible to implement the capability to send more commands to OctoPrint - this specific request is to simulate the "Connect" button. My use case is that I want to leave OctoPrint running all of the time, but turn off the printer off when not in use. The issue is that OctoPrint goes to an error state and stops trying to reconnect after a while.

The idea is that I turn on the printer, wait 10-15 seconds, then tell OctoPrint to connect.

cmroche commented 3 years ago

I'd like to see this implemented as a switch for connect/disconnect I think, but sure I think it make sense.

willpuckett commented 3 years ago

I think you could add an api request to your configuration.yaml as a shell command, something like:

# Exposes service shell_command.printer_connect
shell_command:
  printer_connect: curl -v http://<printerIP>/api/connection -d '{"command":"connect"}' -H 'Content-Type: application/json' -H 'X-Api-Key: !secret octoprint_api'

Or, with the API directly in the file and not using the secret file:

# Exposes service shell_command.printer_connect
shell_command:
  printer_connect: curl -v http://<printerIP>/api/connection -d '{"command":"connect"}' -H 'Content-Type: application/json' -H 'X-Api-Key: <YOUR-API-KEY>'

And then just pull the shell command into a button on your Lovelace dashboard somewhere...

Cheers!

cmroche commented 2 years ago

Issue was resolved on #62