Octoprint, MQTT, and JSONPATH

So, going slightly mad with this one. Followed the docs and examples and I just can’t see what I’m missing.

Got Octoprint writing to my MQTT service, no problems there. I can see messages popping up.

[23:44:02] pi@openHABianPi:/etc/openhab2/items$ mosquitto_sub -t octoprint/prusaMk3/temperature/tool0
{"_timestamp": 1534718641, "actual": 24.9, "target": 0.0}
{"_timestamp": 1534718646, "actual": 24.6, "target": 0.0}

I’ve got an item line configured as:

Number PrusaMk3_Temperature_Tool0 "Temperature [%.1f °C]" (PrusaMk3) { mqtt="<[mymosquitto:octoprint/prusaMk3/temperature/tool0:state:JSONPATH($.actual)]" }

But all I’m getting in the logs is:

2018-08-19 23:41:31.553 [WARN ] [b.core.events.EventPublisherDelegate] - given new state is NULL, couldn't post update for 'PrusaMk3_Temperature_Tool0'
2018-08-19 23:41:36.559 [WARN ] [b.core.events.EventPublisherDelegate] - given new state is NULL, couldn't post update for 'PrusaMk3_Temperature_Tool0'

Not sure what I’m missing, could just be a typo somewhere but I’ve been over it again and again. Any ideas?

I assume that you have other items configured with the mqtt binding and they work correctly.
Do there error messages occur when a message is received. I mean do they occur at the same time as in your test subscription?

I did a quick and dirty test and it works for me:
I used exactly your item definition
and I was sending the Json via node-red through mqtt but that should not make a difference

2018-08-20 01:47:04.209 [vent.ItemStateChangedEvent] - PrusaMk3_Temperature_Tool0 changed from NULL to 24.9
2018-08-20 01:48:18.327 [vent.ItemStateChangedEvent] - PrusaMk3_Temperature_Tool0 changed from 24.9 to 24.6

Maybe a quick clearing of the cache will make it work… Maybe…

Will try the cache clearing in the morning (can’t at the moment, as if I stop openhab then the house alarm complains about it and don’t want to wake the mrs up! :wink: )

I do have other stuff using mqtt and thats all working fine. The error messages do coincide with the test subscription.

What version of openhab are you running? I’m on 2.3.0.


I am running snapshot but it shouldn’t matter the mqtt binding and the jsonpath transform are really mature.
Have your tried another jsonpath on the same message?

Number PrusaMk3_Temperature_Tool0 "Temperature [%.1f °C]" (PrusaMk3) { mqtt="<[mymosquitto:octoprint/prusaMk3/temperature/tool0:state:JSONPATH($.target)]" }

for example?

Also have you tried to get the whole string to check the received message?

String PrusaMk3_json "Prusa json [%s]" (PrusaMk3) { mqtt="<[mymosquitto:octoprint/prusaMk3/temperature/tool0:state:default]" }


I’m also working on Octoprint / MQTT / JSONPATH.

Here are a few items I have so far:

String OctoprintConnected    "Connected [%s]"								                    (gOctoprint)    {mqtt="<[mosquitto:octoprint/connected:state:default]"}

Number:Temperature OctoprintPrinterHotEndTemp		"Nozzle temp [%.1f °C]"     <temperature>	(gOctoprint)	{mqtt="<[mosquitto:octoprint/temperature/tool0:state:JSONPATH($.actual)]"}
Number:Temperature OctoprintPrinterHotEndTempTarget	"Nozzle target [%.1f °C]"   <temperature>	(gOctoprint)	{mqtt="<[mosquitto:octoprint/temperature/tool0:state:JSONPATH($.actual)]"}
Number:Temperature OctoprintPrinterBedTemp			"Bed temp [%.1f °C]"        <temperature>	(gOctoprint)	{mqtt="<[mosquitto:octoprint/temperature/bed:state:JSONPATH($.actual)]"}
Number:Temperature OctoprintPrinterBedTempTarget	"Bed target [%.1f °C]"      <temperature>	(gOctoprint)	{mqtt="<[mosquitto:octoprint/temperature/bed:state:JSONPATH($.target)]"}

Number:Dimensionless OctoprintJobProgressCompletion	"Completion [%.0f %%]"		<battery>       (gOctoprint)	{mqtt="<[mosquitto:octoprint/progress/printing:state:JSONPATH($.progress)]"}

Let me know how far you get and we can complete the list!

I actually ended up just re-installing openhabian (I was on a very old version and it was all a little broken), and with a fresh install and the same config files it all works. So thanks for trying it out Vincent, seems it was just my screwed up installation. :slight_smile:

So far I have added the following:

String PrusaMk3_Connected "Status: %s" (PrusaMk3) { mqtt="<[mymosquitto:octoprint/prusaMk3/mqtt:state:default" }

Number PrusaMk3_Temperature_Tool0 "Temperature [%.1f °C]" (PrusaMk3) { mqtt="<[mymosquitto:octoprint/prusaMk3/temperature/tool0:state:JSONPATH($.actual)]" }
Number PrusaMk3_Temperature_Tool0_Target "Temperature [%.1f °C]" (PrusaMk3) { mqtt="<[mymosquitto:octoprint/prusaMk3/temperature/tool0:state:JSONPATH($.target)]" }
Number PrusaMk3_Temperature_Tool1 "Temperature [%.1f °C]" (PrusaMk3) { mqtt="<[mymosquitto:octoprint/prusaMk3/temperature/tool1:state:JSONPATH($.actual)]" }
Number PrusaMk3_Temperature_Tool1_Target "Temperature [%.1f °C]" (PrusaMk3) { mqtt="<[mymosquitto:octoprint/prusaMk3/temperature/tool1:state:JSONPATH($.target)]" }
Number PrusaMk3_Temperature_Bed "Temperature [%.1f °C]" (PrusaMk3) { mqtt="<[mymosquitto:octoprint/prusaMk3/temperature/bed:state:JSONPATH($.actual)]" }
Number PrusaMk3_Temperature_Bed_Target "Temperature [%.1f °C]" (PrusaMk3) { mqtt="<[mymosquitto:octoprint/prusaMk3/temperature/bed:state:JSONPATH($.target)]" }

Number PrusaMk3_ProgressCompletion "Completion [%.0f %%]" (PrusaMk3) {mqtt="<[mymosquitto:octoprint/prusaMk3/progress/printing:state:JSONPATH($.progress)]"}
Number PrusaMk3_CurrentLayerHeight "Layer Height [%.1f mm]" (PrusaMk3) {mqtt="<[mymosquitto:octoprint/prusaMk3/event/ZChange:state:JSONPATH($.new)]"}

String PrusaMk3_PrintStart "Started: [%s]" (PrusaMk3) {mqtt="<[mymosquitto:octoprint/prusaMk3/event/PrintStarted:state:JSONPATH($.name)]" }
String PrusaMk3_PrintEnd "Finished: [%s]" (PrusaMk3) {mqtt="<[mymosquitto:octoprint/prusaMk3/event/PrintDone:state:JSONPATH($.name)]" }

And have some of it graphing in grafana. I may also put in failed and cancelled printing status, and need to trigger an alert so I can see the format that that produces (doesn’t mention it in the API docs).

Done a quick rule to hopefully broadcast a barking dog to all my google homes. Will find out if it works when my 4.5 day print finishes. :wink:

1 Like

That’s EEEEEEVIL :grin: