Webcam activates LEDs?

That´s great! Maybe if I have enough spare time I consider adding RGB lights to my printer.

Hey there Guys,

you inspired me to take a look into this topic and found a solution by utilizing the way octoprint detects if the mjpg_stream is viewed.

Check out this thread if someone is still interested:

Hey, just a complete noob here, but I am having trouble following how this was solved. I just want to hook up a couple of LEDs. Could someone give me clear instructions as to which files need to be edited to make the gpio pins activate?


Hey @Tiefling! What type of LEDs do you have?

If you are using WS281x/SK6812 type LEDs and my plugin OctoPrint-WS281x_LED_Status, you can take a look at the wiki in the repo (linked), which has some guides for LED setup.

I have a few cree 5mm LEDs that I was going to connect via the pins and mount to a camera holder. Can this be done with your plugin?


If my googling is correct, no unfortunately.

They seem to be standard single-colour LEDs, which would not be controllable - my plugin targets the WS281x space, which has individually controllable LEDs, also known as NeoPixels. This thread was also talking about RGB Leds too.

You may be able to get LEDStripControl to work, but to my knowledge there is no plugin for just turning on/off standard LEDs - your best bet would be a custom script accessed from the system command menu if that's what you're aiming for.

Yeah I am upgrading to a ring of 12 NeoPixels, this should work well with your plugin I think. I will be using a separate power source then running the NeoPixels from GPIO 18.

If you want to use OctoPrint, run them from Pin 10. Described in the plugins' docs, as you can't use PWM on pin 18 without running as root.

Hey @Charlie_Powell, I have installed your plugin, thanks for that. I have run into some issues though. The LED closest to the Vin port is always on, and I am unsure how to solve this. Also once this is fixed will I be able to turn the light on and off on command, while viewing through a camera? Just for clarification this is the neopixel model I am using:


:wave: @Tiefling!

Someone else reported an issue with the first LED, and it turned out to be their level shifter.

You could give that a go, or if not maybe it is an issue with that individual LED.

The on and off command is not implemented automatically when switching to the camera tab, but there are buttons in the navbar that you can use to turn them on and off.

Automatically turning it on is something on my list but it's not going to get looked at all that soon.

This drifted off from the origial question "How to switch on when stream/shot is watched?" to how to control raspi GPIOs. Sadly.

The original question is way more unique and also unsolved.
@supertaz came up with good ideas, but well, still no solution.

I myself tried to modufy ustreamer for this purpose.
While it works, the author of ustreamer pointed out that the http-forward solution is the cleaner solution.

If anyone has the skills, please help me:

I've made a little script based on a tutorial I found:
Sennevds/flask-video-streaming: Supporting code for my article on video streaming with Flask. (
This triggers a GPIO pin when someone access the stream and when there's no activity anymore and deactivate the pin.

This is first time I used flask so I don't know if this code is good but it works for me

Great work!
I like how it turns the whole streaming off when no one is watching!
It is pretty delayed though. I will try the other cameras (only tried CAMERA=pi)

PS: Len on snapshot is not implemented. You need to add:

PPS: Way better with v4l2. But heavy load on pi4.
I think it octopi will manage though:
FYI: I needed to build from source, could not install the packages.

PPPS: Reducing resolution to 640x480 drops load to ~50%. You can also reduce fps for more performance. It also seems more responsive than octopi default mjpg-streamer. Great!

Yeah I disabled it on snapshot because I use the snapshot url in Home Assistant and the light would constantly turn on.
I've fixed this by disabling this in the script and in Octolapse I added 2 scripts to turn on the light just before taking a snapshot.

Is there an easy way to turn on the led while watching from the camera with Octoprint? I read it, but I didn't understand it.

@mryusufcan I improved this project a little bit:

It now has some documentation.
(Also renamed for this specific purpose)
If you have any questions or issues, please file a github issue.

1 Like

thank you, but I don't understand the codes.I can't.