2 transformations in one item

Hello everyone. Im trying to do the following:
Convert the output of exec biding to a item switch. The output is a JSON so I have to convert it via JSONPATH to get the value (1/0). This value I want to convert it with MAP to ON/OFF but every time I define the item as a switch, it is not able to convert it.

Some things I have tried:

  • If I define the item as String it does convert it to ON/OFF but when writing rules or widgets I always end up getting 1/0. Weird.
  • If I do all the transformation by rules it does set the value correctly.
    This is my item:
Switch camera_front_status "Camera front status [MAP(binary_camera_status.map):%s]" { channel="exec:command:camera:output"[profile="transform:JSONPATH", function="$.BA1.deviceInfos.status"]}

This is the custom rule to test the conversion:

rule "Check JSONPATH Output"
    Item camera_status_output_raw_value received update
    val rawStatus = transform("JSONPATH", "$.BA1.deviceInfos.status", camera_status_output_raw_value.state.toString)
    logInfo("Check JSONPATH Output", "Raw status: " + rawStatus.toString)
    val mappedStatus = transform("MAP", "binary_camera_status.map", rawStatus)
    logInfo("Check MAP Output", "Mapped status: " + mappedStatus)


Any idea what could be happening? Thanks!

This only changes how the state of the Item appears in the UIs. You need to convert the the 1/0 to ON/OFF before it gets sent as an update to the Switch Item. The transformation you apply to the label happens after that.

Because you need two transformations here, instead of applying the JSONPATH in a profile, apply it to the Thing. Exec - Bindings | openHAB

Then apply the Map transformation in the profile so the 1/0 gets changed to ON/OFF before the updated gets to the Item.

Or use a Script transformation to handle both. For example, in JavaScript:

(function(input) {
  var parsed = JSON.parse(input);
  (parsed.BA1.deviceInfos.status == 0) ? OFF : ON;

Or continue to use the Rule.

For what’s it’s worth, transformations can also be chained by separating them with the mathematical intersection character “∩”

This is only supported by a few bindings: HTTP and MQTT for certain, I think KNX also but an not positive. Unfortunately chaining is not universally supported across all bindings and the Exec binding is one that lacks support for chaining.