Presence arrival using DHCPlisten possible?

Does it allso work with android phones? :thinking:

it has worked with iPhones, Pixel 2 XL and Pixel 3 XL.

Ok thanks, I will take a look at it tomorrow, its been a long day of programming and trying things out :sleepy:

Has anyone experimented with setting a 5 minute DHCP lease for mobile devices as a way to force a wake up? While it’s not super.high resolution, presumable it would be enough when coupled with a 10 minute timeout in the network binding to turn off lights/heating/music if nobody is at home.

Hi tried implementing [iPhone Presence Detection with hping3 and ARP]. I don’t get any errors but the script allways seems to return that my phone is present, even when it is switched off. Any ideas how i can further debug this?

this is the output in the log:

2018-12-27 09:33:00.164 [INFO ] [.eclipse.smarthome.model.script.RULE] - Iphone update

We trust you have received the usual lecture from the local System

Administrator. It usually boils down to these three things:

    #1) Respect the privacy of others.

    #2) Think before you type.

    #3) With great power comes great responsibility.

sudo: no tty present and no askpass program specified

==> /var/log/openhab2/events.log <==

2018-12-27 09:33:00.176 [ome.event.ItemCommandEvent] - Item 'Iphone_Sw' received command ON

==> /var/log/openhab2/openhab.log <==

2018-12-27 09:33:00.210 [INFO ] [.eclipse.smarthome.model.script.RULE] - Iphone_Sw received command ON. Counter reset to 0

No idea where the admin lecture comes from either :laughing:

Script:

#!/bin/bash

 #Enter your ip of your device here
DEVICES="my device IP here"

for i in `echo $DEVICES`; do
    # Change dev and eth0 if needed
    ip neigh flush dev eth0 $i
    hping3 -2 -c 10 -p 5353 -i u1 $i -q >/dev/null 2>&1
    sleep 1
    # Only arp specific device, grep for a mac-address
    status=`arp -an $i | awk '{print $4}' | grep "..:..:..:..:..:.."`
    statusMessage="OFF"
    #A mac will be 17 characters including the ":"
    if [ ${#status} -eq 17 ]; then
        echo "Phone $i is detected!"
        statusMessage="ON"
    else
        echo "Phone $i is not present"
        statusMessage="OFF"
    fi
done

The rule:

var Number IphoneCounter = 0
val Number MaxCounter = 18

rule "Execute script IphonePresence"
when
    Time cron "0 * * * * ?"
then
    var String IphoneExec = executeCommandLine("sudo@@bash@@/opt/IphoneD.sh", 5000)
    Iphone.postUpdate(IphoneExec)
    logInfo("RULE","Iphone update"+IphoneExec)
end

rule "Determine presence Iphone"
when 
	Item Iphone received update
then {
	if(Iphone.state == "OFF") {
		IphoneCounter = IphoneCounter + 1
		if(IphoneCounter > MaxCounter) {
			Iphone_Sw.sendCommand(OFF)
			IphoneCounter = 0	
			logInfo("RULE","Iphone  counter reached threshold and sent command OFF. Counter set to 0")
		}
		else {
			logInfo("RULE","Counter Iphone threshold not yet reached. Counter set to " + IphoneCounter)
		}
	}
	else {
		Iphone_Sw.sendCommand(ON)	
		IphoneCounter = 0
		logInfo("RULE","Iphone_Sw received command ON. Counter reset to 0")
	}
	}
end

ls -all looks like this:

-rwxrwxrwx  1 openhab    root        624 Dec 27 08:55 IphoneD.sh

visudo last line (since i’m using openhabian):

openhabian ALL=(ALL) NOPASSWD: /bin/ip, /bin/bash

I do notice that where i inserted a logInfo in the first rule, that IphoneExec seems to be empty.

Sorry if i’m missing something stupid. Still got a lot to learn about linux :blush: