publishMQTT stopped working in .rules

After upgrading to openHAB 5.1.0 (or maybe even before that - not 100% sure)
the publishMQTT action stopped working in rules.

I have a very simple two-channel Tasmota-based light switch thing, nothing special - on/off and that’s it.

In my .rules file I have:

rule "sw1ThingStatus"
when
  Thing "mqtt:topic:sw1" changed
then
  if (newThingStatus != "ONLINE") {
      sw1btn1.postUpdate("UNDEF")
      sw1btn2.postUpdate("UNDEF")
  } else {
      val mqttActions = getActions("mqtt", "mqtt:broker:mosquitto")
      mqttActions.publishMQTT("cmnd/sw1/power0", null)
  }
end

Explanation: The "UNDEF" part gives me some “greyed” look of my sitemap buttons. But more importantly, when the thing gets back online, I want to force the switch to re-publish the power state of the two buttons - the cmnd/sw1/power0 command topic does that.

It works when I manually publish this topic in the MQTT broker thing UI → Actionspublish an MQTT message.

But in the .rules I get this error:

Script execution of rule with UID ‘lights-1’ failed: ‘publishMQTT’ is not a member of ‘org.openhab.core.thing.binding.ThingActions’

Any ideas what may be the problem and more importantly how to fix it?

hi,

nearly the same Error with the mail binding : Script execution of rule failed: 'sendHtmlMail' is not a member of 'org.openhab.core.thing.binding.ThingActions'

A clean-cache and 3 or 4 reboots bring the mail binding back to work. But I don’t know why ?

BR Volker

I’d skip the clean-cache and just restart. I have seen this before and figured it was due to the bundle loading after a clean-cache (everything needs to get reloaded and the order might matter). If you just restart after 5-10 minutes following a clean-cache, it should be fine.

How about that - this is the process that fixed it for me… For now, at least:

  1. Remove/Uninstall the MQTT Binding
  2. Restart openHAB
  3. Add/Install the MQTT Binding again
  4. Restart openHAB again

It won’t work if openHAB is not restarted after each Remove/Add. And after each restart, give it some time to fully start/settle. Don’t rush installing, otherwise won’t work… Believe me, I tried.

I’m not sure what it is, but this can’t be the right way of fixing things.

chatGPT says “this forces Actions service to re-register” (whatever that means). Something with the binding being “only partially upgraded”.

Hope this helps others.

1 Like