Running Python script on print start/end

I'm trying to run a python script on print start/end to control LED light.
It used to work before with older octoprint version. Now starting everything from scratch using OctoPrint Version 1.4.2.

I tried this config, but it didn't work:

events:
enabled: true
subscriptions:
- command: sudo python3 /home/pi/led_control.py --off
enabled: true
event: Disconnected
type: system
- command: sudo python3 /home/pi/led_control.py --on
enabled: true
event: PrintStarted
type: system
- command: sudo python3 /home/pi/led_control.py --off
enabled: true
event: PrintDone
type: system
- command: sudo python3 /home/pi/led_control.py --off
enabled: true
event: PrintCancelled
type: system

Would appreciate any help here.

Do you have to enter the users password when you run this command in ssh?

1 Like

BTW: OctoPrint-Enclosure can do this

Yes, this is a "sudo" command, need to provide password in a terminal. It somehow used to work before my SD card got corrupted.

In that case, you will need to disable this behaviour. The command you will be looking for is visudo iirc. You might have to search what the formatting of the sudoers file is to allow your user to do this.

On your old install you probably did this, since OctoPrint has never been able to send in root passwords from the web UI.

Edit: this may be what you are looking for: https://timonweb.com/devops/how-to-enable-passwordless-sudo-for-a-specific-user-in-linux/

I'll give it a try. thanks.

1 Like

That's definitely possible. It was 2 years back... I was too lazy to backup the SD card.
I'll try the Enclosure plugin first, and then this option.

1 Like