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.