My issue is the rules are not firing reliably. I figured maybe it was an issue of still being in bata as these exact same rules run perfectly fine unmodified under OH1. I keep upgrading to the latest snapshot but every attempt to move to OH2 fails, HARD! There’s really nothing special about my rules and OH2 should be far enough along where basic rules wouldn’t be a problem (please correct me if i’m wrong). So either my rules are shitty, i found a bug, or something changed in rule execution that my rules can’t adjust to. I’m not a programmer and these rules represent my best attempt so the issue could very well be in my rules.
Below are 2 of my rules. The first rule is one of 4 rules that respond to sensors (PIR and door contacts). They respond to different sensors and each sets a unique value. The second rule responds to the changes of the item the 1st rule(s) handles and this particular rule is for the ceiling lights. I have similar rules as the second rule for Security, Media, and heating and they all respond simultaneously to the first rule(s). They’re essentially the same syntax as my ceiling example thanks to my naming convention and the find and replace function in notepad++.
Now that you have a little back story, here are the details:
As you can see the first rule sends a command to the string item “TVRoomPresenceSwitch”. The snippet I provided writes “Active” to the string. There’s a rule block to write Inactive, Standby, etc. This works, checking the logs, REST, and the database (i’m using JDBC MySQL for persistence), this first part seems to work as expected every time.
The second rule(s) is supposed to trigger when TVRoomPresenceSwitch receives a command. This is were the problem is. This does not always happen. For instance, my TV room ceiling lights were on all night because when TVRoomPresenceSwitch was changed to Inactive, the rule never triggered to change the lighting mode to off. However around 3:00AM when (i’m assuming) my wife was in the TV room. Not only did all the rules fire as expected when she approached and entered the room, but when she was done the lights turned off on their own as expected. The logs confirms this. During testing simply doing a touch on the affected rule file from command line would trigger all the rules that should have triggered but didn’t. For ease of programming and to keep things as modular as possible, I have rules very similar to the second one for every device i’m controlling. I opted to not have one rule block control all the lights at this level. Going back to last night, my ceiling lights and under cabinet lights remained on, while my floor lamp and projector fixtures turned off. These are 4 independently controlled lights both physically and via OH. They’re a mix of Hue and Zwave. The rule files are basically the same as I created it once and did a find and replace to make 4 unique files. For some reason, 2 worked last night and 2 didn’t. It’s not always the same 2, and the failure isn’t always in the same place. For instance, there have been times where upon entering the room one or more lights didn’t turn on, which would indicate the rules didn’t notice TVRoomPresenceSwitch was changed to Active. There are also times when everything works as expected, just not for long (hours).
Hopefully you’re still with me after all that reading. If it’s an OH2 issue then that’s okay and i’ll help where I can. But I guess I would like you all to look at the rule blocks so I can rule out a run-time issue and focus on improving the rules. I’m also hoping you all can advise on how to make the rules more OH2 compatible (if that’s even a thing one could do).
Rule 1:
rule "TVRoom Active Presence Detected" when System started or Item TVRoomPresenceGroup received update or //Item TVRoomPresenceGroup changed then logDebug("TVRoom", "Active Presence Detection - Presence Starting") if(TVRoomPresenceOverride.state != ON){ logDebug("TVRoom", "Active Presence Detection - Room Override OFF") if (!TVRoomPresenceSwitch.state.toString.equals("Active")) { logDebug("TVRoom", "Active Presence Detection - Room NOT Active") if(TVRoomPresenceGroup.members.filter(s | s.state == ON).size > 0) { logDebug("TVRoom", "Active Presence Detection - ELSE - Room Sensors ACTIVE") logDebug("TVRoom", "Active Presence Detection - Room set to ACTIVE") sendCommand(TVRoomPresenceSwitch, ("Active")) } } } end
Rule2:
rule "TVRoom Ceiling Light Mode Selection" when System started or Item TVRoomPresenceSwitch received command then logDebug("TVRoom", "Lighting Ceiling - Mode Selection - Starting") if(TVRoomPresenceSwitch.state.toString.equals("Startup")){ logDebug("TVRoom", "Lighting Ceiling - Mode Selection - Startup Mode") TVRoom_Ceiling_LightingAutomation.sendCommand(1) logInfo("TVRoom", "Lighting Ceiling - Mode Selection - Mode 1") } else if(TVRoomPresenceSwitch.state.toString.equals("Standby")){ logDebug("TVRoom", "Lighting Ceiling - Mode Selection - Standby Mode") TVRoom_Ceiling_LightingAutomation.sendCommand(12) logInfo("TVRoom", "Lighting Ceiling - Mode Selection - Mode 12") if(TVRoom_Ceiling_Lights_OUT_counter!=null){ logDebug("TVRoom", "Lighting Ceiling - Mode Selection - Standby Mode - TVRoom Lights OUT Timer Canceled") TVRoom_Ceiling_Lights_OUT_counter.cancel TVRoom_Ceiling_Lights_OUT_counter = null } } else if(TVRoomPresenceSwitch.state.toString.equals("Active")){ logDebug("TVRoom", "Lighting Ceiling - Mode Selection - Active Mode") TVRoom_Ceiling_LightingAutomation.sendCommand(2) logInfo("TVRoom", "Lighting Ceiling - Mode Selection - Mode 2") if(TVRoom_Ceiling_Lights_OUT_counter!=null){ logDebug("TVRoom", "Lighting Ceiling - Mode Selection - Active Mode - TVRoom Lights OUT Timer Canceled") TVRoom_Ceiling_Lights_OUT_counter.cancel TVRoom_Ceiling_Lights_OUT_counter = null } } else if(TVRoomPresenceSwitch.state.toString.equals("Manual")){ logDebug("TVRoom", "Lighting Ceiling - Mode Selection - Manual Mode") TVRoom_Ceiling_LightingAutomation.sendCommand(9) logInfo("TVRoom", "Lighting Ceiling - Mode Selection - Mode 9") if(TVRoom_Ceiling_Lights_OUT_counter!=null){ logDebug("TVRoom", "Lighting Ceiling - Mode Selection - Manual Mode - TVRoom Lights OUT Timer Canceled") TVRoom_Ceiling_Lights_OUT_counter.cancel TVRoom_Ceiling_Lights_OUT_counter = null } } else if(TVRoomPresenceSwitch.state.toString.equals("Inactive")){ logDebug("TVRoom", "Lighting Ceiling - Mode Selection - Inactive Mode") TVRoom_Ceiling_LightingAutomation.sendCommand(10) logInfo("TVRoom", "Lighting Ceiling - Mode Selection - Mode 10") } end