Hi,
I am trying to transform incoming MQTT JSON. Working fine on other items, but not on this particular JSON.
Here is MQTT visible on broker:
[{“conso”: “6”, “time”: “11/07/2020”}, {“conso”: “2”, “time”: “12/07/2020”}, {“conso”: “0”, “time”: “13/07/2020”}, {“conso”: “1”, “time”: “14/07/2020”}, {“conso”: “4”, “time”: “15/07/2020”}, {“conso”: “3”, “time”: “16/07/2020”}, {“conso”: “5”, “time”: “17/07/2020”}, {“conso”: “4”, “time”: “18/07/2020”}, {“conso”: “2”, “time”: “19/07/2020”}, {“conso”: “4”, “time”: “20/07/2020”}, {“conso”: “3”, “time”: “21/07/2020”}, {“conso”: “3”, “time”: “22/07/2020”}]
Script running daily is producing this MQTT payload.
I would like to get “conso” value which is produced on daily basis into Openhab item.
Trying to get last value from JSON with JSONPATH.
Bonus would be to check that last value is indeed value from “yesterday”, ie day before the script is run. Because the MQTT payload is produced by extracting website data, and sometimes values may not yet be there. I suppose this would mean use a JS file though.
Any idea? Thanks
.things file:
Thing mqtt:topic:mosquitto:gazpar “Gazpar” (mqtt:broker:mosquitto) @ “Salon” {
Channels:
Type number : gazpar-consommation “Consommation Gaz” [ stateTopic=“gazpar”, transformationPattern=“JSONPATH:$…conso[(@.length-1)]” ]
.items file:
Number Gazpar_Consommation “Consommation gaz [%.d kWh]”
{ channel=“mqtt:topic:mosquitto:gazpar:gazpar-consommation” }
Error log:
2020-07-23 17:43:41.805 [WARN ] [t.generic.ChannelStateTransformation] - Executing the JSONPATH-transformation failed: An error occurred while transforming JSON expression.