Error on event command

Hi everyone
I'm trying to issue a command when octoprint is connecting to the printer
My config.yaml looks like this:

  - command: 'curl -X POST -H "Authorization: Bearer TOKEN"
      -H "Content-Type: application/json" -d ''{"entity_id": "switch.shelly_prise_2"}''
    debug: true
    enabled: true
    event: Connecting
    type: system

the command works in the terminal, it is issued when connecting however I have the following error message: - WARNING - There was an error processing one or more placeholders in the following command: curl -X POST -H "Authorization: Bearer TOKEN" -H "Content-Type: application/json" -d '{"entity_id" : "switch.shelly_prise_2"}' http://hass.casita:8123/api/services/switch/turn_on
I tried to put the command line in a script but the issue is the same, it works in the terminal but octoprint launches an error...

Any idea of what I am doing wrong? Thanks!

This one is tricky. You probably need to escape the { somehow because I believe the events will try to do parameter replacement on the command being run and those are being seen as parameters being passed. Just not sure how to escape it.

Try doubling them up to escape them:

''{{"entity_id": "switch.shelly_prise_2"}}''

first, thanks to both of you for pinpointing the issue
@Charlie_Powell I just tried, I still have the error...

sorry, I forgot to restart Octoprint after the change, it seems to work now!
however, the issue I am facing now is that the script is designed to turn on the smart plug on which the printer is connected, but the connection times out before the printer is actually up and running!

I have to check if there is a way to add a few seconds of delay in the connection might be able to increase the timeouts in OctoPrint's settings or potentially issue the connect command again via API. All of this would be handled for you if using the PSU Control plugin in combination with the Shelly sub-plugin.

Why am I reinventing the wheel you might be wondering?
Because I didn't know it was already invented!
Yes it seems easier to use that plugin plus I see there is a home assistant sub plugin, even better!

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