Handling Shelly Button Press over MQTT

If someone needs to handle Shelly Button presses over MQTT here is the necessary info:

things file:

Type string : rpcevent [stateTopic="bridge/t15/wifi/gardenwestentranceswitch/events/rpc" ]

items file:

String GardenWestEntranceSwitchRpcEvent { channel="mqtt:topic:gardenwestentranceswitch:rpcevent" }

rules file:

rule "GardenWestEntranceSwitchRpcEvent received update"
when
  Item GardenWestEntranceSwitchRpcEvent received update
then
  val jsonstring = GardenWestEntranceSwitchRpcEvent.state.toString()
  val component = transform("JSONPATH", "$.params.events[0].component", jsonstring)
  val event = transform("JSONPATH", "$.params.events[0].event", jsonstring)
  if ((component != NULL) && (component == "bthomesensor:201") && (event != NULL)) {
    if (event == "single_push") {
      GardenDoor.sendCommand("ON")
    }
    else if (event == "double_push") {
      GardenDoor.sendCommand("ON")
    }
    else if (event == "triple_push") {
      GardenDoor.sendCommand("ON")
    }
    else if (event == "long_push") {
      GardenDoor.sendCommand("ON")
    }
    else {
      // unhandled push
    }
  }
end

Make sure to check the id of the Shelly Button in the Webinterface and replace bthomesensor:201 with the number that was assigned to the Shelly Button and replace GardenDoor.sendCommand(“ON”) with what you actually want to do.

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