How to: MQTTv2 Eventbus rules

It does not work unfortunately. I would like to send all statuses cyclically.

When I changed the cron to send every minute

rule “populate dynamic group dg_AllItems”
when
Time cron “1 * * * * ?”

    //Time cron "0 0/1 * * * ?"

then
// add all items to the group
ScriptServiceUtil.getItemRegistry.getItems().forEach[item | dg_AllItems.addMember(item) ]

    // remove all items which no longer exist
    dg_AllItems.members.filter(s | ScriptServiceUtil.getItemRegistry.getItems().filter[i | i.name.contains(s.name)].length == 0).forEach[item | dg_AllItems.removeMember(item)]

    // remove the group from itself (odd.)
    dg_AllItems.removeMember(dg_AllItems)

    //DEBUG dg_AllItems.members.forEach[ item | logInfo("dg_AllItems_member",item.name) ]

end

I’ll just ask if anyone has any ideas. In openHAB 2 I still used the Legacy 1.x binding for MQTT for a long time. It works stably. With this rule I have occasional problems that some things have to be sent out twice. Has anyone here had similar problems and a solution? Otherwise, the principle works with master and slave and vice versa.

So thank you very much for your suggestion.

Cloned my VM and then upgraded to openHAB 3. I hoped that the rule would work in the same way. The rule is at least displayed as being present. But with mosquitto_sub -v -h localhost -p 1883 -t ‘#’ I can’t see that anything has been published, even after status changes.

In my opinion, this can be due to two things and maybe someone here can help me. Either a difference between the bindings MQTT2 and MQTT3. Or differences between openHAB 2.5 (where it ran) and openHAB 3.

Off course I looked inside the MQTT 2.5+ Event Bus topic. The Rules DSL does not work either. Jython works.

I found Jython more cumbersome. I also adapted the mqtt_eb files a bit to create a solution similar to the one above. Unfortunately, it doesn’t work nearly as well as this rule in openHAB 2.

My first insight seems to be that the rule DSL does not work. Maybe someone can confirm this for me. Since I got a few things to work unstably in Jython, I am now simply trying out certain adjustments that I can take from https://github.com/openhab-scripters/openhab-helper-libraries/pull/257. My first attemp does not work either.

//Edit: I got the solution. I have to change

import org.eclipse.smarthome.model.script.ScriptServiceUtil

to

import org.openhab.core.model.script.ScriptServiceUtil

Your openhab.log should have told you about that.