Shelly plus i4

I have an Shelly plus i4 module I would like to introduce to Openhab3.
As the binding does not yet support the i4-module, I would like to get it read by MQTT.
Could somebody tell me how to configure the thing channel in order to read the input states.

The MQTT Explorer shows as topic :
shellyplusi4-083af200f114/events/rpc

and as event value:
{
“src”:“shellyplusi4-083af200f114”,
“dst”:“shellyplusi4-083af200f114/events”,
“method”:“NotifyStatus”,
“params”: {
“ts”:1644437498.95,
“input:3”: {
“id”:3,
“state”:false
}
}
}

Please note that I am not familiar with JSON at all.

Thanks a lot for information.

Ernest

Hast du einen Taster oder einen Schalter?
Für Taster wählst du bitte “Button” in der Shelly I4 Konfiguration.
Dann werden dir auch bei events die Arten der Bedienung angezeigt:
single_push
double_push
long_push
Das sieht dann z.B. so aus:

{“src”:“shellyplusi4-123456789”,“dst”:“shellyplusi4-123456789/events”,“method”:“NotifyEvent”,“params”:{“ts”:1645117510.31,“events”:[{“component”:“input:0”, “id”:0, “event”:“single_push”, “ts”:1645117510.31}]}}

shellyplusi4-123456789 ist bei dir shellyplusi4-083af200f114

Du brauchst einen MQTT Broker für Openhab, auf Openhabian kannst du z.B. Mosquitto im Konfig Menü installieren.
Danach

  • MQTT Binding installieren.
  • JSON Addon installieren.
  • Thing MQTT Broker hinzufügen
  • Thing ShellyPlusI4 hinzufügen (Generic MQTT Thing)
  • Channel hinzufügen mit MQTT State Topic: shellyplusi4-123456789/events/rpc
  • verlinken mit neuem Item Typ String
  • Beim ITEM JSONPATH anhaken und unter JSONPath Expression;
    $.params.events[:1].event

Jetzt hast du ein ITEM, welches du bei RULES verwenden kannst.
Viel Erfolg!

1 Like

English please, this is an international community!!!

1 Like

Hi Pascal
Thank you for your instructions.
The last point was the one I missed.
Now it works fine .
Ernest

Thank you @Ernest and @BigPe for this post.
I have added several Shelly devices into OH3 with the Shelly-binding which was very easy. I experienced the same challenge as you, when I tried to implement a Shelly Plus i4. As the Shelly i4 is currently only supported with MQTT, I tried to follow your instructions (install MQTT Broker via Openhabian config, …). Up to now I didn’t use MQTT and have no knowledge on JSONpath.

When I push a button on the Shelly i4 I get the following result in the OH Log:

2022-03-18 18:41:39.971 [WARN ] [ab.binding.mqtt.generic.ChannelState] - Command ‘{“src”:“shellyplusi4-083af2014970”,“dst”:“shellyplusi4-083af2014970/events”,“method”:“NotifyEvent”,“params”:{“ts”:1647625300.54,“events”:[{“component”:“input:0”, “id”:0, “event”:“btn_down”, “ts”:1647625300.54}]}}’ not supported by type ‘OpenCloseValue’: No enum constant org.openhab.core.library.types.OpenClosedType.{“src”:“shellyplusi4-083af2014970”,“dst”:“shellyplusi4-083af2014970/events”,“method”:“NotifyEvent”,“params”:{“ts”:1647625300.54,“events”:[{“component”:“input:0”, “id”:0, “event”:“btn_down”, “ts”:1647625300.54}]}}

2022-03-18 18:41:40.492 [WARN ] [ab.binding.mqtt.generic.ChannelState] - Command ‘{“src”:“shellyplusi4-083af2014970”,“dst”:“shellyplusi4-083af2014970/events”,“method”:“NotifyEvent”,“params”:{“ts”:1647625301.05,“events”:[{“component”:“input:0”, “id”:0, “event”:“btn_up”, “ts”:1647625301.05}]}}’ not supported by type ‘OpenCloseValue’: No enum constant org.openhab.core.library.types.OpenClosedType.{“src”:“shellyplusi4-083af2014970”,“dst”:“shellyplusi4-083af2014970/events”,“method”:“NotifyEvent”,“params”:{“ts”:1647625301.05,“events”:[{“component”:“input:0”, “id”:0, “event”:“btn_up”, “ts”:1647625301.05}]}}

2022-03-18 18:41:40.497 [WARN ] [ab.binding.mqtt.generic.ChannelState] - Command ‘{“src”:“shellyplusi4-083af2014970”,“dst”:“shellyplusi4-083af2014970/events”,“method”:“NotifyEvent”,“params”:{“ts”:1647625301.05,“events”:[{“component”:“input:0”, “id”:0, “event”:“single_push”, “ts”:1647625301.05}]}}’ not supported by type ‘OpenCloseValue’: No enum constant org.openhab.core.library.types.OpenClosedType.{“src”:“shellyplusi4-083af2014970”,“dst”:“shellyplusi4-083af2014970/events”,“method”:“NotifyEvent”,“params”:{“ts”:1647625301.05,“events”:[{“component”:“input:0”, “id”:0, “event”:“single_push”, “ts”:1647625301.05}]}}

2022-03-18 18:41:45.430 [WARN ] [ab.binding.mqtt.generic.ChannelState] - Command ‘{“src”:“shellyplusi4-083af2014970”,“dst”:“shellyplusi4-083af2014970/events”,“method”:“NotifyEvent”,“params”:{“ts”:1647625306.00,“events”:[{“component”:“input:0”, “id”:0, “event”:“btn_down”, “ts”:1647625306.00}]}}’ not supported by type ‘OpenCloseValue’: No enum constant org.openhab.core.library.types.OpenClosedType.{“src”:“shellyplusi4-083af2014970”,“dst”:“shellyplusi4-083af2014970/events”,“method”:“NotifyEvent”,“params”:{“ts”:1647625306.00,“events”:[{“component”:“input:0”, “id”:0, “event”:“btn_down”, “ts”:1647625306.00}]}}

2022-03-18 18:41:45.657 [WARN ] [ab.binding.mqtt.generic.ChannelState] - Command ‘{“src”:“shellyplusi4-083af2014970”,“dst”:“shellyplusi4-083af2014970/events”,“method”:“NotifyEvent”,“params”:{“ts”:1647625306.23,“events”:[{“component”:“input:0”, “id”:0, “event”:“btn_up”, “ts”:1647625306.23}]}}’ not supported by type ‘OpenCloseValue’: No enum constant org.openhab.core.library.types.OpenClosedType.{“src”:“shellyplusi4-083af2014970”,“dst”:“shellyplusi4-083af2014970/events”,“method”:“NotifyEvent”,“params”:{“ts”:1647625306.23,“events”:[{“component”:“input:0”, “id”:0, “event”:“btn_up”, “ts”:1647625306.23}]}}

2022-03-18 18:41:45.926 [WARN ] [ab.binding.mqtt.generic.ChannelState] - Command ‘{“src”:“shellyplusi4-083af2014970”,“dst”:“shellyplusi4-083af2014970/events”,“method”:“NotifyEvent”,“params”:{“ts”:1647625306.50,“events”:[{“component”:“input:0”, “id”:0, “event”:“single_push”, “ts”:1647625306.50}]}}’ not supported by type ‘OpenCloseValue’: No enum constant org.openhab.core.library.types.OpenClosedType.{“src”:“shellyplusi4-083af2014970”,“dst”:“shellyplusi4-083af2014970/events”,“method”:“NotifyEvent”,“params”:{“ts”:1647625306.50,“events”:[{“component”:“input:0”, “id”:0, “event”:“single_push”, “ts”:1647625306.50}]}}

2022-03-18 18:42:04.364 [WARN ] [ab.binding.mqtt.generic.ChannelState] - Command ‘{“src”:“shellyplusi4-083af2014970”,“dst”:“shellyplusi4-083af2014970/events”,“method”:“NotifyEvent”,“params”:{“ts”:1647625324.94,“events”:[{“component”:“input:1”, “id”:1, “event”:“btn_down”, “ts”:1647625324.94}]}}’ not supported by type ‘OpenCloseValue’: No enum constant org.openhab.core.library.types.OpenClosedType.{“src”:“shellyplusi4-083af2014970”,“dst”:“shellyplusi4-083af2014970/events”,“method”:“NotifyEvent”,“params”:{“ts”:1647625324.94,“events”:[{“component”:“input:1”, “id”:1, “event”:“btn_down”, “ts”:1647625324.94}]}}

2022-03-18 18:42:04.945 [WARN ] [ab.binding.mqtt.generic.ChannelState] - Command ‘{“src”:“shellyplusi4-083af2014970”,“dst”:“shellyplusi4-083af2014970/events”,“method”:“NotifyEvent”,“params”:{“ts”:1647625325.51,“events”:[{“component”:“input:1”, “id”:1, “event”:“btn_up”, “ts”:1647625325.51}]}}’ not supported by type ‘OpenCloseValue’: No enum constant org.openhab.core.library.types.OpenClosedType.{“src”:“shellyplusi4-083af2014970”,“dst”:“shellyplusi4-083af2014970/events”,“method”:“NotifyEvent”,“params”:{“ts”:1647625325.51,“events”:[{“component”:“input:1”, “id”:1, “event”:“btn_up”, “ts”:1647625325.51}]}}

2022-03-18 18:42:04.949 [WARN ] [ab.binding.mqtt.generic.ChannelState] - Command ‘{“src”:“shellyplusi4-083af2014970”,“dst”:“shellyplusi4-083af2014970/events”,“method”:“NotifyEvent”,“params”:{“ts”:1647625325.51,“events”:[{“component”:“input:1”, “id”:1, “event”:“single_push”, “ts”:1647625325.51}]}}’ not supported by type ‘OpenCloseValue’: No enum constant org.openhab.core.library.types.OpenClosedType.{“src”:“shellyplusi4-083af2014970”,“dst”:“shellyplusi4-083af2014970/events”,“method”:“NotifyEvent”,“params”:{“ts”:1647625325.51,“events”:[{“component”:“input:1”, “id”:1, “event”:“single_push”, “ts”:1647625325.51}]}}

2022-03-18 18:42:09.554 [WARN ] [ab.binding.mqtt.generic.ChannelState] - Command ‘{“src”:“shellyplusi4-083af2014970”,“dst”:“shellyplusi4-083af2014970/events”,“method”:“NotifyEvent”,“params”:{“ts”:1647625330.13,“events”:[{“component”:“input:1”, “id”:1, “event”:“btn_down”, “ts”:1647625330.13}]}}’ not supported by type ‘OpenCloseValue’: No enum constant org.openhab.core.library.types.OpenClosedType.{“src”:“shellyplusi4-083af2014970”,“dst”:“shellyplusi4-083af2014970/events”,“method”:“NotifyEvent”,“params”:{“ts”:1647625330.13,“events”:[{“component”:“input:1”, “id”:1, “event”:“btn_down”, “ts”:1647625330.13}]}}

2022-03-18 18:42:09.765 [WARN ] [ab.binding.mqtt.generic.ChannelState] - Command ‘{“src”:“shellyplusi4-083af2014970”,“dst”:“shellyplusi4-083af2014970/events”,“method”:“NotifyEvent”,“params”:{“ts”:1647625330.34,“events”:[{“component”:“input:1”, “id”:1, “event”:“btn_up”, “ts”:1647625330.34}]}}’ not supported by type ‘OpenCloseValue’: No enum constant org.openhab.core.library.types.OpenClosedType.{“src”:“shellyplusi4-083af2014970”,“dst”:“shellyplusi4-083af2014970/events”,“method”:“NotifyEvent”,“params”:{“ts”:1647625330.34,“events”:[{“component”:“input:1”, “id”:1, “event”:“btn_up”, “ts”:1647625330.34}]}}

2022-03-18 18:42:10.053 [WARN ] [ab.binding.mqtt.generic.ChannelState] - Command ‘{“src”:“shellyplusi4-083af2014970”,“dst”:“shellyplusi4-083af2014970/events”,“method”:“NotifyEvent”,“params”:{“ts”:1647625330.63,“events”:[{“component”:“input:1”, “id”:1, “event”:“single_push”, “ts”:1647625330.63}]}}’ not supported by type ‘OpenCloseValue’: No enum constant org.openhab.core.library.types.OpenClosedType.{“src”:“shellyplusi4-083af2014970”,“dst”:“shellyplusi4-083af2014970/events”,“method”:“NotifyEvent”,“params”:{“ts”:1647625330.63,“events”:[{“component”:“input:1”, “id”:1, “event”:“single_push”, “ts”:1647625330.63}]}}

My Channel definition for the buttons 0 and 1:

Item definition for button1:

I assume I did something wrong or didn’t fully understand your instructions. Could you give me a hint what I need to change? Do I need one channel and 4 items (one item for every button) or 4 channels and 4 items?

That looks not wrong… What is the result on the item?

When I push a button I get a result similar to

Do you get something like that?

I only use one button for one light, I want to control. But I guess you don’t need more even with four buttons. The button ID is transmitted via MQTT as well. You can separate this info as well (in an additional item).

When you see a correct result, then next try to add an item to get the ID of your button.

You will have one channel and 2 items. One item for the push type and one for the ID.

Thank you Pascal @BigPe for your quick reply. The result of my items was NULL. So I deleted the items and channel an created the channel again as type “String” and not as type “Contact” as I did before. According your recommendation I linked two items to the channel - one for the id (pushed contact 0 … 3) and one for the event (“single_push”, “double_push”, “long_push”).

Now I’m able to use these items in a rule
… but I still do not fully understand the JSON transformations
“$.params.events[:1].event” and “$.params.events[:1].id” … the part “[:1]” of the transformation stands for ???

I had the same challenge with the Shelly i4 and solved it by installing OpenHab with Mosquitto MQTT as described in this wiki (yes, I know it is written in German.

After installing the MQTT Binding in OpenHab and creating the Thing MQTT Broker, I added a Generic MQTT Thing for the Shelly i4:

UID: mqtt:topic:916484178a:44451a25ad
label: Shelly plus i4
thingTypeUID: mqtt:topic
configuration: {}
bridgeUID: mqtt:broker:916484178a
location: Milky way
channels:
  - id: Button1
    channelTypeUID: mqtt:trigger
    label: Button1 Trigger Events
    description: ""
    configuration:
      stateTopic: shelly-i4/events/rpc
      transformationPattern: JSONPATH:$.params.events[?(@.id==0)].event
  - id: Button2
    channelTypeUID: mqtt:trigger
    label: Button2 Trigger Events
    description: ""
    configuration:
      stateTopic: shelly-i4/events/rpc
      transformationPattern: JSONPATH:$.params.events[?(@.id==1)].event
  - id: Button3
    channelTypeUID: mqtt:trigger
    label: Button3 Trigger Events
    description: null
    configuration:
      stateTopic: shelly-i4/events/rpc
      transformationPattern: JSONPATH:$.params.events[?(@.id==2)].event
  - id: Button4
    channelTypeUID: mqtt:trigger
    label: Button2 Trigger Events
    description: null
    configuration:
      stateTopic: shelly-i4/events/rpc
      transformationPattern: JSONPATH:$.params.events[?(@.id==3)].event

With this configuration you can create e.g. a rule which is triggered by the Shelly channel. In the button channels you will receive singe_push, double_push or long_push.

Example:

configuration: {}
triggers:
  - id: "1"
    configuration:
      thingUID: mqtt:topic:916484178a:44451a25ad
      event: double_push
      channelUID: mqtt:topic:916484178a:44451a25ad:Button1
    type: core.ChannelEventTrigger
conditions: []
actions:
  - inputs: {}
    id: "2"
    configuration:
      type: application/javascript
      script: |-
        events.sendCommand('SomeLightDevice', '100');
    type: script.ScriptAction

I hope that this will save other people some research :slight_smile:

Digging up this topic again, I am having a tiny issue recreating what you folks discussed here. I have 2 Shelly plus i4 switches for which I do not want to use the Shelly binding (currently I am on OH 3.4.5.). The Shelly binding uses websocket based communication and for some reason my switches signal’s get received with a delay of couple of seconds by openHAB at some point of the day. A workaround is to deactivate and activate the i4’s things again. Then the switch signal is instantly received but after a while the delay returns.

To workaround this I wanted to use MQTT. I got it working file based but I still receive warnings in the logs which I would like to get rid of. Could you please help me out?

The thing definition

Bridge mqtt:broker:raspi4 [ host="<IP>", secure=false, clientID="openHAB" ]

Thing mqtt:topic:Lichtschalter_Hobbyraum "Lichtschalter Hobbyraum" (mqtt:broker:raspi4) @ "Hobbyraum" {
    Channels:
        Type switch : status [ stateTopic="shellyplusi4-b8d61a8c78d4/status/input:0", on="true", off="false", transformationPattern="JSONPATH:$.state" ]    
}

The item definition:

Switch          Lichtschalter_Hobbyraum
                "Lichtschalter Hobbyraum"
                (Lichtschalter, Deckenlampen_Hobbyraum)
                { 
                    channel="mqtt:topic:Lichtschalter_Hobbyraum:status"
                }

When using the switch I receive this warning:

Could not transform state 'ON' with function 'JSONPATH:$.state' and format '%s'

or

Could not transform state 'OFF' with function 'JSONPATH:$.state' and format '%s'

Any idea why?

Um… for a reason I do not understand the messages stopped showing up. I did not reboot. The only thing I did was assigning the equipment ["WallSwitch"] to each switch item (and then removed it again for a different reason). Since then the log does not show any warnings :thinking:.