Skip to content

Instantly share code, notes, and snippets.

@thinkl33t
Created October 8, 2017 20:19
Show Gist options
  • Save thinkl33t/a6a957c1a58dd80a4398be6292da191d to your computer and use it in GitHub Desktop.
Save thinkl33t/a6a957c1a58dd80a4398be6292da191d to your computer and use it in GitHub Desktop.
Plugin for turning off a light via MQTT when the printer starts / finishes printing - depends on the MQTT plugin
import octoprint.plugin
class MqttLightsPlugin(octoprint.plugin.StartupPlugin, octoprint.plugin.EventHandlerPlugin):
def __init__(self):
self.mqtt_publish = lambda *args, **kwargs: None
def on_after_startup(self):
helpers = self._plugin_manager.get_helpers("mqtt", "mqtt_publish")
if helpers:
if "mqtt_publish" in helpers:
self.mqtt_publish = helpers["mqtt_publish"]
def on_event(self, event, payload):
if event == 'PrintStarted':
self.mqtt_publish("homie/printerlight/switch/on/set", "true")
if event in ['PrintFailed', 'PrintDone', 'PrintCancelled']:
self.mqtt_publish("homie/printerlight/switch/on/set", "false")
__plugin_implementations__ = [MqttLightsPlugin()]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment