I don’t know how one would even approach iPhone detection using the http binding.
This uses a special command line too called hping3 to send a special type of pocket to wake up the phone then looks for the phone’s response to see is it is still on the network despite being asleep and not responding to pings.
The newest Network binding does this with arping so a separate script like this is no longer needed. There is also an iCloud binding that can get the phone’s location through Apple’s servers.
Thanks for the good explanation - even for beginners
I implemented as you described and the script runs quite nice when executed from the command line.
But after setting up in openhab2 i always get the following error
2017-11-16 15:35:13.142 [ERROR] [ntime.internal.engine.ExecuteRuleJob] - Error during the execution of rule Find My iPhone: The argument ‘state’ must not be null or empty.
Also, be aware that the newest version of the Network Binding supports this through arping and if you have an iPhone there is a iCloud Binding, also available in the SNAPSHOT that works as well for iPhone presence detection.
OK - I tried the example from the network binding page.
i manually added a thing, item and a sitemap. installed arping. everything fine - no errors.
But the outcome for all channels (online/lastseen/latency) is always “-”.
What am i doing wrong?
sitemap iphone label="Main Menu"
{
Frame {
Text item=PhoneS label="iPhone Stefan [%s]"
Text item=PhoneSlastseen label="lastSeen [%s]"
Text item=PhoneSResponseTime label="Response Time [%s]"
}
}
I have been working for hours now on my presence detection rule following the tutorial by @Maurits28 in the first post.
Ive got the script working and i even verified that it updates the correct item.
This is my modified version of the rule:
var Number SmartphoneCounter = 0
val Number MaxCounter = 18
rule "Execute script SmartphonePresence"
when
Time cron "0 * * * * ?"
then
var String Polling = executeCommandLine("sudo@@bash@@/opt/RunarMobil.sh", 5000)
RunarMobil.postUpdate(Polling)
logInfo("Test", Polling)
end
rule "Determine presence of Runarmobil"
when
Item RunarMobil received update
then {
if(RunarMobil.state == "OFF") {
SmartphoneCounter = SmartphoneCounter + 1
if(SmartphoneCounter > MaxCounter) {
RunarMobil_Sw.sendCommand(OFF)
SmartphoneCounter = 0
logInfo("RULE","Smartphone Counter reached threshold and sent command OFF. Counter set to 0")
}
else {
logInfo("RULE","Counter Smartphone threshold not yet reached. Counter set to " + SmartphoneCounter)
}
}
else {
RunarMobil_Sw.sendCommand(ON)
SmartphoneCounter = 0
logInfo("RULE","RunarMobil_Sw received command ON. Counter reset to 0")
}
}
end
And here is what the log shows:
2018-01-06 14:56:01.359 [INFO ] [.eclipse.smarthome.model.script.RULE] - RunarMobil_Sw received command ON. Counter reset to 0
2018-01-06 14:57:01.397 [INFO ] [.eclipse.smarthome.model.script.Test] - Smartphone 10.0.0.110 is not present
==> /var/log/openhab2/events.log <==
2018-01-06 14:57:01.416 [ome.event.ItemCommandEvent] - Item 'RunarMobil_Sw' received command ON
==> /var/log/openhab2/openhab.log <==
2018-01-06 14:57:01.416 [INFO ] [.eclipse.smarthome.model.script.RULE] - RunarMobil_Sw received command ON. Counter reset to 0
2018-01-06 14:58:01.334 [INFO ] [.eclipse.smarthome.model.script.Test] - Smartphone 10.0.0.110 is not present
==> /var/log/openhab2/events.log <==
2018-01-06 14:58:01.351 [ome.event.ItemCommandEvent] - Item 'RunarMobil_Sw' received command ON
==> /var/log/openhab2/openhab.log <==
2018-01-06 14:58:01.363 [INFO ] [.eclipse.smarthome.model.script.RULE] - RunarMobil_Sw received command ON. Counter reset to 0
2018-01-06 14:59:01.341 [INFO ] [.eclipse.smarthome.model.script.Test] - Smartphone 10.0.0.110 is not present
==> /var/log/openhab2/events.log <==
2018-01-06 14:59:01.364 [ome.event.ItemCommandEvent] - Item 'RunarMobil_Sw' received command ON
==> /var/log/openhab2/openhab.log <==
2018-01-06 14:59:01.377 [INFO ] [.eclipse.smarthome.model.script.RULE] - RunarMobil_Sw received command ON. Counter reset to 0
2018-01-06 15:00:01.342 [INFO ] [.eclipse.smarthome.model.script.Test] - Smartphone 10.0.0.110 is not present
==> /var/log/openhab2/events.log <==
2018-01-06 15:00:01.373 [ome.event.ItemCommandEvent] - Item 'RunarMobil_Sw' received command ON
==> /var/log/openhab2/openhab.log <==
2018-01-06 15:00:01.372 [INFO ] [.eclipse.smarthome.model.script.RULE] - RunarMobil_Sw received command ON. Counter reset to 0
2018-01-06 15:01:01.362 [INFO ] [.eclipse.smarthome.model.script.Test] - Smartphone 10.0.0.110 is not present
==> /var/log/openhab2/events.log <==
2018-01-06 15:01:01.385 [ome.event.ItemCommandEvent] - Item 'RunarMobil_Sw' received command ON
==> /var/log/openhab2/openhab.log <==
2018-01-06 15:01:01.386 [INFO ] [.eclipse.smarthome.model.script.RULE] - RunarMobil_Sw received command ON. Counter reset to 0
2018-01-06 15:02:01.387 [INFO ] [.eclipse.smarthome.model.script.Test] - Smartphone 10.0.0.110 is not present
2018-01-06 15:02:01.407 [INFO ] [.eclipse.smarthome.model.script.RULE] - RunarMobil_Sw received command ON. Counter reset to 0
==> /var/log/openhab2/events.log <==
2018-01-06 15:02:01.407 [ome.event.ItemCommandEvent] - Item 'RunarMobil_Sw' received command ON
To me it looks like the rule “Execute script SmartphonePresence” in combination with the script does what its supposed to do. Im wondering if someone with the right expertise can spot the problem. I’ve spent hours upon hours now looking for the problem but cannot figure this out. My prime suspect is those curly brackets hanging around inside the rule and make no sense to me.
Looked up the item receiving the status update from the script using Openhab Rest API - http://openhabianpi:8080/doc/index.html#!/items/getPlainItemState
Seems like we have found a clue on what’s going on we my failing presence detection.
This is the response:
Response Body
Smartphone 10.0.0.110 is not present
Response Code
200
Response Headers
{
"content-length": "36",
"server": "Jetty(9.3.22.v20171030)",
"content-type": "text/plain"
}
wtf? I was expecting a ON or OFF value here… If this is the string output i clearly cannot use this item in the if-statement in my rule:
if(RunarMobil.state == "OFF")
I’m wondering if im supposed to use a second item (the device item) in this part of the rule?
Thank you for trying to help me.
No. As i stated i was following the tutorial in the very first post by @Maurits28. If you think you see the problem i need a guiding hand here.
Edit: Last Q - No i was not aware of that. please provide a link where i can read me up on the topic?
You need to be on 2.2 release. See the readme for the Network binding. All the stuff talking about arping is basically talking about the binding doing what this script does.
Ah!!! Totally missed this. I know i’ve read this before and have actually been taking advantage of this without even realizing that i was. I’m on Openhabian 1.4 and i assume this “arping service” was included in the bundle. As a novice on Raspberry Pi and its operating system i find myself lost all the time in the jungle of different solutions and software-versions. This was one of these moments. Spent several hours trying to get this to work…
If i understand this correct i need to write me a rule that take into consideration “flapping” to avoid unintended action triggered and maybee use the DHCP request from the Android phone as a “reentry trigger” in my presence rule.
Thanx for helping me out Rich !
One last quick question. Im planning to follow this example: Generic Presence Detection
I’m not barking up the wrong tree here again?
It seems clean and simple so i think i’ll be able to work that solution out on my own.
I’ve used that for years now and it still works fine. It is what I would recommend for flapping and in case you ever decide to add more sensors for each person.
I run in Docker and don’t want to run OH as root so I don’t use the arping feature. I have an external python script that executes a version of the above script for me. Others have reported great success with the arping feature of the Network binding.