Help with config.yaml -> event subscription

It seems like OctoPrint is recognizing that I've added two subscriptions to the config.yaml file and it's generically logging that a system command was executed. Since I've got this python script logging each call, it doesn't look like that attempt was successful.

What's the basic setup for invoking a Python script as an event?

  • I created a script in ~/scripts
  • I did a chmod 666 of the script followed by a chmod a+x of same
  • Both script and log file are in the same folder and owned by pi. I did a chmod 666 of the log file.
  • Running the python script manually at the command line works
  • I'm not running user management in OctoPrint's setup wizard, just the standard pi user
  • I used the documentation for Events as my guide

What am I missing here?

How did you actually configure it? Could be something as simple as unexpanded paths.

The example for events suggests that the security context is running under the pi user.

config.yaml

events:
  enabled: true
  subscriptions:
  - event: ZChange
    command: python ~/scripts/logistics.py ZChange {__currentZ} {__progress}
    type: system
    enabled: true
  - event: MetadataAnalysisFinished
    command: python ~/scripts/logistics.py MetadataAnalysisFinished {result}
    type: system
    enabled: true

~/scripts/logistics.py

from datetime import datetime
import sys
import time

f = open('/home/pi/scripts/logistics.log', 'a')
try:
       	msgPrint = datetime.now().strftime('%m/%d/%Y %H:%M')
	f.write(msgPrint + '\n')
finally:
	f.close()

It now works

I deleted a bunch of things out of it and it now works this morning. It must have been silently failing due to some sort of Python-related bug. (I'm trying to generate a PNG file on ZChange, btw.)