script for presence detection of a phone

All kinds of 'OS' scripts
krizzz
Posts: 171
Joined: Wednesday 20 November 2013 21:36
Target OS: Linux
Domoticz version:
Location: The Netherlands
Contact:

Re: script for presence detection of a phone

Post by krizzz » Saturday 10 June 2017 22:14

thijsdebets wrote:I created a script to detect all devices on the network.
Installation instructions are here: https://github.com/thijsdebets/networkdetectz/wiki

It uses a combination of arpscan, ping and even supports bluetooth detection.
I use it very succesfull to detect who is at home and to set the lights to TV-Mode when the tv switches on, etc.

It requires one arp-scan every minute via cron making it low on resources.
I tried and follow the wiki and I get stuck already at

Code: Select all

register the IDX in nwd-config
When doing the git install, is the nod-onfig file already present somewhere? I think not, so do I have to create the file as new? What is included? If I look at

Code: Select all

HardwareIDX=999
Create a Hardware switch for NewDevicedFound and add the IDX in nwd-config
NewDevicesFoundIDX=999
Create a Hardware switch for Running indicator, to see if the script is up. Set this indicator on 'Off-delay' 10 minutes
NWDScriptRunning=999

Set other configuration items in nwd-config:
DomoPIN='1234'
RetryAttempts=1 # 3 = retry 4 times (5 minutes), 1 = retry 2 = 3 minutes
I do not know what should be in or out... Could you help me out?

User avatar
EdwinK
Posts: 1321
Joined: Sunday 22 January 2017 22:46
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Rhoon
Contact:

Re: script for presence detection of a phone

Post by EdwinK » Sunday 11 June 2017 10:52

thijsdebets wrote:I created a script to detect all devices on the network.
Installation instructions are here: https://github.com/thijsdebets/networkdetectz/wiki

It uses a combination of arpscan, ping and even supports bluetooth detection.
I use it very succesfull to detect who is at home and to set the lights to TV-Mode when the tv switches on, etc.

It requires one arp-scan every minute via cron making it low on resources.

Looks neat. But since it requires Domoticz to be running on a Pi, I'm not able to run it on a Synology NAS.
Running latest BETA on a Pi-3 | Toon Thermostat (rooted) | RFxcom | Dashticz V2 |

glsf91
Posts: 38
Joined: Tuesday 14 November 2017 22:56
Target OS: Linux
Domoticz version:
Contact:

Re: script for presence detection of a phone

Post by glsf91 » Tuesday 14 November 2017 23:10

Instead of a ip-address you can also use the dns/dhcp name of the device.
At my router my phone is registered with always the same name.

You can get the name with doing nslookup <ip-address>. It tells you the name. This can be used as argument for the script instead of the ip-address.

marmachine
Posts: 79
Joined: Saturday 26 March 2016 11:19
Target OS: Raspberry Pi
Domoticz version: 3.4834
Location: Netherlands
Contact:

Re: script for presence detection of a phone

Post by marmachine » Thursday 09 August 2018 13:08

See https://dougvitale.wordpress.com/2011/1 ... lacements/

ARP scan is deprecated, IP neighbor should be used now....

zicht
Posts: 216
Joined: Sunday 11 May 2014 11:09
Target OS: Windows
Domoticz version: 3.8xxx
Location: NL
Contact:

Re: script for presence detection of a phone

Post by zicht » Sunday 26 August 2018 10:58

Hi All

Thanks for this great Idea ! I had no clue about the possibilities of this.
On win10 x64 platform (full updated) i implemented arp lookup in LUA
Now i am doing some test and it looks promising.

When doing plain Ping test for presence with android (diff versions : jelly-been to oreo) in dose/sleep state does not get a respond.
Somehow the ARP table keeps the entry also in this state, and the regular wake up of android for checks is enough to keep the entry in the ARP table: normaly based on ping, over night you will see a sequence of ON / OFF in the dummy switch log.

With ARP it stays On the complete night !
But when i turn wifi off the enty disapears in ARP after 5 minutes ...
- A clear benefit for presence detection.
- Another benefit is you can lookup the ARP table against the MAC adress what makes it IP undependent (DHCP can be used vs Static assignment)
- It is very fast ! not depending on external factors, just internal table lookup (no Phone interaction needed)

I Love the idea and will keep on testing for next couple of days.

Below the code replace xx with your mac lookup, It runs the batch file below.

Code: Select all


	commando='findmac.bat xx-xx-xx-xx-xx-xx'   
	content=os.capture(commando)
	if string.len(content)>10 then 
			findm=true
			if otherdevices['Arp M']=="Off" then 
				commandArray['Arp M']="On" 
				NMA("Mherkend") 
			end			
	else
			if otherdevices['Arp M']=="On" then commandArray['Arp M']="Off" end
	end
Lua Helper function i use for more OS captures on my system to read results

Code: Select all

function os.capture(cmd, raw)				-- os.command uitvoeren en resultaat daarvan lezen in string
  local f=assert(io.popen(cmd, 'r'))
  local s=assert(f:read('*a'))
  f:close()
  if raw then return s end
  s=string.gsub(s, '^%s+', '')
  s=string.gsub(s, '%s+$', '')
  s=string.gsub(s, '[\n\r]+', ' ')
  return s
end
Windows batch file in domoticz dir. It is important where you place this file to make it reachable for Lua
It returns an empty string when the ARP entry is not found (checked in LUA on length of the string)
It returns IP and Mac when the entry is found in the ARP table.

Code: Select all

@ECHO OFF
SET macd="%1"
ARP -a |find %macd% 
I keep you posted with the results ( for my purpose this seems much better usable vs the ping aproach...)

EDIT :
I need the pinger to make some kind of connection , if not it takes long before the arp catches the MAC.
But with pinger enabled to the phone it works perfectly and more reliable.
Due to the pinger i slill need to assign a DHCP fixed IP binding to the phone.
So i am trying now a network monitor to see if this is enough for getting the phone in the ARP table
First test looks promising, but need to test longer (goal to not ping any more at all)
Keep you posted
Rpi & Win x64. Using : cam's,Nest,RFXCom,Kaku,LaCrosse,RFY,IsAlive,Dummy,Wether Underground, standard Lua, Curl on windows,Domoticz Android App & Tasker,

"The only source of knowledge is experience (A.Einstein)"

snuiter
Posts: 67
Joined: Saturday 17 June 2017 12:30
Target OS: Raspberry Pi
Domoticz version: beta
Contact:

Re: script for presence detection of a phone

Post by snuiter » Tuesday 11 September 2018 22:12

Today I installed the script of thijsdebets, it was a bit figuring out how he created/made it as the install guide is not flawless but got it working and will now test it for a few a days. Will see how devices will be switched off etc..

Not tried the solution from zicht metioned above

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests