MQTT commands (via RPC Topic)

I would like to control the new Shelly BLU TRV and the old WIFI TRV via openHAB.
The TRV runs via a WIFI Bluetooth gateway.

To control the valve, for example, you need the following publish code:

MQTT Topic:

shellyGatewayIP/rpc

Payload:

{
  "id": 0,
  "src": "testcommand",
  "method": "BluTRV.Call",
  "params": {
    "id": 200,
    "method": "TRV.SetPosition",
    "params": {
      "id": 0,
      "pos": 99
    }
  }
}

As this is an RPC (Remote Procedure Call), the syntax of the payload must look like this.

My question: Can I configure this via the openHAB WebUI in the MQTT channel or item or do I have to start a rule when the setpoint valve position item specifies a new value.

In advance
Thank you for your support :+1:

As long as there is only one parameter to be set (maybe pos?) you can do it via simple formatBeforePublish

formatBeforePublish : '{"id": 0, "src": "testcommand", "method": "BlueTRV.Call", "params": {"id": 200, "method": "TRV.SetPosition", "params": {"id": 0, "pos": %s}}}'

Please be aware that this is a string with single quotes, therefor you don’t need to escape the double quotes. %s will be replaced by the actual value.

Hi Udo, thanks for the tip with the apostrophe that helped me first, because I already had problems with the TRV calibration rule.

Could you explain to me what the expression “formatBeforePublish : ‘{…}’ means?

Sorry, but I had to start with the calibration command before I could send valve positions. Otherwise the TRV will not move.

I have managed to do that now. The JavaScript ECMA11 syntax was also important to me, which I did not find in the official openHAB documentation and found the following source.
https://openhab-scripters.github.io/openhab-helper-libraries/Guides/Actions.html and https://munier.perso.univ-pau.fr/en/tutorial/iot/2021/20210107-openhab3_mqtt_part01/

So the solution is to trigger a calibration in the BLU TRV:

ECMAScript 262 Edtion 11

// Set calibration of the BLU TRV via MQTT Publish

actions.get("mqtt", "mqtt:broker:MQTT_Broker").publishMQTT("yourShellyGatewayIP/rpc", '{"id":0,"src":"calibrate","method":"BluTRV.Call","params":{"id":200,"method":"TRV.Calibrate","params":{"id":0}}}');

The payload has to be valid JSON. '...' the outer single quotes are markers of the string (here the three dots …). The outer curly brackets {...} are already part of the JSON.

1 Like