How to add a camera to Octoprint & Home Assistant – for a smarter printer with awesome timelapses
Octoprint is a powerful software to make your 3D printer even better. To reach its full potential you have to add a camera – for awesome timelapses and even better integration with your smart home. Here is how to add a camera to Octoprint (using a Prusa Mini).
Setting up Octoprint and Home Assistant
I have shown in the past how to set up Octoprint and even how to connect it to your Home Assistant setup for the best printing experience possible. My Prusa Mini is hidden in a small cabinet to keep the temperature consistent and avoid noise. Using Octoprint I can still simply send gcode directly from the Slicer on my PC to the printer.
The Prusa Mini then starts printing showing me a live image of the print via Octoprint, creating a timelaps video of the whole print if I want it to and send a push message to my phone once the printing process is done. The lights in the room are also automatically controlled by Home Assistant so I can actually see everything via the webcam.
All these steps, setup, integration via MQTT and even the automation are described in the two articles I linked above. Whats new is the camera and the timelapse feature. Here is how to do that.
Adding a camera to your 3D printer and Octoprint
Octoprint does support many USB cameras but if you run it on a Raspberry Pi there is a simpler solution: the Raspberry Pi camera module that connects directly to a special port on the Pis via a flex cable and is relatively cheap.
You can simply buy such a camera, connect it to the Pi via the cable and you are ready to use the camera from Octoprint. After a restart your camera should now show up in Octoprint. Simply go to control tab the in the Octoprint UI and after a moment of loading you should now see the image of your camera.
The remaining problem is how to mount the camera properly. It is possible to mount it to some external mount like the wall but I want it to track the progress of my print and make nice timelapse videos too. To do that I am looking to mount it on the Y axes of my Prusa Mini that moves up with the printhead.
After some research I found this great mount made for the Prusa Mini. It slips onto the motor and secures itself using only clamping force. No screws required. Even the two halves of the camera case do fit together automatically without screws.
The camera module fits inside the top part and you only have to be careful to properly maneuver the flex cable out of the case and towards the Pi Zero without interrupting the motion of the printer.
Adding the camera to Home Assistant
The same camera can of course also be added to Home Assistant as the Octoprint interface does only show a web stream. By default you should be able to find the stream at
http://ipOfOctoprint/webcam/?action=stream and a snapshot at
To add the camera to Home Assistant just go to Integrations, click the add integration button and find the
MJPEG IP Camera integration. Add a new one and provide the two URLs from above for the video stream and the still image, used to display a preview of the camera on the dashboard, in the dialog. By default no username or password are needed, your camera stream from Octoprint is unsecure by default!
Now you should be able to see the camera on your dashboard within Home Assistant. It will usually only show a snapshot image updated every couple of seconds but a click on the preview should show you the live image.
I did also add a couple of rules to my Home Assistant setup to automatically turn on the light while printing so that I can see a proper image on the dashboard. It uses a simple rule like this with Octoprint connected to Home Assistant via MQTT.
alias: Turn on light when a 3D print starts description: "" trigger: - type: turned_on platform: device device_id: someid entity_id: binary_sensor.octoprint_printing_2 domain: binary_sensor condition:  action: - service: light.turn_on target: device_id: someotherid data: rgbww_color: 0,0,0,0,255 brightness: 40 mode: single
After the print is done Home Assistant will send a notification, including a picture from the camera, to me, keep the light on for 10 minutes for me to remove the print and then turn it off. A simple but really useful automation. Especially with my new smart watch its pretty cool to get these push message to remind me to remove the print.
alias: Alert print done & light description: Send a push notification & alert when a 3D print is done trigger: - type: turned_off platform: device device_id: someid entity_id: binary_sensor.octoprint_printing_2 domain: binary_sensor condition:  action: - service: notify.notify data: message: A 3D print on the Prusa Mini is ready title: 3D print done data: image: http://192.168.2.142/webcam/?action=snapshot - service: notify.pushover data: message: A 3D print on the Prusa Mini is done title: 3D print done - type: turn_on device_id: someotherid entity_id: light.led_controller_3dprinter_level_light_color_on_off domain: light brightness_pct: 15 - delay: hours: 0 minutes: 10 seconds: 0 milliseconds: 0 - type: turn_off device_id: someotherid entity_id: light.led_controller_3dprinter_level_light_color_on_off domain: light mode: single
Creating timelapses with Octoprint
Now the printer works great: I can slice a model on my PC, send the result to Octoprint to print and even get notifications and a live image from the printer with this camera. The icing on the cake is the possibility to create nice looking timelapses of the prints though.
These short videos show the print “magically” growing layer by layer without including the printhead. This is done by a plugin called Octolapse which moves the printhead to a set position after each layer, takes a picture and then moves on. This way on the pictures the head is always in the same position (only moves up).
The Octolapse plugin can be installed the same way every other plugin go to settings and plugin manager and search for the name. Then click install. You should now see a new tab called timelapse in the main window. Use this to pick the printer settings, camera and output video format and you should be ready to go.
Next time you print something it might take a bit longer but you will see a timelapse like this. If you run into any issues with your print though consider disabling this feature. The additional movement of the print head might introduce small errors in the model.
Bonus: how to get better remaining time estimations
Do you know this annoying problem where your slicer software is telling you pretty much exactly how long the print will take but Octoprint shows wildly different times? The problem is that Octoprint is usually just guessing based on how many gcode commands are left.
With another plugin called SlicerEstimator you can teach Octoprint how to use the more precise estimations from your slicer. Most, like PrusaSlicer and Cura already write this data into the gcode and if you simply install this plugin Octoprint will know how to read and display it. Very nice!