Rule with lots of Items to update/monitor, looking for ideas to simplify

I have 12 thermostatā€™s that I modify though an HTTP api, Iā€™ve written a script to do the polling and adjusting the settings (setpoint, mode). As an example to get the setpoint for a thermostat I execute script.pl --device 5574 --list setpoint.

Iā€™ve created Item files like this:

Number Thermostat_Setpoint_5574 "Bedroom Setpoint [%.0f Ā°C]" <temperature>  { exec="<[/opt/openhab/configurations/scripts/script.pl --device 5574 --list setpoint:60000:REGEX((.*?))]" }

To update the setpoint I execute script.pl --device 5574 --setpoint 21. This is working well the issue is doing this with rules. The only way Iā€™ve come up with so far is to create a rule executes the script for each item:

rule "Update Thermostat_Setpoint_5574"
when
    Item Thermostat_Setpoint_5574 received command
then
    executeCommandLine("/opt/openhab/configurations/scripts/script.pl --device 5574 --setpoint " + Thermostat_Setpoint_5574.state)
end
```

That means creating 12 rules. I'd love to hear if there's a better/cleaner way.

Search for ā€œDesign Patternsā€ on the forum and you should find a postING dominated with stuff from me and bob_dickenson. Scroll down to my posting about Group and Loop. That should give you some ideas on how you can merge your 12 rules into one.

here is the posting. I have it bookmarked :smile:

Start Edit
Looks like an issue with my persistence, Iā€™ve been reading through a bunch of threads and I canā€™t seem to find the correct syntax to grab all the items in a group. I tried this but doesnā€™t seem to work:gThermostatMode*,gThermostatSetpoint : strategy = everyChange, restoreOnStartup

Only way I got it to work was to add each item to the persistence.

2nd Edit
Actually the rule always returns the same Item having been changed. Canā€™t figure out whatā€™s wrong.
End Edit

Thanks for the guidance! Iā€™m hitting a wall and I canā€™t figure out what the issue is, figured Iā€™d post and Iā€™m sure someone will know.

My rule is working fine if thereā€™s only one item in my group, if there is two I get:````
2016-05-22 08:58:31.890 [ERROR] [o.o.c.s.ScriptExecutionThread ] - Error during the execution of rule 'gThermostatMode Ruleā€™
java.lang.NullPointerException: null

Rule:````
rule "gThermostatMode Rule"
when
        Item gThermostatMode received update
then
        Thread::sleep(100) // give lastUpdate time to be populated
        val mostRecent = gThermostatMode.members.sortBy[lastUpdate].last
        logInfo("Thermostat", "gThermostatMode " + mostRecent.name)
end

Item:````
Number Thermostat_Mode_5198 ā€œDen Modeā€ (gThermostatMode) { exec="<[/opt/openhab/configurations/scripts/script.pl --device 5198 --list mode:60000:REGEX((.?))]" }
Number Thermostat_Mode_5194 ā€œDinning Room Modeā€ (gThermostatMode) { exec="<[/opt/openhab/configurations/scripts/script.pl --device 5194 --list mode:60000:REGEX((.
?))]" }

I donā€™t have time to fully analyze your rule right now, but I had what I think was a similar problem which I fixed by using everyUpdate as opposed to everyChange. When you use everyChange, if you receive a new state that is the same as the old state it doesnā€™t get persisted and therefore the timestamp of your lastUpdate doesnā€™t update.