Rule or Script for 3d Printing MQTT

  • Platform information:
    • Hardware: R PI4
    • OS: Synology DS415+
    • openHAB version: 2.04
  • Issue of the topic: MQTT query

I don’t know if I should do this with a rule or with a script, can you send me an example?
I have a mqtt string and want to display the values from tool 0,1,2,3,4

the values can look like this, depending on which color I print with, the value behind “filament” is different.

Color white:
… “filament”: {“tool0”: {“volume”: 35.43455963325066, “length”: 5012.964730592337}}},

color orange
… “filament”: {“tool1”: {“volume”: 35.43455963325066, “length”: 5012.964730592337}}},

color green
… “filament”: {“tool2”: {“volume”: 35.43455963325066, “length”: 5012.964730592337}}},

color gray
… “filament”: {“tool3”: {“volume”: 35.43455963325066, “length”: 5012.964730592337}}},

Color: Black
… “filament”: {“tool4”: {“volume”: 35.43455963325066, “length”: 5012.964730592337}}},

the complete mqtt value looks like this when I print with green.

{"_timestamp": 1591433108, “progress”: 16, “printer_data”: {“progress”: {“completion”: 16.000371777137083, “printTimeLeftOrigin”: “genius”, “printTime”: 2010, “printTimeLeft”: 6720, “filepos”: 604247}, “state”: {“text”: “Printing”, “flags”: {“cancelling”: false, “paused”: false, “operational”: true, “pausing”: false, “printing”: true, “resuming”: false, “sdReady”: true, “error”: false, “ready”: false, “finishing”: false, “closedOrError”: false}}, “currentZ”: 3.8, “job”: {“averagePrintTime”: null, “lastPrintTime”: null, “user”: “_api”, “file”: {“origin”: “local”, “name”: “V29D_Fixed_0.15mm_PETG_MK3SMMU2S_2h25m.gcode”, “date”: 1591431097, “path”: “V29D_Fixed_0.15mm_PETG_MK3SMMU2S_2h25m.gcode”, “display”: “V29D_Fixed_0.15mm_PETG_MK3SMMU2S_2h25m.gcode”, “size”: 3776456}, “estimatedPrintTime”: 8787.496217990165, “filament”: {“tool2”: {“volume”: 35.43455963325066, “length”: 5012.964730592337}}}, “offsets”: {“tool4”: 0, “tool3”: 0, “tool2”: 0, “tool1”: 0, “tool0”: 0}}, “location”: “local”, “path”: “V29D_Fixed_0.15mm_PETG_MK3SMMU2S_2h25m.gcode”}

I only want to show the values of the current tool, in this case green,

it should be the screen mirror from 3D printing tool OctoDash under Octoprint.

What are you going to do with them? Assuming display on UI, you would have to get the values into multiple Items. So we have an idea of what we’re trying to acheive.

Where do they come from? Guessing there is one or more MQTT topics you can subscribe to, so you’d make a generic Thing for that.

Having got the two ends of the process, it looks like you’d just need to use JSONPATH transformation to extract fields into suitable channels, which you link to Items

Yes (thanks for answer) , I have problems with this value. extract the appropriate channel: Volume
I’m trying right now, but I’m probably blind

Value: → filamen.tool2.volume

{
“_timestamp” : 1591453362,
“progress” : 11,
“printer_data” : {
“progress” : {
“completion” : 11.00092255808091,
“printTimeLeftOrigin” : “genius”,
“printTime” : 1865,
“printTimeLeft” : 7140,
“filepos” : 415445
},
“state” : {
“text” : “Printing”,
“flags” : {
“cancelling” : false,
“paused” : false,
“operational” : true,
“pausing” : false,
“printing” : true,
“resuming” : false,
“sdReady” : true,
“error” : false,
“ready” : false,
“finishing” : false,
“closedOrError” : false
}
},
“currentZ” : 2.9,
“job” : {
“averagePrintTime” : null,
“lastPrintTime” : null,
“user” : “_api”,
“file” : {
“origin” : “local”,
“name” : “V29D_Fixed_0.15mm_PETG_MK3SMMU2S_2h25m.gcode”,
“date” : 1591451495,
“path” : “V29D_Fixed_0.15mm_PETG_MK3SMMU2S_2h25m.gcode”,
“display” : “V29D_Fixed_0.15mm_PETG_MK3SMMU2S_2h25m.gcode”,
“size” : 3776456
},
“estimatedPrintTime” : 8787.496217990165,
“filament” : {
“tool2” : {
“volume” : 35.43455963325066,
“length” : 5012.964730592337
}
}
},
“offsets” : {
“tool4” : 0,
“tool3” : 0,
“tool2” : 0,
“tool1” : 0,
“tool0” : 0
}
},
“location” : “local”,
“path” : “V29D_Fixed_0.15mm_PETG_MK3SMMU2S_2h25m.gcode”
}

Okay, what have you tried? We cannot see your Item, we cannot see your channel, we cannot see any JSONPATH that you have configured.

If we indent your JSON for clarity -

{
“_timestamp” : 1591453362,
“progress” : 11,
“printer_data” : {
   “progress” : {
   ...
   },
   “state” : {
      “text” : “Printing”,
      “flags” : {
          “cancelling” : false,
          ....
      }
   },
   “currentZ” : 2.9,
   “job” : {
       “averagePrintTime” : null,
      ...
      “file” : {
         “origin” : “local”,
         ...
      },
      “estimatedPrintTime” : 8787.496217990165,
      “filament” : {
         “tool2” : {
            “volume” : 35.43455963325066,
            “length” : 5012.964730592337
         }
      }
   },
  “offsets” : {
      “tool4” : 0,
   ...

isn’t the JSONPATH $.printer_data.job.filament.tool2.volume ?

thanks a lot of (I do not see “job” : I need the Placeholder because Tool1 -4 are variable, now it is working.
JSONPATH $.printer_data.job.filament.*.volume

Here ist the first run with all values:

what I don’t have sensible yet is formatting the values
35.43455963325066 is much too long and should only have 3 digits:

[%.3f] g. Filament
%.3f

does not work?

Well, no, you’ve used a String type Item, so you cannot format it like a decimal.
Why not use a Number Item with number channel?

‘Outgoing value format’ is what it says, about outgoing values. Put what you like in there, it won’t affect incoming MQTT messages.