3D Printer Status from Octoprint via MQTT

running the latest openhabian and updated to the latest octoprint by clean install and restore backup.I cant make octoprint mqtt to talk to openhab anymore.My settings (things ,items etc) are all the same but i get “disconnected” on octoprint/mqtt topic.Any ideas?Of course all my other mqtt items ,other than octoprint ,they run ok.

Have you checked the “octoprint” vs “octoPrint” (capital P) in the stateTopic? It has changed in octoprint mqtt plugin.

yeap checked , my main topic is

octoprint/

the same as in my octoprint mqtt plugin.

Did you try to use a tool like mqtt.fx and see if the mqtt messages are actually arriving at the broker?

using mqtt.fx and subscribe to topics like “octoprint/temperature/bed” or “octoprint/mqtt” i get only the last retained value,so i thing the problem is at octoprint side…

You can use a # to see all messages on the broker. If there is nothing from octoprint, then check the connection between octoprint and broker!

found it ! i disabled Plugin blacklist processing feature at octoprint + checked the “Clean session” option at mqtt plugin,restarted and mqtt started working…

1 Like

Could you be so kind and share your things file for the MQTT settings?
Are you using the embedded MQTT broker?

Hy,

I added a HABPanel like Octodash and expanded the MQTT thing and items.

How can I create a Template from them?
What ist the best technic for Responsive Design?

the following is required for the panel:

Octodash: https://github.com/UnchartedBull/OctoDash
OctoPrint-MQTT: https://github.com/OctoPrint/OctoPrint-MQTT/blob/master/README.md

Things

Thing mqtt:topic:octoprint "octoprint" (mqtt:broker:psmqtt) @ "3D PRINTER" {
  Channels:
    Type string : connected "Connected" [ stateTopic="octoPrint/mqtt" ]
    Type string : state "State" [ stateTopic="octoPrint/event/PrinterStateChanged", transformationPattern="JSONPATH:$.state_string" ]
    Type string : event "Event" [ stateTopic="octoPrint/event/+", transformationPattern="JSONPATH:$._event" ]
    Type string : filename "Filename" [ stateTopic="octoPrint/progress/printing", transformationPattern="JSONPATH:$.printer_data.job.file.name" ]
    Type number : progress "Progress" [ stateTopic="octoPrint/progress/printing", transformationPattern="JSONPATH:$.printer_data.progress.completion" ]
    Type number : printTime "Time Printed" [ stateTopic="octoPrint/progress/printing", transformationPattern="JSONPATH:$.printer_data.progress.printTime" ]
    Type number : printTimeLeft "Time Left" [ stateTopic="octoPrint/progress/printing", transformationPattern="JSONPATH:$.printer_data.progress.printTimeLeft" ]
    Type number : temperature_bed_actual "Temperature Bed Actual" [ stateTopic="octoPrint/temperature/bed", transformationPattern="JSONPATH:$.actual" ]
    Type number : temperature_bed_target "Temperature Bed Target" [ stateTopic="octoPrint/temperature/bed", transformationPattern="JSONPATH:$.target" ]
    Type number : temperature_hotend_actual "Temperature Hotend Actual" [ stateTopic="octoPrint/temperature/tool0", transformationPattern="JSONPATH:$.actual" ]
    Type number : temperature_hotend_target "Temperature Hotend Target" [ stateTopic="octoPrint/temperature/tool0", transformationPattern="JSONPATH:$.target" ]
    Type number : filvolume "Filament Volumen" [ stateTopic="octoPrint/progress/printing", transformationPattern="JSONPATH:$.printer_data.job.filament.*.volume" ]
    Type number : fillength "Filament Length" [ stateTopic="octoPrint/progress/printing", transformationPattern="JSONPATH:$.printer_data.job.filament.*.length" ]
    Type string : fanspeed "Fanspeed" [ stateTopic="octoPrint/event/DisplayLayerProgress_progressChanged", transformationPattern="JSONPATH:$.fanspeed" ]
    Type number : currentLayer "Current Layer" [ stateTopic="octoPrint/event/DisplayLayerProgress_progressChanged", transformationPattern="JSONPATH:$.currentLayer" ]
    Type number : totalLayer "Total Layer" [ stateTopic="octoPrint/event/DisplayLayerProgress_progressChanged", transformationPattern="JSONPATH:$.totalLayer" ]}

Items

Group gOctoprint "octoprint" (gAll)
    // MQTT
    String OctoprintConnected                           "Connected [%s]"                                <network>       (gOctoprint)    {channel="mqtt:topic:octoprint:connected"} 
    String OctoprintState	                            "State [%s]"                                    <office>        (gOctoprint)	{channel="mqtt:topic:octoprint:state"}
    String OctoprintEvent   	                        "Event [%s]"                                    <office>        (gOctoprint)	{channel="mqtt:topic:octoprint:event"}
    String OctoprintJobFileName	                        "Filename [%.26s ...]"                          <office>        (gOctoprint)	{channel="mqtt:topic:octoprint:filename"}
    Number:Dimensionless OctoprintJobProgressCompletion	"Completion [%.0f %%]"                          <battery>       (gOctoprint)	{channel="mqtt:topic:octoprint:progress"}
    Number OctoprintPrintTime                           "Time Printed [%.0f s]"                         <time>          (gOctoprint)	{channel="mqtt:topic:octoprint:printTime"}
    String OctoprintPrintTimeString                     "Time Printed [%s]"                             <time>          (gOctoprint)
    Number OctoprintPrintTimeLeft                       "Time Left [%.0f s]"                            <time>          (gOctoprint)	{channel="mqtt:topic:octoprint:printTimeLeft"}
    String OctoprintPrintTimeLeftString                 "Time Left [%s]"                                <time>          (gOctoprint)
    String OctoprintPrintETAString                      "ETA [%s]"                                      <time>	        (gOctoprint)
    DateTime OctoprintPrintETADateTime                  "ETA [%1$tA, %1$td.%1$tm.%1$tY %1$tH:%1$tM]"    <time>          (gOctoprint)
    Number:Temperature OctoprintPrinterHotEndTemp		"Nozzle temp [%.1f °C]"                         <temperature>   (gOctoprint)	{channel="mqtt:topic:octoprint:temperature_hotend_actual"}
    Number:Temperature OctoprintPrinterHotEndTempTarget	"Nozzle target [%.1f °C]"                       <temperature>	(gOctoprint)	{channel="mqtt:topic:octoprint:temperature_hotend_target"}
    Number:Temperature OctoprintPrinterBedTemp			"Bed temp [%.1f °C]"                            <temperature>	(gOctoprint)	{channel="mqtt:topic:octoprint:temperature_bed_actual"}
    Number:Temperature OctoprintPrinterBedTempTarget	"Bed target [%.1f °C]"                          <temperature>	(gOctoprint)	{channel="mqtt:topic:octoprint:temperature_bed_target"}
    Number OctoprintFilVolume	                        "Filament Volume [%.2f]"                                        (gOctoprint)	{channel="mqtt:topic:octoprint:filvolume"}
    Number OctoprintFilLength 	                        "Filament Length [%.2f]"                                        (gOctoprint)	{channel="mqtt:topic:octoprint:fillenght"}
    Switch OctoprintPower                               "Power"                                                         (gOctoprint)    {channel="mqtt:topic:sonoff-plug-1:power"}
    Switch OctoprintShutdownAfterPrint                  "Turn Off after Print"                                          (gOctoprint)
    Number OctoprintPrintTime                           "Time Printed [%.0f s]"                         <time>          (gOctoprint)	{channel="mqtt:topic:octoprint:printTime"}
    Number OctoprintFilVolume	                        "Filament Volume [%.2f]"                                        (gOctoprint)	{channel="mqtt:topic:octoprint:filvolume"}
    Number OctoprintFilLength 	                        "Filament Length [%.2f]"                                        (gOctoprint)	{channel="mqtt:topic:octoprint:fillenght"}
    String OctoprintFanspeed	                        "Fanspeeed [%s]"		                        <office>        (gOctoprint)	{channel="mqtt:topic:octoprint:fanspeed"}
    Number OctoprintTotalLayer                          "Layer total [%.2f]"                            <flowpipe>      (gOctoprint)    {channel="mqtt:topic:octoprint:totalLayer"}
    Number OctoprintCurrentLayer                        "Layer current [%.2f]"                          <flowpipe>      (gOctoprint)    {channel="mqtt:topic:octoprint:currentLayer"}

Here it the VIEW in Classic UI

Octodash on Raspberry HyperPixel 4.0 https://www.thingiverse.com/make:727128

3 Likes

@Boby did you ever find a solution to this?

fyi: There is an older issue for this feature request.

Someone mentioned octoprint/event/PrintPaused.
But I don’t know if this helps.

Here’s my rule which works fine so far. Can’t distinguish between pause of print or end of print, but that’s okay for me…

rule "Send notification print pause"
when
    Time cron "0 0/3 * * * ?"
then
    if (OctoprintPrinterHotEndTemp.state < 100.0 | " °C" && 
        OctoprintPrinterBedTemp.state >= 50.0 | " °C" &&
        OctoprintJobProgressCompletion.state > 0 | " %")
    { 
        sendBroadcastNotification("[ACHTUNG]: Der aktuelle 3D-Druck ist pausiert oder beendet. Bitte nach dem Drucker sehen!")
    } else {
        if (OctoprintState.state != "Operational")
        {
            logInfo("Druckerinfo", "[INFO]: Aktueller Druckerstatus: " + OctoprintState.state)
        }
    }
end

@christoph_wempe:
Unfortunately this only works if your Octoprint causes the pause, e.g. when using a filament runout sensor connected to you Octoprint-RPI. When the printer firmware pauses a print, only a combination of temerpature and printing state could tell the printer isn’t printing (see my last post)

Prusa mini with firmware 4.1.0 sends pauses to octoprint as well so yeah a pause is good enuff in leu of an m600 trigger

Can anyone help with defining a switch thing to toggle based on octoprint/event/PrintPaused topic?

The shutdown was not working for me, so i had to adapt the whole part of the rule to the follwing:

rule "Shutdown after finish"
when
	Item OctoprintState changed from Finishing to Operational
then
		if (OctoprintState.state == "Operational" && OctoprintJobProgressCompletion.state.toString == "100.0"){
			createTimer(now.plusSeconds(600),  [ | // wait 10 minutes, so that the Hot-End has enough time to cool down, so that you don't get a heat creap into the Cold-End.
				Steckdose3DDrucker_Switch.sendCommand(OFF) // i used here my own item, no need for a double entry
			])
			createTimer(now.plusSeconds(610),  [ |
				OctoprintShutdownAfterPrint.sendCommand(OFF) // This command could be used to decide in a later version if you want to "disable" the shutdown, but this is not yet implemented in the rule!
			])
			createTimer(now.plusSeconds(595),  [ | // 5 seconds before the printer is turned off, send a telegram message to my bot.
				sendTelegram("bot1", "Turn 3D-Printer off")
			])
			logInfo("Testing" ,"Octoprint switch off!")
		}
end

So maybe i did help someone who also struggles with the mqtt octoprint and autoshutdown of the printer.

1 Like

Hello,
i have a problem with the eta calculation. In the objects OctoprintJobPrintETAString and
OctoprintJobPrintETADateTime only the value NULL is displayed. What can that be?

For OH3, the handling of time in rules has changed.

Try this:

rule "Time Printed String"

when
    Item OctoprintPrintTime changed
then
    Thread::sleep(500)
    val seconds = (OctoprintPrintTime.state as DecimalType).intValue
    val int totalMinutes = seconds/60
    val int remainderSecs = seconds%60
    val int totalHours = totalMinutes/60
    val int remainderMins = totalMinutes%60
    val formattedTime = String::format("%02d", totalHours) + ":" + String::format("%02d", remainderMins) + ":" + String::format("%02d", remainderSecs)
    OctoprintPrintTimeString.postUpdate(formattedTime)
end

rule "Time Left String"
when
    Item OctoprintPrintTimeLeft changed
then
    Thread::sleep(500)
    val seconds = (OctoprintPrintTimeLeft.state as DecimalType).intValue
    val int totalMinutes = seconds/60
    val int remainderSecs = seconds%60
    val int totalHours = totalMinutes/60
    val int remainderMins = totalMinutes%60
    val formattedTime = String::format("%02d", totalHours) + ":" + String::format("%02d", remainderMins) + ":" + String::format("%02d", remainderSecs)
    OctoprintPrintTimeLeftString.postUpdate(formattedTime)
    val OctoprintETA = now.plusSeconds(seconds)
    //logInfo("Testing" ,"Octoprint ETA: " + OctoprintETA.toString)
    val DateTimeType OctoprintETADT = DateTimeType.valueOf(OctoprintETA.toLocalDateTime().toString())
    //logInfo("Testing" ,"Octoprint ETA: " + OctoprintETADT.toString)
    OctoprintPrintETADateTime.postUpdate(OctoprintETADT)
    Thread::sleep(500)
    val String date = OctoprintPrintETADateTime.state.format("%1$td.%1$tm.%1$ty %1$tH:%1$tM")
    OctoprintPrintETAString.postUpdate(date)
end

Thx for the fast replay!!!
That solved my problem. Thanks

Hi, i have a little problem with the time strings OctoprintPrintTimeString and OctoprintPrintTimeLeftString they have values in the ui like it should but added to the sitemap it says no values from source-view.

Where could be the problem here. The time is generated via the rules and has the correct value but sitemaps don’t show it.

Found it here: BasicUI items not showing values from MQTT events - #2 by Lolodomo