OctoPrint-Enclosure icon indicating copy to clipboard operation
OctoPrint-Enclosure copied to clipboard

MQTT support?

Open mrwee opened this issue 7 years ago • 17 comments

Hi, This plugin looks very nice and it seems like it extends OctoPrint with many features I could use. One challenge for me, is that I prefer to use MQTT driven external devices, rather than connecting via GPIO's on Raspberry. Is it possible to modify this to use MQTT commands instead?

mrwee avatar May 15 '17 12:05 mrwee

Definitely possible to add MQTT commands, for inputs and outputs. But I don't see a lot of gain, usually you need a raspberry pi connected to your printer in order to talk to your printer. And your enclosure is also around your printer, so it makes sense to use the gpio directly and avoid sending signals over the network to come back and do something 12 inches away from your raspberry pi. The only device that is more likely to be useful would be the power for the printer it-self with a smart outlet of some sort. Also if I do implement what would you expect on the configuration? being able to set the topic and payload? or should I fix the payload with a simple API like "ON" and "OFF" for inputs and outputs. Hard coding the API would be easy to implement. Also I would rater not implement reading the temperature via MQTT, in case of the client stops receiving data from the enclosure sensor it would not be able to control the temperature. Another thing: EVENT driven MQTT events on the plugin don't make sense, because if you have MQTT devices on the network, they can already subscribe to those events and handle them accordingly. So I guess only outputs would be a real world useful enhancement.

vitormhenrique avatar May 23 '17 19:05 vitormhenrique

It would be nice to be able to control gpio via MQTT so my home automation hub can send a message to the octopi and it would turn the printer's main power on and turn off the printer and lights when the print ends.

I would also be great if it would report back the status of the temperature and the heater's gpio status to track how often the heater is on and for how long (same goes for other gpio as well). And if it sent back the filament Sensor status, the the home automation hub could send a text message to my phone telling me it is out of filament.

To implement it, I think it would be fine if you were to hard code the topics and payloads, both for the status and commands. I also think it would be best if it could use the octoprint MQTT plugin's "helpers", that way there is only one setup location for the MQTT server's info and credentials.

floppystick6 avatar Jun 13 '17 23:06 floppystick6

I'd like to second Floppy's request for MQTT, and approach of using the MQTT plugin's "helpers" for config.

Example, I have Tasmota installed on a Sonoff that controls mains to my 3d printer. Instead of wiring the temp sensor to the RPI, I wired it to the Sonoff so that I could have a more direct path to shutting down mains power in case of runaway enclosure temps, and (granted: weird edge case) the RPI is down or non-responsive.

This looks like a very handy plugin, and I'm looking forward to using it soon.

petonic avatar Mar 29 '18 18:03 petonic

I agree with petonic and floppystick6 with Mqtt add (you can implement a mosquitto on the same board) plus node-red you can open a big bunch of posibilities to an ultimate automation.

xinuxnt avatar Oct 29 '18 14:10 xinuxnt

Hi -- Related to this, I've implemented a self-contained Sonoff thermostat for an enclosure fan. Basically, the enclosure fan relay Vcc is on one output pin of the Sonoff, and the DHT22 (or whatever) is on a sensor pin of the Sonoff. You can plug in a range of temperatures for which you want the enclosure to remain within, i.e., 26 degC - 36 degC. It implements a hysteresis mechanism.

This is done using Sonoff's relatively recent "Rules" mechanism. When I'm back from my travels, I can post the code if anyone is interested...

petonic avatar Oct 29 '18 19:10 petonic

This would be a great feature to allow people running octoprint on a computer to use this plugin. That's where I am at right now. I have a PC to run two octoprints/webcams and would like to be able to use this plugin with my setup.

I was considering going through and changing all the direct hardware calls to serial calls to an arduino with the enclosure hardware hanging off. Then I would just have to build up the Arduino code to run the enclosure. If it were MQTT, I would use an ESP and half the work would be done.

Even more interesting would be if this plugin had an I/O plugin module allowing users to choose between RPI, MQTT, or serial to an arduino helper. If that were to happen, I would be happy to build out the serial protocol and arduino code.

ibishop100 avatar Dec 07 '18 23:12 ibishop100

@vitormhenrique hi. I have a question. Is there any "command" to power on/off added output's . It will be nice that with plugin https://plugins.octoprint.org/plugins/mqtt/ i will be able to turn on my printer and lights using mqtt command.

kaju666 avatar Feb 17 '19 10:02 kaju666

I don't know what do you mean by command, if the plugin can send gcode using mqtt it would be possible, other than that all the current API is documented on the wiki.

vitormhenrique avatar Feb 18 '19 21:02 vitormhenrique

I don't know what do you mean by command, if the plugin can send gcode using mqtt it would be possible, other than that all the current API is documented on the wiki.

Thanks, didn't see the API.

I made a script and instrucion for others interested: https://github.com/kaju666/OctoPrint-Enclosure-Relay-MQTT-Integration

kaju666 avatar Feb 20 '19 12:02 kaju666

Is there any progress in adding MQTT support for the input/output pins? I would like to control my lights/fans/etc from Home Assistant. Thank you!

Exit2Studios avatar Apr 08 '19 18:04 Exit2Studios

I too would like to vote for addition of MQTT support, primarily for toggle on/off ability on the configured output pins.

I am willing to help with implementation, however I am limited with experience of python so some guidence will be required if anyone can give it.

pattonwebz avatar Jul 03 '19 23:07 pattonwebz

As I am limited in experience with python I won't be easily be able to create an MQTT interface from scratch. I have found the paho-mqtt library which looks to be a common choice for adding MQTT features in python applications. @vitormhenrique would you be opposed to adding this library as a dependency in your codebase if I used it for mqtt features?

pattonwebz avatar Jul 03 '19 23:07 pattonwebz

the MQTT plugin mentioned earlier in this thread has hooks that could be used. I'l like to get sensor / state information pushed into MQTT myself, controlling the enclosure over MQTTis of less concern to me personally.

cnf avatar May 25 '20 19:05 cnf

Hi, wanted to monitor the enclosure temperature for long prints during the night and get alerts through home assistant if some threshold is hit, so I quickly edited the SI7021.py file to get all the temperature sensor values to mqtt/HA, added to file end:

#install paho mqtt lib with: pip install paho-mqtt
import paho.mqtt.publish as publish
#if u need HA auto discovery uncomment following:
#publish.single("homeassistant/sensor/enclosure_temp_%s/config" % address,
#  payload=u'{"dev_cla": "temperature", "name": "enclosure_temp_%s", "unit_of_meas": "\N{DEGREE SIGN}C", "stat_t": "octoPrint1/temperature/enclosure_temp_%s"}' % (address, address),
#  hostname="192.168.X.X",
#  client_id="octoPrint1",
#  auth={'username':"usr", 'password':"pwd"},
#  port=1883)

publish.single("octoPrint1/temperature/enclosure_temp_%s" % address,
  payload=cTemp,
  hostname="192.168.X.X",
  client_id="octoPrint1",
  auth={'username':"usr", 'password':"pwd"},
  port=1883)

this is highly unoptimal but better to have some monitoring than none while the printer is in same space as us, probably need to get some new smoke sensors inside the enclosure as well... have few around but...

fspralja avatar Dec 23 '20 08:12 fspralja

Adding the sensor to the GPIO makes sense often however there are clear advantage of an MQTT solution:

  • Xiaomi Mi temperature sensor and such can be placed anywhere very easily without any wire
  • Home Assistant (or an ESP-32 flashed with ESPHome) can read those sensors and include their values is other automation (i.e. it can be used outside of OctoPrint). Technically RPi can talk to BLE (like HA does) so OctoPi could even directly communicate with such sensors.

OctoPrint could export the enclosure temperature/humidity/... but that'd probably only work if OctoPrint natively supports enclosures as a core feature (or if the HA integration incorporated metrics exported by this plugin which seems a long stretch).

wernight avatar Jan 04 '22 13:01 wernight

+1

tnemrap avatar Jan 27 '22 21:01 tnemrap

Perhaps the addition of Sub plugins similar to the way PSU control has them might be the way to go. as not everyone will need MQTT then including the paho / other libraries by default would be unrequired. That said integration with the existing MQTT plugin https://plugins.octoprint.org/plugins/mqtt/ would be even better. Anyone with some basic octoprint plugin creation experience want to assist me with trying to put this together? send me a message. I have some Python 3 experience but 0 in relation to creating an octoprint plugin.

Also just to add my 2c the reason I would like MQTT integration is I use RF based switches all throughout my house. these are controlled using MQTT and Home Assistant and i could easily plug my printer into one of these. PSU control I can do this simply but I love the enclosure plugin and think it would be a super addition.

siparker avatar Apr 23 '22 09:04 siparker