acutally i am checking my openhab logs and i found this entry, but dont really know whats wrong in my rule.
Maybe someone could help me solving this.
This is the log entry:
21:31:22.677 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'iPhone_IG_Distance' changed from 10329 to 10335
21:31:22.678 [INFO ] [nhab.core.model.script.iPhone IG Home] - iPhone IG is away. (Distance: 10335 m)
21:31:22.679 [ERROR] [.internal.handler.ScriptActionHandler] - Script execution of rule with UID 'anwesenheit-5' failed: An error occurred during the script execution: index=1, size=1 in anwesenheit
And this is the triggered rule:
rule "presence by location IG"
when
Item iPhone_IG_Distance changed
then
if (( iPhone_IG_Distance.state > 200) && ( iPhone_IG_LocationAccuracy.state < 100) ) {
Home_Anwesenheit_IG.postUpdate(OFF)
logInfo("iPhone IG Home", "iPhone IG is away. (Distance: "+iPhone_IG_Distance.state+" m)")
}
if ( iPhone_IG_Distance.state <= 200) {
Home_Anwesenheit_IG.postUpdate(ON)
logInfo("iPhone IG Home", "iPhone IG is at home. (Distance: "+iPhone_IG_Distance.state+" m)")
}
else {
logInfo("Fehler bei Berechnung Anwesenheit IG: Status Anwesenheit: "+Home_Anwesenheit_IG.state+", Status Distanz: "+iPhone_IG_Distance.state+", Messgenauigkeit: "+iPhone_IG_LocationAccuracy.state+".")
}
end
rule "presence by location IG"
when
Item iPhone_IG_Distance changed
then
if (( iPhone_IG_Distance.state > 200) && ( iPhone_IG_LocationAccuracy.state < 100) ) {
Home_Anwesenheit_IG.postUpdate(OFF)
// logInfo("iPhone IG Home", "iPhone IG is away. (Distance: "+iPhone_IG_Distance.state+" m)")
logInfo("iPhone IG is away. (Distance: "+iPhone_IG_Distance.state+" m)")
}
if ( iPhone_IG_Distance.state <= 200) {
Home_Anwesenheit_IG.postUpdate(ON)
// logInfo("iPhone IG Home", "iPhone IG is at home. (Distance: "+iPhone_IG_Distance.state+" m)")
logInfo("iPhone IG is at home. (Distance: "+iPhone_IG_Distance.state+" m)")
}
else {
logInfo("Fehler bei Berechnung Anwesenheit IG: Status Anwesenheit: "+Home_Anwesenheit_IG.state+", Status Distanz: "+iPhone_IG_Distance.state+", Messgenauigkeit: "+iPhone_IG_LocationAccuracy.state+".")
}
end
But now the log entry is missing complete:
13:04:03.425 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'iPhone_IG_Distance' changed from 6824 to 4860
13:04:03.426 [ERROR] [.internal.handler.ScriptActionHandler] - Script execution of rule with UID 'anwesenheit-5' failed: An error occurred during the script execution: index=1, size=1 in anwesenheit
I think this is the reason, why i used two strings.
rule "presence by location AG"
when
Item iPhone_AG_Distance changed
then
if (( iPhone_AG_Distance.state > 200) && ( iPhone_AG_LocationAccuracy.state < 100) ) {
Home_Anwesenheit_AG.postUpdate(OFF)
logInfo("iPhone AG Home", "iPhone AG is away. (Distance: "+iPhone_AG_Distance+" m)")
}
if ( iPhone_AG_Distance.state <= 200) {
Home_Anwesenheit_AG.postUpdate(ON)
logInfo("iPhone AG Home", "iPhone AG is at home. (Distance: "+iPhone_AG_Distance+" m)")
}
else {
logInfo("iPhone AG Home", "Fehler bei Berechnung Anwesenheit AG: Status Anwesenheit: "+Home_Anwesenheit_AG.state+", Status Distanz: "+iPhone_AG_Distance.state+", Messgenauigkeit: "+iPhone_AG_LocationAccuracy.state+".")
}
end
logInfo("iPhone AG Home", "iPhone AG is away. (Distance: "+iPhone_AG_Distance+" m)")
I think you should use iPhone_AG_Distance.state
This applies also to other logInfo statements
The second point is that (at least from my understanding) every time the distance is > 200 you will run into the “else” branch and log an error. Is that intended? Perhaps there should be a “return” at the end of your first if-block