On/Off Navbar Button of WS281x LED Status through system command

I want to turn on LED when my printer is off and no gcode´s can be sent.
I thought i could realize this through system commands drop down. But always i try octoprint is crashing and i have to reboot th Pi4 and delte the system command again.
I can run it through ssh but not know if it is not possible to run curl through system commands or there is a failure in my setup.
The command is: curl --header "Content-Type: application/json" --header "X-Api-Key: YOURAPIKEY" --request POST --data '{"command": "toggle_lights"}' http://127.0.0.1/api/plugin/ws281x_led_status

I tried it as curl, python and bash. All of the work via ssh connection but not system command button.
I used abolute paths as well.

I'm sorry, but I'm not quite understanding what you are trying to do. If your printer is off, Octoprint won't be able to connect to it so you won't be able to start a print.

Are you trying to have the light turn on automatically or manually through one of the commands in Octoprint? Why would you need to turn on the light manually if you already know that the printer is off? A little more detail about what you are trying to accomplish would be helpful.

Hi ryan780,

Thank you for the quick response. When my print is done, my printer goes off using PSU Control. If i want to see the result i have to turn on light because it is dark in the room. I want avoid powering and connecting to printer just to turn on the light and power off again. As i know system commands are the only which work when printer is off. My Anycubic does not accept gcode´s when off.

What i already tried in config.yaml:

  1. /usr/bin/curl curl --header "Content-Type: application/json" --header "X-Api-Key: MYAPIKEY" --request POST --data '{"command": "toggle_lights"}' http://127.0.0.1/api/plugin/ws281x_led_status
  2. /usr/bin/sh /home/pi/scripts/camlight.sh and only camlight.sh

content of camlight.sh
#!/bin/sh
/usr/bin/curl --header "Content-Type: application/json" --header "X-Api-Key: MYAPIKEY" --request POST --data '{"command": "toggle_lights"}' http://127.0.0.1/api/plugin/ws281x_led_status

  1. /usr/bin/python /home/pi/scripts/camlight.py
    and /home/pi/oprint/bin/python /home/pi/scripts/camlight.py:

content of camlight.py
#!/usr/bin/env python
import rpi_ws281x as ws281x_led_status
import requests
headers = {
'Content-Type': 'application/json',
'X-Api-Key': 'MYAPIKEY',
}
data = '{"command": "toggle_lights"}'
response = requests.post('http://127.0.0.1/api/plugin/ws281x_led_status', headers=headers, data=data)

Okay...but you are trying to turn on a light that is connected to your printer or directly to your Pi? If it is connected directly to your pi, you do not have to uses CURL to turn the light on. You're using the WS281x status plugin? That plugin has the ability to add a button to the nav bar so you can turn the lights on directly, without having to use system commands.

It's listed right there on the page.

You are right. There is a button on the navbar. I use octopod on my ios device and there is no nav bar button available but system commands.

I don't understand. How is there no nav bar. You're accessing the same website from all devices. Are you using Safari or Chrome?

Octopod is a ios app and no support for navbar buttons.

Then use the web interface. What you are trying to do is unnecessarily complicated and I don't believe will work.