I use a location/function based convention:
Room_Device_Function
Number LivingRoom_Thermostat_TargetTemp
Switch LivingRoom_WallSwitch_Left
Contact LivingRoom_Window_TopLeft
My groups are plurals:
Group Temperatures
Group:Contact Windows
Group:Contact LivingRoom_Windows
This approach allows this:
and
And results in nice short code.
I have ONE rule for ALL my windows for alarm example
Or this in my heating rules:
rule "Generic Windows Changed"
when
Member of HeatingWindows changed or
Member of Radiators changed
then
if (previousState == NULL) return;
val String room = triggeringItem.name.split("_").get(0)
val GroupItem window = Windows.members.filter[ i | i.name.contains(room) ].head as GroupItem
val SwitchItem radiator = Radiators.members.filter [ i | i.name.contains(room) ].head as SwitchItem
if (radiator.state == ON) {
if (window.state == OPEN) {
sendCommand(room + "_RadiatorValve", "OFF")
postUpdate(room + "_Thermostat_Mode", "off")
}
}
if (radiator.state == OFF) {
if (window.state == CLOSED) {
val offset = House_HeatingOffset.getStateAs(QuantityType).doubleValue
val target = (Targets.members.filter[ i | i.name.contains(room) ].head.state as QuantityType<Number>).doubleValue
val ambient = (AmbientTemps.members.filter[ i | i.name.contains(room) ].head.state as QuantityType<Number>).doubleValue
if (ambient <= (target - (offset / 2))) {
sendCommand(room + "_RadiatorValve", "ON")
postUpdate(room + "_Thermostat_Mode", "heat")
}
}
}
end
If a window in a room is opened and the radiator is on then turn it off and vice versa.
Let’s say that the window SmallBedroom_Window
changed to OPEN
and the
radiator SmallBedroom_RadiatorValve
is ON
The rule goes like this:
room = "SmallBedroom" (String)
window = SmallBedroom_Windows (Group Item Contact)
radiator = SmallBedroom_RadiatorValve (Item)
radiator.state is ON
window.state is OPEN
sendCommand "OFF" to "SmallBedroom_RadiatorValve"
sendCommand "off" to "SmallBedroom_ThermostatMode"
If I closed the window and the radiator is off then the rule checks if the room needs heating and opens the valve if needed
ONE rule for ALL the rooms. That can only work if you have a consistent approach to naming your items.
And using _
to separate the Room_Device_Function
allows the extraction of the Room
or Device
from triggeringItem.name
to be reused to call other related items.
Does it make sense?