Enclosure Temperature / Fan / Light Control / Filament - Octoprint Plugin

Hello Guys,

For the last week I’ve been working on a plugin for octoprint to control my enclosure.

My goal is to control a light, fans and a small heater inside the enclosure over the internet using octoprint.

I just finished the first version of the plugin.

You can find it on my github page.

Basically I use the raspberry pi GPIO to control relays and turn on / off whatever I want on my enclosure. There is plenty information on the plugin page on github. For now the plugin only works on raspberry pi.

The heater should turn off when the print is complete. The lights are specially good when you want to check your print while you are not home over the internet.

I’m using a DHT22 sensor to measure temperature and humidity inside the enclosure, a small lasko heater and a usb fan.

Few print-screens and pictures:

Nice! That’s is great addition to octoprint!

I just figured it out a way to improve the GPIO handling without needing a root user… It will avoid possible issues.

I’ll implement / test tonight and update the plugin.

Plugin updated, now i’m using wiringPi to access GPIO. So I don’t need to access GPIO pins using sudo command.

Tested the heat stabilization yesterday and could keep my enclosure on a nice 40 C. It took 10 minutes to get to the temperature.

I just got OctoPrint running my Taz 5 remotely and am interested in building a similar enclosure with temperature & humidity control. I’m curious, how necessary is the additional heater? Have you found an optimum enclosure temp that is higher than what the heated build plate and nozzle put out?

If you build a enclosure, setting the hot bed to 110C and the hot end to 240C will only heat your enclosure to about 30C, due to thermal losses, etc…

With a heater and controlling the temperature, I can easily keep the internal temperature to 50C, this help a lot when printing LARGE ABS prints, where warping would be an issue, if you want to only print small ABS or PLA you don’t need a enclosure.

Another thing to consider is that heating the environment can also make it harder to print PLA, that is why I also added a fan to my enclosure, to keep the temperature as low as possible to print PLA.

Good afternoon,

Thank you for posting this code. I am running OctoPi, and was looking for a way to control a fan on an enclosure I am currently building.

I see in you pics that you have a target temperature setting… does it control both the fan and heater, or just the heater?


It only controls the heater, there is no need to turn the fan to decrease the temperature, there are plenty of heat losses on enclosure that will make the temperature drop really quick once the heater element is off inside the enclosure. Just turning off the heater makes the temperature control very stable.

I only use the FAN to print PLA, and with the enclosure open, to cool the enclosure as I have really bad experience printing PLA on a heated chamber, I get heat creep avery single time.

You can also use the fan as a exhaust fan to remove fumes from your enclosure, but I would add a filter on the exhaust fan If you do that.

I’m about to update the code and add second fan support, because it was requested on github by a few people. I’ve keeping my enclosure at 55 C when printing large ABS prints and no warping what so ever!

Check github page for more info.

I updated the code,

Now the plugin has the ability to pause the printer using a filament sensor, it can control up to 4 different I/Os with configurable names.

You can configure if the I/O should automatically shut off after printing is done.

for example, you can add a solid state relay and turn the entire print off after 30 minutes or so that your print is complete.


First would like to say thank you for you great work, this plugin is exactly what I need.

I would have some suggestion.
It would be great if we can choose to power on some I/O when print starts if that would be possible. ( I always forgot to turn on LED lights :blush: )
And it would be nice to have on off button on some more easier accessible place, in a system menu for example.

Well that would be nice to have but even now is a great plugin.

I’m going to implement this… I like the idea…

I don’t understand this one, as it already has on/ off buttons under the enclosure plugin tab…


Sorry for late reply, was away for some time…

I don’t understand this one, as it already has on/ off buttons under the enclosure plugin tab…

What I mean is that I have this button to show extra tabs and I dont like it.

And I see in some other plugin, buttons for on/off in the system tab under restart option.
Well that is really not so important, I just ask if it is possible to have on/off buttons somewhere easly accessible.

Hello. I have a raspberry pi 2 with octoprint image installed. Then I did the steps to install python as the previous post says Then I connect my DHT22 to the raspberry but it does works. only shows 0 in the octoprint.

This is my Sensor:

I put:
GND to PIN 6
VCC to PIN 4
DAT to PIN 7

Is it correct?

There are many steps to trouble shoot this issue.

If you did install the adafruit library (as required per instructions on the github page), you can check if your connection is ok.

Follow the instructions on adafruit and test your wiring: https://learn.adafruit.com/dht-humidity-sensing-on-raspberry-pi-with-gdocs-logging/software-install-updated

if your wiring is ok, next step, ssh into your raspberry pi, stop octoprint using:

sudo service octoprint stop

start octopring manually using


take a look on the log, and look for anything that has to do with the enclosure, they will be logged with something like:

octoprint.plugins.enclosure - INFO - Failed to read Humidity

I don’t like including buttons on the shutdown menu. It is possible to inject the html any part of the octoprint, I’ll test putting it on the control tab.

I have this notification:

sudo: /home/pi/.octoprint/plugins/OctoPrint-Enclosure/extras/GetTemperature.py: command not found
2017-02-01 14:44:35,738 - octoprint.plugins.enclosure - INFO - Failed to convert to float
sudo: /home/pi/.octoprint/plugins/OctoPrint-Enclosure/extras/GetHumidity.py: command not found
2017-02-01 14:44:35,808 - octoprint.plugins.enclosure - INFO - Failed to convert to float
2017-02-01 14:44:35,810 - octoprint.plugins.enclosure - INFO - Turning heater off.

Doing test with Adafruit links shows that:

pi@octopi:~/Adafruit_Python_DHT/examples $ sudo ./AdafruitDHT.py 2302 4
Failed to get reading. Try again!

You have two issues…

You should first the the adafruit code working, it that does not work, the enclosure will never display the temperature, try to use 22 and 11 for the parameters, test multiple times, until you get a reading, by the way I just noticed that you are using 5V on the VCC of the sensor, it should be 3.3V to use on a 3.3 device, you can fry your raspberry pi using 5V.

pi@octopi:~/Adafruit_Python_DHT/examples $ sudo ./AdafruitDHT.py 22 4

pi@octopi:~/Adafruit_Python_DHT/examples $ sudo ./AdafruitDHT.py 11 4

After you get this working you can work on the second issue, you are getting.

sudo: /home/pi/.octoprint/plugins/OctoPrint-Enclosure/extras/GetTemperature.py: command not found

That means that you either:

  • Did not download the scripts to the proper folder
  • Did not gave the scripts permission the execute
  • Some other weird Linux permission issue

This is my connection:

GND to PIN 6 (white)
VCC to PIN 4 (red)
DAT to PIN 7 (green)

The dht22 module needs to work in 5v. I have other and with Arduino it works with 5v, so this is the way I connect to 5v to Raspberry.

Now I try again and I need to do

pi@octopi:~ $ cd Adafruit_Python_DHT


pi@octopi:~/Adafruit_Python_DHT $ sudo python setup.py install

I finally I obtained:

Installed /usr/local/lib/python2.7/dist-packages/Adafruit_DHT-1.3.1-py2.7-linux-armv7l.egg
Processing dependencies for Adafruit-DHT==1.3.1
Finished processing dependencies for Adafruit-DHT==1.3.1
pi@octopi:~/Adafruit_Python_DHT $ cd examples
pi@octopi:~/Adafruit_Python_DHT/examples $ sudo ./AdafruitDHT.py 2302 4
Temp=22.3*  Humidity=67.8%

OK. Now it works… FINE!!!

I need to enter in terminal this lines one by one.

mkdir -p ~/.octoprint/plugins/OctoPrint-Enclosure/extras/
cd ~/.octoprint/plugins/OctoPrint-Enclosure/extras/
wget https://raw.githubusercontent.com/vitormhenrique/OctoPrint-Enclosure/master/extras/GetHumidity.py
wget https://raw.githubusercontent.com/vitormhenrique/OctoPrint-Enclosure/master/extras/GetTemperature.py
chmod +x ~/.octoprint/plugins/OctoPrint-Enclosure/extras/GetTemperature.py
chmod +x ~/.octoprint/plugins/OctoPrint-Enclosure/extras/GetHumidity.py

dht22 works fine with 3.3V.

You still need to fix the second issue, because you are getting the

sudo: /home/pi/.octoprint/plugins/OctoPrint-Enclosure/extras/GetTemperature.py: command not found

  • That means that you either:
  • Did not download the scripts to the proper folder
  • Did not gave the scripts permission the execute
  • Some other weird Linux permission issue

OK, but I connected to 5v and works fine. RBP gives 5v too. I don´t know what is better.

I did it again and NOW IT WORKS! Thanks a lot for your work!

Now I can buy leds and turn it ON or OFF with this plugin.

It only need other way more friendly.