If you intend on editing files on Windows using notepad this will be a perennial problem.

No, I use Designer to edit any OpenHAB files since it will show line errors in the file, but I did have to create this one using Notepad. I do have Notepad++, so I'll use it in the future. I recreated the script in Nano and can view it in Designer with no errors. When I run

in your script directory and post the result here. We have so see if your script is executable (that was maybe the reason for the "permission denied"). Furthermore you made a second try starting the script with "iphoneDetect.sh", but the correct name is "iPhoneDetect.sh" (with a capital P). Maybe that's the reason why you became a "command not found".

You can try to execute the script (while you are in the correct directory) with: ./iPhoneDetect.sh

I have a working iPhone detection using the exec-Binding and a Bash script, just like you want to do it. It was mainly a matter of permissions and user rights to get this working. But as Rich already mentioned, this is clearly no real beginner stuff. You should at first get a little more comfortable with Linux as an OS.

They are permanently set. The difference is: When you manually start the script (like you just did), you execute it as User "pi". When Openhab executes the script with the exec binding, it executes the script with the user "openhab". We have to make sure that this is allowed (which we did with chmod 777).

Next step: Please quote the current content of your iPhoneDetect.sh script. I want to compare it with my script (but I can't do this until this evening when I am at home). Try to get this with using nano on your ssh shell (type: nano iPhoneDetect.sh).

Furthermore we have to take care that the included commands in the script (like hping3) also are allowed to be executed by the user openhab. We have to edit the /etc/sudoers file for this. But one step at a time...

This allows the programs of the script to be executed by the user openhab. Save your changes and exit the editor.CAUTION: This is a sensible file. Don't mess up the file or modify/delete any of the other content.

This is a sensible file. Don't mess up the file or modify/delete any of the other content

OK, done.

jaydee73:

sudo apt-get install hping3

Done.

jaydee73:

check if your mac address in the script is written in lower cases (aa:bb:cc instead of AA:BB:CC).

Modified to lower case.

jaydee73:

There is a typo. You wrote "DEVIES

Corrected.

jaydee73:

I have an additional "sudo" before hping3

Done.

I rebooted my Pi after this and ran the script again and I got Permissions denied again. I ran the ls -l and saw the x's were missing from the script so I knew the permissions were incorrect again. I ran the sudo chmod and then ran the script manually and got "present"!

Sorry, my fault. As Rich mentioned, the file permissions in the folder you used for the script are resetted with every boot. This folder is not intended to be used for other files.

So move over the file to another directory (Max suggested one, mine are in /scripts). So make a directory with:

mkdir /scripts

Copy your sh script to this folder (I won't describe how to, just google and learn some linux commands ) and check the permissions one more time. Adapt your item configuration to the new path and test again.

And then disable wifi on your phone and check if the state changes to absent. The script only executes once a minute, so the change is not visible immediately.

Make sure you fill in your own local IP address of your Iphone as well as your MAC address (replace xx.xx.xx..... in row 6). Make sure to use all lowercase for your MAC address.
Save and close the file.
3) Now you need to change the permissions:

sudo chown 777 IphoneD.sh

Now check with:

ls -all

if the script is executable.
4) Install hping3:

sudo apt-get install hping3

5) Make a rule to check from time to time presence (every minute in this example):
As an example I made an item that shows the result of my rule:

String Iphone "John Doe @ Home? [%s]"

This item is updated by this rule, trigger by a cron job (link for details: [Cron Trigger tutorial](http://www.quartz-scheduler.org/documentation/quartz-2.1.x/tutorials/crontrigger)

Nice and concise tutorial on how to make hping3 work. Thank you for posting.

I might make one suggestion to add a sleep between the hping3 and the arp call in IphoneD.sh. I've found on my machine at least that the script runs faster than arp packets fly across the network causing the script to only intermittently correctly report Present. Adding a sleep 1 in my case (much less would probably be adequate) makes it return the correct state every time.

Some things occurred which I could not explain, maybe you can explain to me:1) I inserted a hyperlink, first one works, second one only shows the text.2) I inserted link to another forum user, first one works, second one only shows the text3) I could not give 'hard enters / line breaks' at some point in the post, which makes it more difficult to read (e.g. step 3)

Nice and concise tutorial on how to make hping3 work. Thank you for posting.

I might make one suggestion to add a sleep between the hping3 and the arp call in IphoneD.sh. I've found on my machine at least that the script runs faster than arp packets fly across the network causing the script to only intermittently correctly report Present. Adding a sleep 1 in my case (much less would probably be adequate) makes it return the correct state every time.

Thank you for the suggestion, I added it to the tutorial, and changed it in the post above.

This tutorial describes how to detect the presence of an Iphone if it is connected to your home's wifi network.
It is a summary of several posts on this forum, started by the script posted by @kemotsysinc. Thanks for that!
Used hardware: Iphone 6 and Raspberry Pi 2 Used software: Rasbian with openHAB 1.8.3 and hping3 Necessary binding: Exec binding
To enable Iphone detection follow these steps:
1) Make a directory to store scripts (if you don't have this yet)
sudo mkdir /home/pi/scri…

With that I will go ahead and close this thread. If there's a reason against that, please do not hesitate to write me a personal message!