Created
October 8, 2017 20:19
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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