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.
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.
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
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.