I just uploaded some code to github that uses some of the techniques in this pattern.
I have temperature sensors and smart vents in a bunch of different rooms in my house, and I use this code to manage the smart vent states. I have it set up so that I can use the thermostat set point for heat/cool target or override the target temperature by room. It is also possible to turn individual room control on and off manually or via other external rules.
Just thought I’d share in case it’s useful to anybody else.
Is there any solution to this problem with DateTime groups, @rlkoshak … 2 years later? According to the openHAB docs MIN/MAX should work on decimal types only.
The updates to the docs are the solution. This used to work in OH 1.8 but did what ever reason, they decided not to support DateTime any more. There were lots of bugs and changes necessary to the aggregation functions at that time which probably broke DateTime, and the fact it worked before that may have been a fluke.
I’m using the following rule to alert me when my plants need water:
rule "Planten water geven"
when
Member of gMoistures changed //or
// Item test_switch changed
then
val StringBuilder sb = new StringBuilder
gMoistures.allMembers.filter[ i | i.state <= 30].forEach[i | sb.append(transform("MAP", "plants.map", i.name) + "\n") ]
if (sb.length < 1){
return;
} else {
logInfo("notifications", "Sending notification via mail." + gMoistures.members.filter[ e | e.state <= 30])
sendMail("xxx", "Planten water geven", "De volgende plant(en) heeft/hebben dorst: \n\n" +sb)
}
end
But I have the idea I’ve overcomplicated things. When I use Member of gMoistures changed the rule only runs on the member that triggered the rule, right? Isn’t there an easier way to only check the item that trigger the rule for <=30 instead of searching all group members for that value?
The former should be: all the direct members of the Group. In other words, if you define:
Group grpA
Group grpB (grpA)
Group grpC (grpA)
String strA (grpA)
String strB (grpB)
String strC (grpC)
Then grpA.members returns the following items:
grpB
grpC
strA
And grpA.allMembers returns only non-group items by resolving all groups into their items. In the example above, grpA.allMembers returns the following items:
I never used Jython myself (although I will probably start to in the near future), but I think you can just use two list comprehensions to achieve this (somebody correct me if I am wrong with this ):
temperature_list = [i.name for i in ir.getItem('gTemperatures').members]
livingroom_temperatures = [i for i in ir.getItem('gLivingroom').members if i.name in temperature_list]
you could also make two sets out of your groups and intersect them.
I answered someone else a couple days ago (I’ll add this to the docs)…
Here are a couple more examples that will be in the helper library docs…
list_of_items = [item for item in itemRegistry.getItem("gDS_FamilyRoom").members if "gMotion_Sensor" in item.groupNames]
# or
list_of_items = [item for item in itemRegistry.getItem("gDS_FamilyRoom").members if item in itemRegistry.getItem("gMotion_Sensor").members]
# or
list_of_items = [item for item in itemRegistry.getItem("gMotion_Sensor").members if item in itemRegistry.getItem("gDownstairs").allMembers]