See Design Pattern: Cascading Timers for one such approach. Essentially what you need to do is parse out the pump station number valve number from the Item name that triggers the Rule. That tells you the valve that turned off. Then you can use those numbers to build the Item names and MQTT Topic names to send the messages to.
Put all the Irrigation Items into a Group, I’ll call it PumpStation1. If you have more than one PumpStations you might consider similarly parsing the pumpstation number out of the Item name.
import org.eclipse.smarthome.model.script.ScriptServiceUtil
rule "PumpStation1 Irrigation Item received command OFF"
when
Member of PumpStation1 received command OFF
then
val parts = triggeringItem.name.split('_')
val valve = parts.get(1)
val valveFlow = PumpStation1_Flow.state as Number
val valveVolume = (PumpStation1_Meter.state as Number) - PumpStation1_MemoriseMeterRead // gloval variable?
val topicRoot = "ArgyleCourt/Property/PumpStation1/"
// MQTT 1.x version
publish("mymosquitto", topicRoot+"Flow"+valve, valveFlow.toString)
publish("mymosquitto", topicRoot+"Volume"+valve, valveVolume.toString)
// MQTT 2.x version
// val mqttActions = getActions("mqtt","mqtt:broker:mymosquitto") // use Thing ID for broker Thing
// mqttActions.publishMQTT(topicRoot+"Flow"+valve, valveFlow.toString)
// mqttActions.publishMQTT(TopicRoot+"Volvume"+valve, valveVolume.toString)
PumpStation1_LastSessionMemory.postUpdate((PumpStation1_LastSessionMemory.state as Number) + valveVolume)
end
The above is a pretty straight forward application of Design Pattern: Associated Items and Design Pattern: How to Structure a Rule.
Note I just typed in the above. There are surely errors.
Note that 1.x bindings (i.e. those that do not use Things) are not and will not be supported on OH 3.