Shelly Plus 1PM via MQTT

Hi folkes,
I am a bit inpatient and cannot waiting for the Shelly binding to cover the new devices and I read that due to the new ESP32 and new API, Shelly devices can now run cloud and MQTT in parallel. So if you start controlling your new devices (e.g. the Shelly Plus 1PM) via MQTT, you are not missing out on anything else. So here is my thing code for the Shelly Plus 1PM:

UID: mqtt:topic:5d0f79cab1:b0df524d88
label: MQTT Shelly Plus 1PM
thingTypeUID: mqtt:topic
configuration:
  payloadNotAvailable: off
  payloadAvailable: on
bridgeUID: mqtt:broker:5d0f79cab1
location: MQTT
channels:
  - id: id
    channelTypeUID: mqtt:number
    label: ID
    description: ""
    configuration:
      stateTopic: shellyplus1pm-44179393f8d0/status/switch:0
      transformationPattern: JSONPATH:$.id
  - id: source
    channelTypeUID: mqtt:string
    label: Quelle
    description: ""
    configuration:
      stateTopic: shellyplus1pm-44179393f8d0/status/switch:0
      transformationPattern: JSONPATH:$.source
  - id: output
    channelTypeUID: mqtt:string
    label: Ausgang
    description: ""
    configuration:
      stateTopic: shellyplus1pm-44179393f8d0/status/switch:0
      transformationPattern: JSONPATH:$.output
  - id: apower
    channelTypeUID: mqtt:number
    label: Leistung
    description: ""
    configuration:
      unit: W
      formatBeforePublish: "%.2f"
      stateTopic: shellyplus1pm-44179393f8d0/status/switch:0
      transformationPattern: JSONPATH:$.apower
  - id: voltage
    channelTypeUID: mqtt:number
    label: Spannung
    description: null
    configuration:
      unit: V
      formatBeforePublish: "%.2f"
      stateTopic: shellyplus1pm-44179393f8d0/status/switch:0
      transformationPattern: JSONPATH:$.voltage
  - id: current
    channelTypeUID: mqtt:number
    label: Strom
    description: null
    configuration:
      unit: A
      formatBeforePublish: "%.2f"
      stateTopic: shellyplus1pm-44179393f8d0/status/switch:0
      transformationPattern: JSONPATH:$.current
  - id: aenergy
    channelTypeUID: mqtt:number
    label: Energie
    description: null
    configuration:
      unit: Wh
      formatBeforePublish: "%.2f"
      stateTopic: shellyplus1pm-44179393f8d0/status/switch:0
      transformationPattern: JSONPATH:$.aenergy.total
  - id: temperature
    channelTypeUID: mqtt:number
    label: Temperatur
    description: null
    configuration:
      unit: °C
      formatBeforePublish: "%.2f"
      stateTopic: shellyplus1pm-44179393f8d0/status/switch:0
      transformationPattern: JSONPATH:$.temperature.tC
  - id: input
    channelTypeUID: mqtt:switch
    label: Input
    description: ""
    configuration:
      stateTopic: shellyplus1pm-44179393f8d0/status/input:0
      transformationPattern: JSONPATH:$.state
      off: "false"
      on: "true"
  - id: control
    channelTypeUID: mqtt:switch
    label: Schalter
    description: null
    configuration:
      commandTopic: shellyplus1pm-44179393f8d0/rpc
      formatBeforePublish: '{"src":"openhab", "method":"Switch.Set", "params":{"id":0,"on":%s}}'
      stateTopic: shellyplus1pm-44179393f8d0/status/switch:0
      transformationPattern: JSONPATH:$.output
      off: "false"
      on: "true"
  - id: online
    channelTypeUID: mqtt:switch
    label: Verbunden
    description: ""
    configuration:
      stateTopic: shellyplus1pm-44179393f8d0/online
      off: "false"
      on: "true"
  - id: cloud
    channelTypeUID: mqtt:switch
    label: Cloud
    description: ""
    configuration:
      stateTopic: shellyplus1pm-44179393f8d0/status/cloud
      transformationPattern: JSONPATH:$.connected
      off: flase
      on: "true"
  - id: mqtt
    channelTypeUID: mqtt:switch
    label: MQTT
    description: ""
    configuration:
      stateTopic: shellyplus1pm-44179393f8d0/status/cloud
      transformationPattern: JSONPATH:$.connected
      off: "false"
      on: "true"
  - id: kvs1
    channelTypeUID: mqtt:string
    label: KVS1
    description: null
    configuration:
      commandTopic: shellyplus1pm-44179393f8d0/rpc
      postCommand: true
      formatBeforePublish: '{"src":"openhab","method":"KVS.Get","params":{"id":1,"key":"admin"}}'
      stateTopic: shellyplus1pm-44179393f8d0/openhab/rpc
      transformationPattern: JSONPATH:$.params.value

You will need the MQTT binding of course and an MQTT broker like mosquitto (but that is a quite easy thing to get installed)

1 Like

I’m having and using ur same configuration I have a Shelly pro 2PM, I can command and control, but I cannot read any state

Hi all,

Since I’ve been sitting on it for the last two days, reading up to the API docs and it finally works, my advice:

Read the Shelly Plus 1PM with the option “Generic status update over MQTT: ON”, this is more reliable than rpc-notifications.

But be careful, the mqtt-channel will have a different state topic, namely mqtt_prefix/status/switch:0 instead of mqtt_prefix/events/rpc

living example:

#mosquitto_sub -t shellyplus1pm-4855199956f8/status/switch:0
Output:
{“id”:0, “source”: “init”, “output”:true, “apower”:8.3, “voltage”:231.6, “current”:0.059, “aenergy”:{“total”:5.537, “by_minute”:[78.115,70.837,74.719], “minute_ts”:1669555253}, “temperature.tC”:45.5, “tF”:113.9}}

Config of the Shelly Thing (bridged to the mqtt-broker)

UID: mqtt:topic:1d5559dbd3
label: Shelly_workroom
thingTypeUID: mqtt:topic
configuration: {}
bridgeUID: mqtt:broker:65063444ed
channels:

  • {} id: {} current consumption
    channelTypeUID: mqtt:number
    label: Current consumption
    description: “”
    configuration:
    stateTopic: shellyplus1pm-4855199956f8/status/switch:0
    transformationPattern: JSONPATH:$.apower
    unit: W
  • id: Total consumption
    channelTypeUID: mqtt:number
    label: Total consumption
    description: “”
    configuration:
    stateTopic: shellyplus1pm-4855199956f8/state/switch:0
    transformationPattern: JSONPATH:$.aenergy.total
    unit: Wh
  • id: Temperature
    channelTypeUID: mqtt:number
    label: Temperature
    description: “”
    configuration:
    stateTopic: shellyplus1pm-4855199956f8/state/switch:0
    transformationPattern: JSONPATH:$.temperature.tC
    unit: °C

best regards,
Hans

1 Like

Hi folks, I am new to the game here. Not new to openhab though, as I am playing around with it since v2.5. I am new to using shellys instead of my good old tasmota flashed sonoffs. Now since using the shellys, I noticed, even though the controlled device is switched off, I can see a constant fluctuation between 0.0 and 0.1w

2022-11-29 08:45:10.817 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'WMStateMachine_Power' changed from 0.0 to 0.1
2022-11-29 08:47:00.818 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'WMStateMachine_Power' changed from 0.1 to 0.0
2022-11-29 08:48:00.821 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'WMStateMachine_Power' changed from 0.0 to 0.1
2022-11-29 08:49:00.822 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'WMStateMachine_Power' changed from 0.1 to 0.0

Now this kills my Statemachine (at least the way I set it up, but I keep on reading if there is a better way) as it now reports back on/off all the time…

TL;DR:

  • Is there a way of “flattening” shelly output values,
  • calibrate without reflashing tasmota,
  • or any other way to overcome this ?
    Maybe i am missing the obvious here… and my apologies, if I did not express myself correctly, or if the formatting of my first post seems to be off-standard… :slight_smile:

Thanks,
Mathias

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