I am now tracing room occupancy using room-assistant (see room-assistant.io) I am tracking people using iBeacons. I have put the my wife and I into a group called gKCBeacon (ChetBeacon, KathrinBeacon are members).
I have also created 4 room occupancy switches LivingRoom, Bedroom, office, temple (its actually a gym/meditation room). They are in a group called gRoomOccupancy.
I wrote a script to switch on a room when it was occupied:
The above rule works fine. However, after reading a DP I wanted to upgrade this rule. The result is:
rule "Room Occupancy Updater" //Used information from DP: Associated Items
when
Member of gKCBeacon changed
then
gRoomOccupancy.members.forEach[ SwitchItem r |
if (r.state == ON && r.name != ChetBeacon.state || r.name != KathrinBeacon.state) r.sendCommand(OFF)
if (r.state == OFF && r.name == ChetBeacon.state || r.name == KathrinBeacon.state) r.sendCommand(ON)
]
end
The above rule throws no errors, no problems reported in VS Code, but it doesn’t work. The “if” statements are never triggered. I have been staring at this for two days and can’t figure out what’s wrong.
I may have bitten off more than I can chew. Does anyone see an error in the “if” statements, or does the problem lie somewhere else?
Platform information:
Hardware: Gigabyte miniPC i7
OS: _Unbuntu 18.04.04LTS
Java Runtime Environment: openjdk version “1.8.0_232”, Zulu 8.42.0.21-CA-linux32
@5iver Thanks, the “toString” did the trick! Unfortunately the logic is quite right.
My wife and I are in the LivingRoom. The group state is:
LivingRoom ON
Bedroom OFF
Office OFF
Temple OFF
I incorporated your change, then I used MQTT Explorer to change my location to Bedroom. The rule change the group state to:
LivingRoom OFF
Bedroom ON
Office ON
Temple ON
Thanks 5iver. that did it. I was trying out variations on the “room.sendCommand(if (room.state…” line without any luck. Your solution has everything working correctly.
A thousand thank you’s and a big debt of gratitude to you!
With that solved, I will read the link you provided about Area Triggers