Mqtt Transformation

I would like to change a channel from my Mosquitto Broker to a Location Item. In the channel comes the following:


I thought I could insert the values for longitude, latitude and altitude as comma separated values into a location item by inserting the following per JSONPath at the Incoming Value Transformations item:

$.longitude, $.latitude, $.altitude

I have also tried:

[$.longitude, $.latitude, $.altitude]

Unfortunately it does not work I always get the following error

[WARN ] [rnal.handler.GenericMQTTThingHandler] - Channel configuration error

java.lang.IllegalArgumentException: The transformation pattern must consist of the type and the pattern separated by a colon

How can I transform it correctly?

Unfortunately, I don’t think it’s possible to do this in one go. You’ll have to extract each parameter into separate Items, and then combine using a rule.

Alternatively a JavaScript transformation can be used, that’s more flexible

1 Like

It means e.g.
[$.longitude, $.latitude, $.altitude]
will not do, you need to tell it which transformation service to use
JSONPATH:[$.longitude, $.latitude, $.altitude]
which will satisfy the syntax, but as you have found will not do what you want as the transformation service is limited to single-string answers, and chaining with ∩ pipes one output into the next input.

As already suggested, use JS instead to extract and manipulate into the single comma string that you want.

Thanks for your answers, i made a rule to transform it

configuration: {}
  - id: "1"
      itemName: GeolocationMQTT_DanielRohdaten
    type: core.ItemStateUpdateTrigger
conditions: []
  - inputs: {}
    id: "2"
      type: application/vnd.openhab.dsl.rule
      script: >-2
            val String json = (GeolocationMQTT_DanielRohdaten.state as StringType).toString
        		val String lat  = transform("JSONPATH", "$.latitude", json)
        		val String lon  = transform("JSONPATH", "$.longitude", json)
        		val String acc  = transform("JSONPATH", "$.gps_accuracy", json)
        		val String batt = transform("JSONPATH", "$.battery_level", json)
        		mqtt_PhoneDaniel_Location.postUpdate(lat + "," + lon)
        		mqtt_PhoneDaniel_LastUpdate.postUpdate(new DateTimeType())		
    type: script.ScriptAction