Controlling Wemo Light Automatically in OctoPrint

2015-10-20 in 3d Printing Wemo , OctoPrint

I use a Wemo Insight Switch to turn a lamp on and off for my prints and had been doing it manually via the Wemo app. Instead, it made a lot more sense to have this just happen automatically via OctoPrint so that I could always see what was printing and then not waste energy after the print was done. Turns out OctoPrint has a great events handler that lets you do just this as long as you can perform the action you want via shell script or gcode.

I use OctoPrint on a Raspberry Pi using OctoPi so I had to perform the following commands to install

sudo apt-get install python-setuptools python-dev
easy_install ouimeaux

If you have issues, check the Ouimeaux installation docs.

This will give you /usr/local/bin/wemo which can be used to control your lights. To see available devices:

/usr/local/bin/wemo list

Verify that you can control your switches like so:

/usr/local/bin/wemo switch "3d Printer Light" on
/usr/local/bin/wemo switch "3d Printer Light" off

You will then need to add the following to the ~/.octoprint/config.yaml file:

events:
  enabled: true
  subscriptions:
  - command: /usr/local/bin/wemo switch "3d Printer Light" on
    event: PrintStarted
    type: system
  - command: /usr/local/bin/wemo switch "3d Printer Light" off
    event: PrintDone
    type: system
  - command: /usr/local/bin/wemo switch "3d Printer Light" off
    event: PrintFailed
    type: system
  - command: /usr/local/bin/wemo switch "3d Printer Light" off
    event: PrintCancelled
    type: system

Substitute the name of your switch / light in the config above where I used ‘3d Printer Light’. Restart OctoPrint and you are good to go. While I am using a switch here and a small LED lamp, you can do this with a Wemo bulb as well without any issues.