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 --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/ --device 5574 --list setpoint:60000:REGEX((.*?))]" }

To update the setpoint I execute --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"
    Item Thermostat_Setpoint_5574 received command
    executeCommandLine("/opt/openhab/configurations/scripts/ --device 5574 --setpoint " + Thermostat_Setpoint_5574.state)

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 "gThermostatMode Rule"
        Item gThermostatMode received update
        Thread::sleep(100) // give lastUpdate time to be populated
        val mostRecent = gThermostatMode.members.sortBy[lastUpdate].last
        logInfo("Thermostat", "gThermostatMode " +

Number Thermostat_Mode_5198 “Den Mode” (gThermostatMode) { exec="<[/opt/openhab/configurations/scripts/ --device 5198 --list mode:60000:REGEX((.?))]" }
Number Thermostat_Mode_5194 “Dinning Room Mode” (gThermostatMode) { exec="<[/opt/openhab/configurations/scripts/ --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.