JSONPATH transformation failed from MQTT events from Shelly Plus 2PM with Shelly Addon

Hi Openhab Community,

I have a problem with JSONPATH transformation.
I have the following setup:

  • Openhabian 3.4.4 on a Rpi 4
  • MQTT Broker from Openhabian running on the Pi
  • Shelly Plus 2PM with a Shelly Plus Addon where a contact sensor

The contact sensor is on a window and is supposed to track if the window is opened or closed.
The Shelly Plus 2PM is connected to my MQTT broker. When the window is opened/closed a event is triggered there and appears to be correct:


On the right side you see the events “true” or “false” which are triggered from the sensor.

I have a MQTT thing where I want to extract the sensor status using JSONPATH transformation:

Bridge mqtt:broker:MQTTBroker [ host="localhost", secure=false, username="", password=""] {
Thing topic Shelly2PM_DG_Kueche "ShellyPlus2PM_Fenster_DG_Küche" @ "DG Küche" {
        Channels:
            Type contact : Shelly2PM_DG_Kueche_Window "Shelly 2PM DG Küche Fensterkontakt" [ stateTopic="shellyplus2pm-441793a7e098/events/rpc", transformationPattern="JSONPATH:$.params.input:100.state", Open="true", Close="false" ]
        }    
}

Futher I have created this item:

Contact DG_Kueche_Fenster "Fenster DG Küche" <window> (DG_Kueche) ["Window"] {channel="mqtt:topic:MQTTBroker:Shelly2PM_DG_Kueche:Shelly2PM_DG_Kueche_Window", homekit="ContactSensor"}

Unfortunately, the transformation does not work.
The item does always display NULL as status. Although the events are transmitted via MQTT.

When the sensor triggeres events, the logfile displays this entry:

What am I doing wrong? Every help or hint is highly appreciated.

Thanks!

The transform is working correctly. Your error message tells you that after the transform has returned “false” the channel doesn’t know what to do with that because "false" is not a viable option for a contact channel.

If you look in your channel definition you used Open and Closed to try to define custom values, but those are not valid configurations. Contact channels are configured just like switch channels if I recall, so you need to use on and off to define custom values even for the contact type channel.

Thanks a lot for this fast reply!

I changed the thing to that:

Thing topic Shelly2PM_DG_Kueche "ShellyPlus2PM_Fenster_DG_Küche" @ "DG Küche" {
        Channels:
            Type contact : Shelly2PM_DG_Kueche_Window "Shelly 2PM DG Küche Fensterkontakt" [ stateTopic="shellyplus2pm-441793a7e098/events/rpc", transformationPattern="JSONPATH:$.params.input:100.state", On="true", Off="false" ]
        } 

I tried different writing versions: on ON and On

However, that had no effect.
The log keeps displaying this entry:

Not “On” and “Off”, but “on” and “off”. These configurations are case-sensitive.

I tried different versions, also on and off. Unfortunately, always no effect.

I thought that on and off where bi-directional, but maybe they are only outgoing transformations (I don’t use them on my few MQTT items). In that case, you will need to chain the JSONPath transform to another transform (e.g. map transform) to convert the true/false strings to open/closed commands.

Please try another JSONPATH:

Thing topic Shelly2PM_DG_Kueche "ShellyPlus2PM_Fenster_DG_Küche" @ "DG Küche" {
    Channels:
        Type contact : Shelly2PM_DG_Kueche_Window "Shelly 2PM DG Küche Fensterkontakt" [ stateTopic="shellyplus2pm-441793a7e098/events/rpc", transformationPattern="JSONPATH:$.params['input:100'].state", on="true", off="false" ]
}

Please be aware that there is absolutely no need to use such long names for the Channels, as the Channels are always addressed with the complete
UID: mqtt:topic:brokername:Shelly2PM_DG_Kueche:Shelly2PM_DG_Kueche_Window

1 Like

Thank you very much! That finally worked.
Also thanks to the hint regarding the channel names. I had in mind that they also need to be unique. But the uniqueness is created through the thing name.