MQTT Action service ThingHandler connection is null

I have a rules file like this:

val mqttActions = getActions("mqtt","mqtt:broker:myUnsecureBroker")
rule "alarmdisabled"
    Item StatusArmed changed to 0
    Item CamEnable changed to OFF

    mqttActions.publishMQTT( "eufy/cmd", "{\"command\": \"station.set_guard_mode\", \"messageId\": \"set_guard_mode\", \"serialNumber\": \"Txxx\",\"mode\":2 }",false) 

Occasionally it stops working and I see the following in the logs:

2022-08-18 09:31:42.451 [WARN ] [ing.mqtt.internal.action.MQTTActions] - MQTT Action service ThingHandler connection is null!

Re-saving the rules file so that it is re-loaded fixes the problem for a while. Is there an issue with MQTT in 3.3? I use MQTT for receiving so much other logged stuff so I think the connection to my broker is fine (there are no other errors or dropouts)


No, there is a misunderstanding on what happens when you call getActions. That call gives you a reference to a Thing that provides actions. But what if that Thing goes OFFLINE? What happens if the Thing doesn’t even exist yet or isn’t yet initialized when your .rules file is loaded? Obviously, mqttActions isn’t going to work because there was no Thing available at the time getActions was called, or the reference changed later because the Thing went offline and then came back online.

You must call getActions inside your rule, not outside. You need to get the current reference to the Thing, not what happened to exist when the file happened to be loaded.

I see. Thanks Rich!