MQTT 2.5 Actions Fail

Hi there,

I’m updating my OpenHAB server to a new Raspberry PI4 and updating it to 2.5.9 (I know, it’s about time).
Basically, this means moving to the new 2.5.x MQTT binding. Most of the update has been smooth sailing, but one thing still causes issues.

Previously, I had an MQTT publish action that would send an MQTT message to my shellies and have the update to the latest firmware.

Now I am trying to use the Rule Action that is described on the new bindings addon page (https://www.openhab.org/addons/bindings/mqtt.generic/#rule-actions), but it simply will not work.

I keep getting errors like this in the log:
An error occurred during the script execution: Could not invoke method: org.openhab.binding.mqtt.action.MQTTActions.publishMQTT(org.eclipse.smarthome.core.thing.binding.ThingActions,java.lang.String,java.lang.String,java.lang.Boolean) on instance: null

Here’s my MQTT thing:
Bridge mqtt:broker:mosquitto [ host="192.168.0.11", clientID="openhab2", port=1883,secure=false,retainMessages=false, retain=false ] { }

and here’s my test rule:

rule "Shellies Announce"
when
    Item Shellies_Command received command
then
    logDebug(logger, "Shelly maintenance on all devices: " + receivedCommand)

    val actions = getActions("mqtt","mqtt:broker:mosquitto")
    actions.publishMQTT("dollerup/home/test","Shellies Announce")    

    switch (receivedCommand) 
    {
        case "announce" :
        {
            actions.publishMQTT("mosquitto", "shellies/command", "announce") 
            logDebug(logger, "All Shellies are requested to announce themselves")
        }            
    }

    Shellies_Command.postUpdate(NULL)

end

What am I doing wrong?

I am not sure why it would not be working is you bridge thing online in paper UI?

My bridge is this

Bridge mqtt:broker:myMQTTBroker [ host ="192.168.1.148", secure =false, clientID ="myMQTTClient" ]

Do you need a username and password or your mosquitto?
Do you have the mqtt binding installed?

Can you try restarting openhab using sudo systemctl restart openhab2.service

Here are 2 working rule examples that work for me 2.5.9

rule "Test Item"
when
  Item TEST222a received command
then
   
  val value = '{\"state\":\"' + receivedCommand + '\"}'
  val actions = getActions("mqtt","mqtt:broker:myMQTTBroker") // myMQTTBroker is the name of my broker yours may be different
  actions.publishMQTT("zigbee2mqtt/WZ/PLUG/CAMERA/set",value)    

end


rule "Test MQTT Rule"
when
 Item TEST222a changed 
then
   val mqttActions = getActions("mqtt","mqtt:broker:myMQTTBroker")
   mqttActions.publishMQTT("dollerup/home/test", "Shellies Announce")
end

I found it. I had an extra parameter in the publishMQTT statement:

        case "announce" :
        {
            actions.publishMQTT("mosquitto", "shellies/command", "announce") 
            logDebug(logger, "All Shellies are requested to announce themselves")
        }  

After I changed it to:

        case "announce" :
        {
            actions.publishMQTT("shellies/command", "announce") 
            logDebug(logger, "All Shellies are requested to announce themselves")
        }  

It worked!!!

Now, as to why I didn’t see that I failed to “update” the mqtt action v1 statement, I can’t really give you an answer :wink:

Thanks!