[SOLVED] OH2: I am sure there is a better way to write this rule?

Try using Design Pattern: Associated Items

You have already used a good naming convention for your items, so implementing it should be quite easy.

Basically, you rule could be (provided you put all Irrigation*_Valve items in a group Irrigation_Valves):

rule "PumpStation2 update flow and volume"
    when
        Item PumpStation2_Meter received update
    then
        Irrigation_Valves.members.filter([item|item.state == ON]).forEach [ item |
          postUpdate(item.name + "Volume", PumpStation2_Meter.state as Number)
          postUpdate(item.name + "Flow", PumpStation2_Flow.state as Number)
        ]
end

Note: untested and written on my phone, might be syntax errors, but should demonstrate the basic principles.

2 Likes