Openhab Shelly PRO 3 PM generic MQTT Thing Code

Hi There,

unfortunately the standard shelly binding does not support shelly pro devices. Three Years ago htttito already posted a solution for generic MQTT Binding .

UID: mqtt:topic:7d3c004212:Shelly4_Heizpatrone
label: Shelly4_Heizpatrone
thingTypeUID: mqtt:topic
configuration: {}
bridgeUID: mqtt:broker:7d3c004212
channels:
  - id: Relay0
    channelTypeUID: mqtt:switch
    label: Relay0
    description: ""
    configuration:
      commandTopic: shellies/shellypro4pm-84cca87d86bc/rpc
      formatBeforePublish: '{"src":"MQTT","method":"Switch.Set", "params":{"id":0,"on":%s}}'
      stateTopic: shellies/shellypro4pm-84cca87d86bc/status/switch:0
      transformationPattern: JSONPATH:$.output
      off: "false"
      on: "true"
  - id: Relay0_Volt
    channelTypeUID: mqtt:number
    label: Relay0_Volt
    description: null
    configuration:
      unit: V
      formatBeforePublish: "%.4f"
      stateTopic: shellies/shellypro4pm-84cca87d86bc/status/switch:0
      transformationPattern: JSONPATH:$.voltage
  - id: Relay0_Watt
    channelTypeUID: mqtt:number
    label: Relay0_Watt
    description: ""
    configuration:
      unit: W
      formatBeforePublish: "%.4f"
      stateTopic: shellies/shellypro4pm-84cca87d86bc/status/switch:0
      transformationPattern: JSONPATH:$.apower
  - id: Relay0_Ampere
    channelTypeUID: mqtt:number
    label: Relay0_Ampere
    description: null
    configuration:
      unit: A
      formatBeforePublish: "%.4f"
      stateTopic: shellies/shellypro4pm-84cca87d86bc/status/switch:0
      transformationPattern: JSONPATH:$.current

unfortunately it seems that the MQTT code is not any longer the same.

By monitoring the signals of the Shelly pro 3PM via MQTT Explorer i couldn’t find the signal in root like shellies.… as discribed by htttito.

my PRO devices show a green payload if adresses like this

UID: mqtt:topic:synologyMQTTmosquitobroker:b5e5c9c274
label: DGF Flur Shelly pro Dimmer 1 pm
  final-shellyprodm1pm-34987aa8e914-192.168.178.130
thingTypeUID: mqtt:topic
configuration:
  payloadNotAvailable: "false"
  availabilityTopic: shellyprodm1pm-34987aa8e914/online
  payloadAvailable: "true"
bridgeUID: mqtt:broker:synologyMQTTmosquitobroker
channels:
  - id: ch1Dim
    channelTypeUID: mqtt:dimmer
    label: Channel 1 Dimmer
    configuration:
      postCommand: false
      retained: false
      formatBeforePublish: '{"id":0, "src":"user_1", "method":"Light.Set",
        "params":{"id":0, "brightness": %d}}'
      commandTopic: shellyprodm1pm-34987aa8e914/rpc
      step: 1
      stateTopic: shellyprodm1pm-34987aa8e914/events/rpc
      transformationPattern: REGEX:(.*light:0.*brightness.*)∩JSONPATH:$.params["light:0"]brightness
  - id: ch1Sw
    channelTypeUID: mqtt:switch
    label: Channel 1 Switch
    configuration:
      postCommand: false
      retained: false
      formatBeforePublish: '{"id":0, "src":"user_1", "method":"Light.Set",
        "params":{"id":0, "on": %s}}'
      commandTopic: shellyprodm1pm-34987aa8e914/rpc
      stateTopic: shellyprodm1pm-34987aa8e914/rpc
      transformationPattern: REGEX:(.*light:0.*output.*)∩JSONPATH:$.params.["light:0"]output
      off: "false"
      on: "true"
  - id: ch1In
    channelTypeUID: mqtt:switch
    label: Channel 1 Input
    configuration:
      stateTopic: shellyprodm1pm-34987aa8e914/events/rpc
      transformationPattern: REGEX:(.*input:0.*event.*)∩JSONPATH:$.params.events[0]event
      off: btn_up
      on: btn_down
  - id: ch2In
    channelTypeUID: mqtt:switch
    label: Channel 2 Input
    configuration:
      stateTopic: shellyprodm1pm-34987aa8e914/events/rpc
      transformationPattern: REGEX:(.*input:1.*event.*)∩JSONPATH:$.params.events[0]event
      off: btn_up
      on: btn_down
  - id: ch1InStr
    channelTypeUID: mqtt:string
    label: Channel 1 Input String
    configuration:
      stateTopic: shellyprodm1pm-34987aa8e914/events/rpc
      transformationPattern: REGEX:(.*input:0.*event.*)∩JSONPATH:$.params.events[0]event
  - id: ch2InStr
    channelTypeUID: mqtt:string
    label: Channel 2 Input String
    configuration:
      stateTopic: shellyprodm1pm-34987aa8e914/events/rpc
      transformationPattern: REGEX:(.*input:1.*event.*)∩JSONPATH:$.params.events[0]event
  - id: ch1Power
    channelTypeUID: mqtt:number
    label: Channel 1 Power
    configuration:
      stateTopic: shellyprodm1pm-34987aa8e914/events/rpc
      transformationPattern: REGEX:(.*light:0.*apower.*)∩JSONPATH:$.params["light:0"]apower
      unit: W




addons like regex and jasonpath are installed addionally.

But all trials to adjust the code from htttito to my Shelly Pro Dimmer code went wrong.

This is what i tied so far without being able to communicate with the PRO 3 PM device even if the code shoes a “green” payload"

UID: mqtt:topic:synologyMQTTmosquitobroker:9e5cd7a60f
label: OGB Bad Deckenstrahler weiss 192.168.178.160
thingTypeUID: mqtt:topic
configuration:
  payloadNotAvailable: "false"
  availabilityTopic: shellypro3-fce8c0db4794/online
  payloadAvailable: "true"
bridgeUID: mqtt:broker:synologyMQTTmosquitobroker
location: Shelly
channels:
  - id: Relay0
    channelTypeUID: mqtt:switch
    label: Relay0
    configuration:
      commandTopic: shellypro3-fce8c0db4794/rpc
      formatBeforePublish: '{"src":"MQTT","method":"Switch.Set", "params":{"id":0,"on":%s}}'
      stateTopic: shellypro3-fce8c0db4794/status/switch:0
      transformationPattern: JSONPATH:$.output
      off: "false"
      on: "true"
  - id: Relay0_Volt
    channelTypeUID: mqtt:number
    label: Relay0_Volt
    configuration:
      unit: V
      formatBeforePublish: "%.4f"
      stateTopic: shellypro3-fce8c0db4794/status/switch:0
      transformationPattern: JSONPATH:$.voltage
  - id: Relay0_Watt
    channelTypeUID: mqtt:number
    label: Relay0_Watt
    configuration:
      unit: W
      formatBeforePublish: "%.4f"
      stateTopic: shellypro3-fce8c0db4794/status/switch:0
      transformationPattern: JSONPATH:$.apower
  - id: Relay0_Ampere
    channelTypeUID: mqtt:number
    label: Relay0_Ampere
    configuration:
      unit: A
      formatBeforePublish: "%.4f"
      stateTopic: shellies/shellypro3-fce8c0db4794/status/switch:0
      transformationPattern: JSONPATH:$.current
  - id: ch1In
    channelTypeUID: mqtt:switch
    label: Channel 1 Input
    configuration:
      stateTopic: shellypro3-fce8c0db4794events/rpc
      transformationPattern: REGEX:(.*input:0.*event.*)∩JSONPATH:$.params.events[0]event
      off: btn_up
      on: btn_down
  - id: ch1Sw
    channelTypeUID: mqtt:switch
    label: Channel 0 Switch
    configuration:
      postCommand: false
      retained: false
      formatBeforePublish: '{"src":"User_1","method":"Switch.Set", "params":{"id":0,"on":%s}}'
      commandTopic: shellypro3-fce8c0db4794/rpc
      stateTopic: shellypro3-fce8c0db4794/rpc
      transformationPattern: REGEX:(.*switch:0.*output.*)∩JSONPATH:$.params.["switch:0"]output
      off: "false"
      on: "true"
  - id: ch1Power
    channelTypeUID: mqtt:number
    label: Channel 1 Power
    configuration:
      stateTopic: shellypro3-fce8c0db4794/events/rpc
      transformationPattern: REGEX:(.*switch:0.*apower.*)∩JSONPATH:$.params["switch:0"]apower
      unit: W

looking forward getting suggestions from advanced MQTT cracks. Unfortunately Im a beginner and don’t realy understand the MQTT code

best regards Runa

I have that same device now running with FW 1.5.1 and the Shelly binding and it’s been stable these last weeks.
[/quote]

I have that same device now running with FW 1.5.1 and the Shelly binding and it’s been stable these last weeks.
[/quote]

I have that same device now running with FW 1.5.1 and the Shelly binding and it’s been stable these last weeks.

Hi Pedro_Liberal,

are you using the standard binding or the beta binding fort shelly devices ? FW 1.5.1. is also my current FW

but im stll looking for a MQTT solution

Greeting Runa

1 Like

Standard. From marketplace.

Hi. Thanks for your example on the dimmer.

I used this to control my Shelly Dimmer gen 3.
I like that the Dimmer item goes to 0% when the Switch item is off, so I replaced your REGEX with a js transormation.

But I have not been able to set the Switch item to “true” when I operate the Dimmer item in openhab. Since both use the “Light.Set” parameter, I don’t see how I can do this. Maybe someone can give me a push in the right direction.

Thing code:

UID: mqtt:topic:Farmen:b5e5c9c274
label: Shelly_Dimmer69
thingTypeUID: mqtt:topic
configuration:
  payloadNotAvailable: "false"
  availabilityTopic: shellydimmerg3-e4b3233b3ffc/online
  payloadAvailable: "true"
bridgeUID: mqtt:broker:Farmen
channels:
  - id: ch1Dim
    channelTypeUID: mqtt:dimmer
    label: Channel 1 Dimmer
    configuration:
      postCommand: false
      retained: false
      formatBeforePublish: '{"id":0, "src":"user_1", "method":"Light.Set",
        "params":{"id":0, "brightness": %d}}'
      commandTopic: shellydimmerg3-e4b3233b3ffc/rpc
      step: 1
      stateTopic: shellydimmerg3-e4b3233b3ffc/status/light:0
      transformationPattern:
        - JS:shelly_dimmer_input_bright-g3.js
  - id: ch1Sw
    channelTypeUID: mqtt:switch
    label: Channel 1 Switch
    configuration:
      postCommand: false
      retained: false
      formatBeforePublish: '{"id":0, "src":"user_1", "method":"Light.Set",
        "params":{"id":0, "on": %s}}'
      commandTopic: shellydimmerg3-e4b3233b3ffc/rpc
      stateTopic: shellydimmerg3-e4b3233b3ffc/status/light:0
      transformationPattern:
        - JSONPATH:$.output
      off: "false"
      on: "true"
  - id: ch1In
    channelTypeUID: mqtt:switch
    label: Channel 1 Input
    configuration:
      stateTopic: shellydimmerg3-e4b3233b3ffc/events/rpc
      transformationPattern:
        - REGEX:(.*input:0.*event.*)∩JSONPATH:$.params.events[0]event
      off: btn_up
      on: btn_down
  - id: ch2In
    channelTypeUID: mqtt:switch
    label: Channel 2 Input
    configuration:
      stateTopic: shellydimmerg3-e4b3233b3ffc/events/rpc
      transformationPattern:
        - REGEX:(.*input:1.*event.*)∩JSONPATH:$.params.events[0]event
      off: btn_up
      on: btn_down
  - id: ch1InStr
    channelTypeUID: mqtt:string
    label: Channel 1 Input String
    configuration:
      stateTopic: shellydimmerg3-e4b3233b3ffc/events/rpc
      transformationPattern:
        - REGEX:(.*input:0.*event.*)∩JSONPATH:$.params.events[0]event
  - id: ch2InStr
    channelTypeUID: mqtt:string
    label: Channel 2 Input String
    configuration:
      stateTopic: shellydimmerg3-e4b3233b3ffc/events/rpc
      transformationPattern:
        - REGEX:(.*input:1.*event.*)∩JSONPATH:$.params.events[0]event
  - id: ch1Power
    channelTypeUID: mqtt:number
    label: Channel 1 Power
    configuration:
      stateTopic: shellydimmerg3-e4b3233b3ffc/events/rpc
      transformationPattern:
        - REGEX:(.*light:0.*apower.*)∩JSONPATH:$.params["light:0"]apower
      unit: W

shelly_dimmer_input_bright-g3.js

(function(i) {
    shellyInput = JSON.parse(i);
    shellyInput.output ? brightness = shellyInput.brightness : brightness = 0;
    return brightness;
})(input)

It does not realy apply to the topic PRO3 but i also have difficulties in controlling the switch function properly with my dimmer code.

If i swich the shelly device by openhab on an off everything is fine but if the shelly device is switched on by other option e.g. external switch or shelly app the change of status is not mentioned an the openhab stays at the same status.

Nasty is it e.g. with the auto off function. Openhab still remains in on status. perhabs some has a solution for this.

My workaround is monitoring the power an changing the status according to power > 0W or power = 0 . but this is a pure solution.