JSONPath command channel configuration for Shelly Plus (MQTT)

Recently I received my first Shelly Plus 2PM.
Since they are not yet supported by the Shelly binding, I would like to integrate them via MQTT.
I managed to read their output (relais) status via JSONPath transformation.

Also for the command channel I found a working solution, but it seems to be dirty hack.
What is the proper JSONPATH transformation to send a string like this?

{
  "method": "Switch.Set",
  "params": {
    "id": 0,
    "on": false
  }
}

My dirty hack makes use of “formatBeforePublish”. Code below:

UID: mqtt:topic:e3daee878f:shellyplus2pm-test
label: shellyplus2pm-test
thingTypeUID: mqtt:topic
configuration: {}
bridgeUID: mqtt:broker:e3daee878f
channels:
  - id: Output0
    channelTypeUID: mqtt:switch
    label: Output0
    description: ""
    configuration:
      commandTopic: shellies/shellyplus2pm-test/rpc
      formatBeforePublish: ' {"method":"Switch.Set", "params":{"id":0,"on":%s}}'
      stateTopic: shellies/shellyplus2pm-test/status/switch:0
      transformationPattern: JSONPATH:$.output
      off: "false"
      on: "true"
  - id: Output1
    channelTypeUID: mqtt:switch
    label: Output1
    description: ""
    configuration:
      commandTopic: shellies/shellyplus2pm-test/rpc
      formatBeforePublish: ' {"method":"Switch.Set", "params":{"id":1,"on":%s}}'
      stateTopic: shellies/shellyplus2pm-test/status/switch:1
      transformationPattern: JSONPATH:$.output
      off: "false"
      on: "true"

Thank you in advance,
Sven

That’s valid, nothing wrong with formatBeforePublish!

1 Like

There isn’t one, JSONPATH analyses JSON, it does not have a reverse function to build JSON.