Control WS2812 LED's via Octoprint MQTT Events

Mitch Roote 9a758be366 Add breathing animation 1 year ago
.gitignore bc045675ca Initial commit 1 year ago
README.md f989a96291 Fix single animation run 1 year ago
animations.py 9a758be366 Add breathing animation 1 year ago
led_control.py 9a758be366 Add breathing animation 1 year ago
led_control.service 1fedcb3929 Add systemd service file 1 year ago

README.md

Octoprint-LED-Control

Control WS2812 LED's via Octoprint MQTT Events

Using the MQTT plugin for Octoprint this script will respond to event messages and change attached LED's using the desired animation.

Useful for lighting the build surface and reacting to print events such as heating or print completed.

Dependencies

External Dependencies

  • MQTT Broker running, either on the Octopi server or elsewhere.
  • MQTT Plugin installed through OctoPrint and configured to connect to the MQTT broker.

Setup

  1. Use git to clone the script, I use the ~/.octoprint/scripts directory in the octopi user's home dir.
  2. Change any configuration options in the led_control.py file to reflect your LED strip.
  3. Add systemd service file to /etc/systemd/user/
  4. Enable systemd service with systemctl enable --user led_control.service
  5. Start service with systemctl start led_control.service

Usage

The script can be run with two modes, daemon and single run. Single run is useful for testing animations while daemon mode will listen to thq MQTT bus and respond to messages.

To run a single run animation:

$ ./led_control.py --animation color_wipe --color 255 255 255

To launch the daemon mode:

$ ./led_control.py --daemon

Help text is available with all options for each mode with the --help flag.

$ ./led_control.py --help
usage: led_control.py [-h] [--daemon [DAEMON]] [--host HOST] [--port PORT]
                      [--user USER] [-p PASSWORD]
                      [--animation {rainbow_cycle,rainbow,theater_chase_rainbow,theaterchase,color_wipe,bounce}]
                      [--color RGB RGB RGB] [--color2 RGB RGB RGB]
                      [--wait-ms WAIT_MS] [--interval INTERVAL]

optional arguments:
  -h, --help            show this help message and exit
  --daemon [DAEMON]     Start LED Control Daemon.
  --host HOST           Hostname or IP Address for MQTT broker.
  --port PORT           Port for MQTT broker.
  --user USER           User for MQTT broker.
  -p PASSWORD, --password PASSWORD
                        Password for MQTT broker.
  --animation {rainbow_cycle,rainbow,theater_chase_rainbow,theaterchase,color_wipe,bounce}
                        Run a single animation and exit.
  --color RGB RGB RGB
  --color2 RGB RGB RGB
  --wait-ms WAIT_MS
  --interval INTERVAL