Problems with trigger rhannel and/or rule on Zigbee2MQTT action topic for Third Reality remote

Hi all,

I’m having an issue where my trigger channel on my Third Reality remote. I probably just don’t have it configured correctly, but I’ve tried searching and cannot seem to find anything that can help me. My remote has 4 actions that it will publish: single, double, hold, release. It publishes to a common topic with all the remote properties. This looks something like this:

z2m:mqtt: MQTT publish: topic 'zigbee2mqtt/livingroom_remote', payload '{"action":"release","battery":100,"linkquality":255,"update":{"installed_version":35,"latest_version":47,"state":"available"}}'

Disregard the version information. I can’t quite get it to respond to the OTA updates.

Openhab sees it online, but it can’t seem to read the action when it’s published. The JSONPATH looks correct to me.

UID: mqtt:topic:myBroker:livingroom_remote
label: Living Room Remote
thingTypeUID: mqtt:topic
configuration:
  payloadNotAvailable: offline
  payloadAvailable: online
  transformationPattern: JSONPATH:$.state
  availabilityTopic: zigbee2mqtt/livingroom_remote/availability
bridgeUID: mqtt:broker:myBroker
location: Living Room
channels:
  - id: livingroom_remote_trigger
    channelTypeUID: mqtt:trigger
    label: Living Room Action Trigger
    description: ""
    configuration:
      stateTopic: zigbee2mqtt/livingroom_remote
      transformationPattern: JSONPATH:$.action

However, when I create a rule to look for the events on that trigger being one of the 4 values above, I am unable to get the rule to do anything. Here is what my rule looks like. Maybe I am incorrectly identifying the event?

configuration: {}
triggers:
  - id: "1"
    configuration:
      thingUID: mqtt:topic:myBroker:f1_livingroom_remote
      event: single
      channelUID: mqtt:topic:myBroker:livingroom_remote:livingroom_remote_trigger
    type: core.ChannelEventTrigger
conditions:
  - inputs: {}
    id: "3"
    configuration:
      itemName: Living_Room_Bulb_1_Power
      state: ON
      operator: =
    type: core.ItemStateCondition
actions:
  - inputs: {}
    id: "2"
    configuration:
      command: OFF
      itemName: Living_Room_Bulb_1_Power
    type: core.ItemCommandAction

I’m not really sure what else to look at. Documentation on how to get from a trigger channel to a functional rule is a little lacking (or at least nothing with examples). I appreciate any help that anyone can offer.

I only have a three-way-switch, but I think that th way to use is nearly the same as yours. My setup is textual-based.

The Thing is declared:

// **********************************************************************************************************************************************************************************************************************
//Gruppe ZigBee                Schalter 
// **********************************************************************************************************************************************************************************************************************
//                          Mini Switch SNZB01 - 01 contact_snzb01_01
Thing mqtt:topic:danny:snzb0101 "Sonoff SNZB01 01"  (mqtt:broker:danny )   @ "zigbee2mqtt"
      [ availabilityTopic="zigbee2mqtt/contact_snzb01_01/availability", transformationPattern="JSONPATH:$.state", payloadNotAvailable="offline", payloadAvailable="online" ] 
    {
    Channels:
        Type string  : action       "SNZB01 01 Ein/Aus"                      [ stateTopic="zigbee2mqtt/contact_snzb01_01/action" ]
        Type number  : voltage      "SNZB01 01 Batterie-Spannung"            [ stateTopic="zigbee2mqtt/contact_snzb01_01/voltage", unit="mV" ]
        Type number  : battery      "SNZB01 01 Batterie-Level"               [ stateTopic="zigbee2mqtt/contact_snzb01_01/battery", unit="%" ] 
        Type number  : linkquality  "SNZB01 01 Empfangsstärke LQI"           [ stateTopic="zigbee2mqtt/contact_snzb01_01", transformationPattern="JSONPATH:$.linkquality" ]
        Type trigger : click        "SNZB01 01 Trigger"                      [ stateTopic="zigbee2mqtt/contact_snzb01_01/action" ]
        Type switch  : reachable    "SNZB01 01 Reachable"                    [ stateTopic="zigbee2mqtt/contact_snzb01_01/availability", transformationPattern="JSONPATH:$.state", on="online", off="offline" ]
    }

Then the Item(s) are declared as:

//**********************************************************************************************************************************************************************************************************************
//Gruppe ZigBee             Schalter - Taster
//**********************************************************************************************************************************************************************************************************************
//                          Mini Switch SNZB01 - 01 snzb_01_01
Group                       gsnzb01_01                 "Taster SNZB-01 01"                               <snzb_01>               (gEG_Kind2,gZ2M)                   ["Button"]
String                      snzb01_01_action           "Taster SNZB-01 01 Zustand"                       <snzb_01>               (gsnzb01_01)                       ["Switch"]                                  { channel="mqtt:topic:danny:snzb0101:action" }     
Number:ElectricPotential    snzb01_01_voltage          "Taster SNZB-01 01 Spannung [%.1f]"               <snzb_01>               (gsnzb01_01)                       ["Voltage"]                                 { channel="mqtt:topic:danny:snzb0101:voltage" }        
Number:Dimensionless        snzb01_01_battery          "Taster SNZB-01 01 Batterie"                      <snzb_01>               (gsnzb01_01,gBattLevelEG)          ["LowBattery"]                              { channel="mqtt:topic:danny:snzb0101:battery", unit="%" }       
Number                      snzb01_01_linkquality      "Taster SNZB-01 01 LQI "                          <snzb_01>               (gsnzb01_01)                       ["Level"]                                   { channel="mqtt:topic:danny:snzb0101:linkquality", stateDescription=" " [pattern="%.0f LQI"] }     
Switch                      snzb01_01_Unreach          "Taster SNZB-01 01 Erreichbarkeit [%s]"           <siren1>                (gsnzb01_01,gLWT)                  ["Point"]                                   { channel="mqtt:topic:danny:snzb0101:reachable" }     

And at least the Rule looks for the switch like:

//------------------------------------------------------------------------------------------------------------------------------------------------
rule "miniswitch_snzb01_01"
  when
   Channel 'mqtt:topic:danny:snzb0101:click' triggered
  then
    var  GenericItem itZiel
    val strReceivedEvent = String::format("%1$-6s", receivedEvent)
     switch(receivedEvent) {
        case "single" : itZiel = LidlLedLamp_01
        case "double" : itZiel = Be2709w_01
        case "long"   : itZiel = zbminil2_01_state
        default : {
            logWarn("miniswitch_snzb01_01","Da ist was schief gegangen! Unbekanntes Event {} empfangen!", strReceivedEvent)
            return;
        }
    }
    var strLocation = getLocation(itZiel).label                      // Location Label ermitteln
    val strOnOff    = if(itZiel.state != ON) "ein" else "aus"        // künftiger Zustand
    val strItLabel  = String::format("%1$-17s", itZiel.label)
    logInfo("miniswitch_snzb01_01", "{} - {} {}geschaltet: {}", strReceivedEvent, strItLabel, String::format("%1$3s",  strOnOff ), strLocation)
    itZiel.sendCommand(if(itZiel.state != ON) ON else OFF)
end

  

So I think you have to declare a Trigger-Channel (Type trigger) and then ask for the receivedEvent. I first had the same problem, but get help from @Udo_Hartmann in the past who solves my problem.

In the Script-Section you can use either “switch/case” or “if/else”.

Hope this can help you.

Cheers - Peter

When something doesn’t work, simplify and add logging.

Trigger the rule without limiting the event to “single” and then log out the event. That will tell you if your JSONPATH is working and whether you are getting the event you think you should be getting.

Love the help Peter…thanks for the insight into your setup. I wish I had the time to convert all my things, items, and rules into configuration files. Also I wish I knew more about Java to be confident doing it. This really helped. Specifically, tying a string item to the channel showed me that the JSONPATH was correct and that the it was capturing the right actions. While this item isn’t technically needed, this helped me to determine that the rule was the culprit.

While duplicating your rule and translating it to my things/items, I discovered that my problem was that I haphazardly recreated the remote and the lights it was intended to control in zigbee2mqtt and Openhab. In my haste, I forgot to delete the old things/items from openhab (although I could have just recycled them), and I was still referencing them on the old rule. The new items were named so similarly to the old items that I was having trouble distinguishing the difference between the two and I think I had been looking at that problem for several hours after a long day of work. When I corrected the control and condition items, everything started working.

So the mystery solved and lesson learned. Don’t recreate things. Just update the existing things with the new topics. Or better yet, keep the same name on zigbee2mqtt objects and you don’t have to do anything in Openhab.

Cheers,

John H

Thanks Rich,

This helped me to get logging setup. I hadn’t considered it earlier. This should help with troubleshooting going forward.

Cheers,

John H

That’s great, if everything now works. BTW I saw that my Trigger-Channel uses the direct payload. So if you want to use the JSONPATH one have to add a transformationPattern=“JSONPATH:$.action”

I mix sometimes the possibilities as I can use both ways.

Cheers,

Peter

Yeah, this is exactly what I had to do. Mine doesn’t have the direct topic. I had to pull it from the payload using this exact JSONPATH.

Thanks again!

Cheers!