Shelly Plus 2PM as Rollershutter via MQTT

Since yesterday I’ve my first Shelly Plus 2PM installed and I’m struggling with the usage via MQTT. I found different threads here (like here or here) with similar topics, but I did not get it running. Maybe someone has a hint for me?

Here is a snippet from my MQTT things file:

    Thing mqtt:topic:shelly_galery_raffstore_south "blabla" @ "blablabla" {
            Type rollershutter : control "Steuerung" [ stateTopic="shellies/shellyplus2pm-mac/cover:0", transformationPattern="JSONPATH:$.current_pos", commandTopic="shellies/shellyplus2pm-mac/events/rpc", on="Open", off="Close", stop="Stop", formatBeforePublish="'{ \"method\": \"Cover.%s\", \"params\": { \"id\": 0 } }'" ]

            // all other items are currently disabled (as line comments)

Currently I’m trying to get the rollershutter command topic running. But it does not work. On the MQTT broker I can see, that rpc=Open resp. rpc=Stop resp. rpc=Close is published (instead of a JSON string). But required here is the JSON formatted string.

It looks like, that the formatbeforepublish is not recognized.

The documentation from the MQTT binding describes the pattern behaviour for each type:

  • Switch: No pattern supported. Always on and off strings.
  • Rollershutter: No pattern supported. Always up, down, stop string or integer percent value.

What does it (“pattern”) mean? Afaik from Java perspective means something more complex than %s. And curiuosly, for Switch types is seems to work (like on the linked example thread).

Thanks in advance!

I took a look into the source of MQTT binding:

  • Switch type supports (contrary to the documentation) using pattern (see here)
  • Rollershutter type does not support using patterns (see here)

Probably, I’ve to try something with transformationPatternOut to deal with that scenario …

As a workaround, I’ve replaced the formatBeforePublish with a JS-based trafo via transformationPatternOut. The JS file creates the JSON string based on the specified values for on (=>“Open”), off (=> “Close”) and stop (=> “Stop”).

In fact, it is only a workaround. Because other arguments like the cover Id for the shelly could not be extracted and only hard-coded handed over. Therefore the better solution would be via formatBeforePublish.

When applying a JS transformation to the state you can give additional arguments to the transformation script. Not sure if same is possible for transformationPatternOut, but maybe worth to test if that’s helpful for you

Thank you for that hint - unfortunately, I did not get it running. Therefore the hard-coded JS-trafo remains as solution for me until formatBeforePublish will be implemented in another way.

Just to complete “MQTT” and “Shelly Plus 2PM”, because the Gen 2 devices are very different in handling MQTT from Gen 1. It took some time to build similiar MQTT items with similar functionality compared to Gen 1. Here are some examples:

Preface: The value of the state topic is full flexible and based on two configurable aspects (which have to be synchronized)

  • Shelly MQTT configuration (e.g. via web frontend)
  • The “src” parameter within the JSON-Payload in published MQTT requests

I prefer the schema from Gen 1 devices, i.e. shellies/<device>-<mac>. Therefore I’m using it in my OH setup and in the following lines.

Example 1: How to trigger device information (MQTT topic and value)

// topic
// value
{ "id": 1001, "src": "shellies/shellyplus2pm-<mac>/response/device", "method": "Shelly.GetDeviceInfo" }

Example 2: How to fetch the firmware version number from MQTT response
Type string : firmware "FW-Version" [ stateTopic="shellies/shellyplus2pm-<mac>/response/device/rpc", transformationPattern="JSONPATH:$.result.ver" ]

Example 3: How to trigger firmware update

// topic = see Example 1
// value
"{ "id": 1002, "src": "shellies/shellyplus2pm-<mac>/response/device", "method": "Shelly.Update" }"

Do not forget the “id” or “src” param on top level! Unfortunately, the current firmware version validates it not correctly. In some situations missing params will return into an error response; but there are even more situations where simply nothing happens without any reactions or responses. I spent some hours for that insight (and to understand the shelly documentation in that point :crazy_face:).

Maybe this helpful for other Gen 2 newbies like me

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.