[SOLVED] Rules hooked to MQTT channels are not triggered

Hi all,

I successfully can publish message from the OH rule engine to the local mqtt broker. Works like a charm.

rule "Temporarily unlock the door"
when
    Item UnlockDoor received command
then   
        logInfo("SAH", "Unlock the door temporarily.")    
        val mqttActions = getActions("mqtt", "mqtt:broker:localbroker")
        mqttActions.publishMQTT("sah/aarau/maindoor/lock/cmd", UnlockDoor.state.toString)
end

That tells me the broker is configured correctly - at least to accept messages to be published.

Anyhow, the rule does NOT receive messages from the mqtt channel defined thru PaperUI. I copied the channel after I have created it: mqtt:topic:maindoor:contact and added it to the rule.

Switch MechanicalDoorBell "Door Bell" <button> (gDoorBellSystem) { channel="mqtt:topic:doorbell:mechanicaldoorbell", autoupdate="true"}

rule "mechanical door bell pressed"
when
     Item MechanicalDoorBell received command or Item MechanicalDoorBell changed
then
    var msg = "The mechanical door bell was pushed."
    sendBroadcastNotification(msg)
    playSound("doorbell.mp3")
    logInfo("SAH", msg)        
    //say(msg, "voicerss:enUS", "chromecast:audiogroup:PublicSpeakers", new PercentType(100))    
end

Some observations I can confirm:

  • The ruleset file has no errors (as I know how it would be indicated by the log file)

  • The rule that publishes successfully to the mqtt broker is in the same ruleset file as the receiving rule, which is not working.

  • with MQTT.fx I can see that the message, which the rule should react on, arrives at the broker (I also did shut down the MQTT.fx client to make sure the message is not consumed before OH does).

    I also tried to work with channels and triggered.

      rule "mechanical door (channel) bell pressed"
      when
           Channel "mqtt:topic:doorbell:mechanicaldoorbell" triggered
      then
          var msg = "The mechanical door bell was pushed."
          sendBroadcastNotification(msg)
          playSound("bird.wav")
          logInfo("SAH", msg)        
          //say(msg, "voicerss:enUS", "chromecast:audiogroup:PublicSpeakers", new PercentType(100))    
      end
    

I clearly miss out on how to configure the consumption of mqtt messages with items or channels, since the messages are evidently delivered to the mqtt broker. What am I missing from the documentation?

Hi,
Switch MechanicalDoorBell "Door Bell" <button> (gDoorBellSystem) { channel="mqtt:topic:doorbell:mechanicaldoorbell", autoupdate="true"}

How is that channel defined, please?
Can you show the config?

Does the log show that the item changes when you press the doorbell or send a test topic/payload with mqtt.fx?

MQTT doesn’t work like that. You have a broker that receives all messages and then broadcasts it to ALL subscribers of that particular topic.

Hi Vincent

Thanks for your fast response.

Is this what you are looking for? From the ItemChannelLink.json

"mqtt_topic_doorbell_mechanicaldoorbell -\u003e mqtt:topic:doorbell:mechanicaldoorbell": {
    "class": "org.eclipse.smarthome.core.thing.link.ItemChannelLink",
    "value": {
      "channelUID": {
        "segments": [
          "mqtt",
          "topic",
          "doorbell",
          "mechanicaldoorbell"
        ]
      },
      "configuration": {
        "properties": {}
      },
      "itemName": "mqtt_topic_doorbell_mechanicaldoorbell"
    }
  },

You defined the channel on the paperUI?
I can’t see a topic in the JSON
Can you post a screenshot of your channel definition, please?

You defined the channel on the paperUI?

Yes.

I can’t see a topic in the JSON

I have not clue how that would look like in the ItemChannelLink.json file after entered in the PaperUI.
In the Thing.json file I have found what you propably are looking for. Where the mechanicaldoorbell is matched with the topic sah/aarau/maindoor/mechanicaldoorbell of the mqtt broker

"channels": [
        {
          "acceptedItemType": "Switch",
          "kind": "STATE",
          "uid": {
            "segments": [
              "mqtt",
              "topic",
              "doorbell",
              "mechanicaldoorbell"
            ]
          },
          "channelTypeUID": {
            "segments": [
              "mqtt",
              "switch"
            ]
          },
          "label": "Mechanical Door Bell",
          "configuration": {
            "properties": {
              "commandTopic": "",
              "stateTopic": "sah/aarau/maindoor/mechanicaldoorbell",
              "retained": false
            }
          },
          "properties": {},
          "defaultTags": []
        },

Can you post a screenshot of your channel definition, please?

Sure. Here it is.

You can trust me, that the thing (Door Bell System) has the one and only broker bridged assigned.

… and here the mechanical door bell in the PaperUI config

So the topic is defined as:
sah/aarau/maindoor/mechanicaldoorbell

What is the payload?

It is only a ON. (A OFF is never sent. It’s assumed to be the default state. A debouncer ensure the signal is only sent once every 5 seconds so that no one can storm-signal the mechanical door bell)

Right then your rules triggers are wrong:
The item doesn’t receive a command nor does it changes
Updates of items to the same value are not shown of the events log.

Change the trigger to received update

rule "mechanical door bell pressed"
when
    //Item MechanicalDoorBell received command or 
    //Item MechanicalDoorBell changed
    Item MechanicalDoorBell received update
then
    var msg = "The mechanical door bell was pushed."
    sendBroadcastNotification(msg)
    playSound("doorbell.mp3")
    logInfo("SAH", msg)        
    //say(msg, "voicerss:enUS", "chromecast:audiogroup:PublicSpeakers", new PercentType(100))    
end
2 Likes

Thank you Vincent for your serious inspection and support. Changing it to “update” did it. I’ll remember the synopsis.

Btw. Here the docs for other folks looking for the difference of update and command.