How HomeKit Rules Opperate - Same Trigger, Differnt Conditions

Originator:jonw
Number:rdar://28120349 Date Originated:9/1/2016
Status:Open Resolved:No
Product:HomeKit Accessory Certification Product Version:9.3.5
Classification:HomeKit Reproducible:Always
 
Summary:
We are experiencing an issue with how rules are being executed in HomeKit. Each rule consists of a Trigger, a Condition, and a Scene. If the Trigger happens, while the Condition is met, then execute the Scene. The problem we are experiencing is when we have multiple rules with the same Trigger and different Conditions. The rules seem to be executed in sequence and the Condition is checked for every rule individually in sequence rather than being checked initially, at the time of the Trigger, before any rules have been executed. Therefore, if the Scene in rule 1 changes the status of the Condition checked in rule 2, it will affect the execution of rule 2.

Steps to Reproduce:
1. Add a stateless programmable switch (button)
2. Add a Light
3. Set rule one as follows
Trigger - Button Pressed
Condition - Light Off
Scene - Turn Light On
4. Set rule two as follows
Trigger - Button Pressed
Condition - Light On
Scene - Turn Light Off
5. Press the button once and see results
6. Press the button again and see results

Expected Results:
If the Light is off and the button is pressed, the following happens.
1 – Check Rule 1
	1a – Condition is True (Light was off at time of trigger)
	1b – Turn Light On
2 – Check Rule 2
	2a – Condition is False (Light was off at time of trigger)

If the Light is on and the button is pressed, the following happens.
1 – Check Rule 1
	1a – Condition is False (Light was on at time of trigger)
2 – Check Rule 2
	2a – Condition is True (Light was on at time of trigger)
	2b – Turn Light Off

Actual Results:
If the Light is off and the button is pressed, the following happens.
1 – Check Rule 1
	1a – Condition is True (Light is off)
	1b – Turn Light On
2 – Check Rule 2
	2a – Condition is True (Light is on from Scene 1)
	2b – Turn Light Off

If the Light is on and the button is pressed, the following happens.
1 – Check Rule 1
	1a – Condition is False (Light is on)
2 – Check Rule 2
	2a – Condition is True (Light is on)
	2b – Turn Light Off

Version:
iOS 9.3.5

Notes:
I expect, with the rules set up as explained, for the button to toggle the light state once regardless of the light condition. Instead, in one direction, the light is being toggled twice, because the rules are being evaluated and executed in sequence, therefore allowing the first rule to effect the evaluation of the second rule. When the button is pressed once, the light turns on and then off again, because Rule 2 is not parsed until the first scene has already executed. I would suggest reading all applicable Conditions once, at the time of Trigger, and then going through the rules, rather than reading the Conditions separately, in sequence after previous rules have already executed.

Configuration:
This problem happens when the Scene in rule one affects the Condition of rule two.

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!