Clearly im doing something wrong, but the log shows double entries and matches against something it shouldnt , gPresenceSensors OFF when its actually ON
EDIT: else, should be else if right!?
rule "Blue Iris Motion Changes based on Presence & Time of Day"
when
Item gPresenceSensors received update
then
if(gPresenceSensors.state == ON && vTimeOfDay.state == "DAY"){ // If we are home and its day time, turn off Motion
sendHttpGetRequest("http://192.168.0.4:82/admin?profile=3&user=Kris&pw=xx!")
logInfo("Blue Iris", "Selective motion recording OFF because someone came home and its day")
}
if(gPresenceSensors.state == ON && vTimeOfDay.state == "NIGHT" || vTimeOfDay.state == "EVENING"){ // If we are home and its night time, turn on Motion
sendHttpGetRequest("http://192.168.0.4:82/admin?profile=4&user=Kris&pw=xxx!")
logInfo("Blue Iris", "It's night time so all motion recording ON")
}
else(gPresenceSensors.state == OFF){ // If no one is home, turn on Motion Recording
sendHttpGetRequest("http://192.168.0.4:82/admin?profile=2&user=Kris&pw=xxx")
logInfo("Blue Iris", "Motion recording ON as no one is home")
}
end
And the log entry
20:15:18.850 [INFO ] [ipse.smarthome.model.script.Blue Iris] - It's night time so all motion recording ON
20:15:18.886 [INFO ] [ipse.smarthome.model.script.Blue Iris] - Motion recording ON as no one is home
20:15:18.930 [INFO ] [ipse.smarthome.model.script.Blue Iris] - Motion recording ON as no one is home
First of all, your else has a condition - I think you would need an else if in this case.
Secondly, it looks like you want to check the presence and if it is either NIGHT or EVENING. Be careful with the OR statement, bacause now this is true even if it’s EVENING and presence is OFF.
Probably you’ll have to fold it a bit using nested if statements.
rule "Blue Iris Motion Changes based on Presence & Time of Day"
when
Item gPresenceSensors received update
then
if(gPresenceSensors.state == ON && vTimeOfDay.state == "DAY"){ // If we are home and its day time, turn off Motion
sendHttpGetRequest("http://192.168.0.4:82/admin?profile=3&user=Kris&pw=xx")
logInfo("Blue Iris", "Selective motion recording ON because someone came home and its day")
}
if(gPresenceSensors.state == ON && vTimeOfDay.state == "NIGHT"){ // If we are home and its night time, turn on Motion
sendHttpGetRequest("http://192.168.0.4:82/admin?profile=4&user=Kris&pw=xx")
logInfo("Blue Iris", "It's night time so selective motion recording ON")
}
if(gPresenceSensors.state == ON && vTimeOfDay.state == "EVENING"){ // If we are home and its evening, turn on Motion
sendHttpGetRequest("http://192.168.0.4:82/admin?profile=4&user=Kris&pw=xx!")
logInfo("Blue Iris", "It's night time so selective motion recording ON")
}
else if(gPresenceSensors.state == OFF){ // If no one is home, turn on Motion Recording
sendHttpGetRequest("http://192.168.0.4:82/admin?profile=2&user=Kris&pw=xxx")
logInfo("Blue Iris", "All motion recording ON as no one is home")
}
end
It seems the double log entry is still present
20:49:20.250 [INFO ] [ipse.smarthome.model.script.Blue Iris] - It's night time so selective motion recording ON
20:49:20.250 [INFO ] [ipse.smarthome.model.script.Blue Iris] - It's night time so selective motion recording ON
Put a logInfo right at the beginning of the rule, I guess the rule is called twice. You could have a more precise trigger in the “when” clause and spit your rule in two, one for ON and one for OFF.
As lostcontrol said, your rule might be triggered twice.
You can use the rule locking as described in here (your code needs to go in the section where the rule is skipped if a lock is present).
Splitting it sounds like an option. Should this be received update?
rule "Blue Iris Motion Changes based on Presence & Time of Day"
when
Item gPresenceSensors received update
then
if(gPresenceSensors.state == ON && vTimeOfDay.state == "DAY"){ // If we are home and its day time, turn off Motion
sendHttpGetRequest("http://192.168.0.4:82/admin?profile=3&user=Kris&pw=xx")
logInfo("Blue Iris", "Selective motion recording ON because someone came home and its day")
}
if(gPresenceSensors.state == ON && vTimeOfDay.state == "NIGHT"){ // If we are home and its night time, turn on Motion
sendHttpGetRequest("http://192.168.0.4:82/admin?profile=4&user=Kris&pw=Sxx")
logInfo("Blue Iris", "It's night time so selective motion recording ON")
}
if(gPresenceSensors.state == ON && vTimeOfDay.state == "EVENING"){ // If we are home and its evening, turn on Motion
sendHttpGetRequest("http://192.168.0.4:82/admin?profile=4&user=Kris&pw=xxx")
logInfo("Blue Iris", "It's night time so selective motion recording ON")
}
end
rule "Blue Iris Motion Changes based on Presence & Time of Day"
when
Item gPresenceSensors received update
then
if(gPresenceSensors.state == OFF){ // If no one is home, turn on Motion Recording
sendHttpGetRequest("http://192.168.0.4:82/admin?profile=2&user=Kris&pw=xxx")
logInfo("Blue Iris", "All motion recording ON as no one is home")
}
end
When a member of a Group receives and update the new state of the Group gets calculated incrementally. It iterates through the members of the Group to aggregate the values (e.g. MIN, SUM, AND). Each step through the loop it updates the Group’s state.
So every time there is an update to a member of a Group, the Group will receive N-1 updated as a result and consequently your Rule will trigger N-1 times (where N is the number of members of the Group).
This is why the Rule triggers more than once.
Using changed or Member of are better choices when triggering Rules by Groups.
Be very very very very careful using locks. The slightest error can cause the finally block to never execute and therefore the lock never gets unlocked and if you have a lot of members of a Group, they will use up all the available Rule Runtime Threads waiting for access to the lock.
We should all go to great lengths including considering a different approach or exporting the work to an external script to avoid locks unless it is impossible.
So it doesnt appear that member of, or changed to is working well. Without the presence checks, its not changing. Right now its evening, but its still showing on the day profile. Because the presence is on its not changing over… Its almost like it needs to change to received an update, but then also check if its on
rule "Blue Iris Motion Changes based on Presence & Time of Day"
when
Item gPresenceSensors changed to ON
then
if(vTimeOfDay.state == "DAY"){ // If we are home and its day time, turn off Motion
sendHttpGetRequest("http://192.168.0.4:82/admin?profile=3&user=Kris&pw=Spooties1!")
logInfo("Blue Iris", "Selective motion recording ON because someone came home and its day")
}
if(vTimeOfDay.state == "NIGHT"){ // If we are home and its night time, turn on Motion
sendHttpGetRequest("http://192.168.0.4:82/admin?profile=4&user=Kris&pw=Spooties1!")
logInfo("Blue Iris", "It's night time so selective motion recording ON")
}
if(vTimeOfDay.state == "EVENING"){ // If we are home and its evening, turn on Motion
sendHttpGetRequest("http://192.168.0.4:82/admin?profile=4&user=Kris&pw=Spooties1!")
logInfo("Blue Iris", "It's night time so selective motion recording ON")
}
end
Remember that Rules trigger based on events. If the Rule needs to do something when vTimeOfDay changes in addition to when gPresenceSensors changes then you need to trigger the Rule by vTimeOfDay too.