For me to understand & learn:
Wouldn’t this mean that if it takes the camera 1000ms to respond to the move request, it will make the rule wait for a whole second?
If my understanding is correct, why would you prefer the rule to wait for 1 second over using a timer thread? Because there are only 2 timer threads and 5 rule threads?
You are correct.
The reason for this is that the “Start Video recording” and “Stop video recording” are at the same part of the code, while the “Run PHP file” is in a later part of the code, which calls the PHP file with a parameter, based on an “if” clause.
Based on reading your Design Pattern: How to Structure a Rule, I assume I should build the HTTP string in the “if” clause, and only then create a single timer with the 2 HTTP calls:
One “static” to Start Video recording
Second “dynamic” (which was built in the “if” clause) to run the PHP file.
Am I correct?
EDIT:
While waiting for your answer, I tried modifying the rule, but I receive an error in VS.
The error is:
Cannot refer to the non-final variable httpPHPStr inside a lambda expression
The modified rule:
rule EntranceDoor Opened
when
Item iEntranceDoorSensor changed to OPEN
then
createTimer(now.plusMillis(1), [ |
sendHttpGetRequest(". . . . .", 1000) // Move camera to face door
])
var httpPHPStr = "http://192.168.1.111/SendMailOpenHAB.php?id=3" // Parents at home
if (ParentsNotAtHome) {
if (KidsAtHome) {
httpPHPStr = "http://192.168.1.111/SendMailOpenHAB.php?id=1" // Kids Home Alone
} else {
httpPHPStr = "http://192.168.1.111/SendMailOpenHAB.php?id=2" // Home is Empty
}
}
createTimer(now.plusSeconds(1), [ |
sendHttpGetRequest(". . . . .", 1000) // Start Video recording
sendHttpGetRequest(httpPHPStr, 1000) // Run PHP file that checks what is the latest file NOW but sends it in 30 seconds
])
createTimer(now.plusSeconds(15), [ |
sendHttpGetRequest(". . . . .", 1000) // Stop Video recording
])
end
I assume this is because the httpPHPStr variable is not defined within the createTimer.
How should I tackle this?
Or does it mean I cannot use your DP in this case?