I trigger a rule upon the change of the occupancy item. Within the rule I check illumination.
My problem: occupancy is updated before illumination and I need it the other way around.
That did not change the order of the events occuring.
2025-03-03 17:57:25.149 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Bewegungsmelder_Bad' changed from CLOSED to OPEN
2025-03-03 17:57:25.681 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Bewegungsmelder_Bad_Dunkel' changed from OFF to ON
Also logged the state of Bewegungsmelder_Bad_Dunkel and it is still OFF when executing the rule.
Hmmm, possibly due to the illumination property being after occupancy in the MQTT JSON?
In this case I would define the whole JSON message as a Thing, activate the rule by the message changing, and then retrieve the individual properties from the JSON with JSONPATH within the rule, so that they are all available at the same time from the single MQTT message for the rule, from which you could then pass on the proper illumination on to the switch_on_light function.
Unless someone else might know how to reverse the order of the properties with this small delay any another way.
There is no guarantee of the order that an Item gets updated from any binding if one message results in updates to multiple Items. There is no way to control that order.
So your options are:
put the whole JSON into a String Item and parse out the values from the raw message (as @Hans_Lree recommends)
add a timer to the rule to wait half a second or so to give all the Items a chance to update
add checks in the rule and don’t process until all three Items are updated
Option 1 is going to be the most straight forward in this case. You can update the three Items from the rule, keep the Channels in place as you have them now, or remove the three Items if you don’t use them anywhere else.