Detect a new device/person on LAN and take actions

Posted on
Sun Jul 01, 2018 2:25 pm
mundmc offline
User avatar
Posts: 1060
Joined: Sep 14, 2012

Detect a new device/person on LAN and take actions

Hi Karl,
I'm a little neurotic, and I want Pushover notifications whenever a new device connects to my LAN. I'm unclear whether I would be better suited to do this on your Unifi plugin, which I also use.

I assume the best way is via 1) Trigger on "Fingscan Event" -> "New IP Device on Network"

My question is HOW do I tell what the MAC address, etc, of the new device is? It looks like it is stored in the "IP devices" folder. I've played at this for about 2 hours, sorry to bug if it's an obvious answer!

PS- I'll wash your car if you can then tell me how to do this for devices Unifi (or piBeacon) detects that are NOT on my network, because that mailman of mine is looking shifty :)

Posted on
Sun Jul 01, 2018 6:34 pm
mundmc offline
User avatar
Posts: 1060
Joined: Sep 14, 2012

Re: Detect a new device/person on LAN and take actions

I'm doing it like this in the interim, not sure if it's working as it hasn't been triggered yet...
Code: Select all
newDevice = indigo.variables[491200589].value # "ipDevsNewIPNumber"
indigo.server.log("New Device: " + newDevice)
#New Device: ipDevice54;new-10-9C:8E:CD:0D:97:EF

newDeviceNumber = newDevice[15:17]
newDeviceMAC = newDevice[18:35]

indigo.server.log("Device Number: " + str(newDeviceNumber))
indigo.server.log("Device MAC: " + str(newDeviceMAC))

Posted on
Sun Jul 01, 2018 11:13 pm
kw123 offline
User avatar
Posts: 8363
Joined: May 12, 2013
Location: Dallas, TX

Re: Detect a new device/person on LAN and take actions

here the update command:
Code: Select all
indigo.variable.updateValue("ipDevsNewDeviceNo", "ipDevice"+str(newIPDevNumber)+";"+devI["deviceName"])

variable ipDevsNewDeviceNo will contain:
ipDeviceindigo.dev.number;indigo.devicename

eg "ipDevice12345;new-571"

where 12345 is the indigo device number and new-5711 is the indigo device name of the new device

AND do not use indigo variable # but indigo variable name to check. The variable gets recycled at midnight = deleted and recreated - that means it gets a new indigo #. That way the sql tables are kept smaller.

Code: Select all
try:
   var = indigo.devices("ipDevsNewDeviceNo").value
   var = var.split(";")
   newDeviceNumber =int( var[0].split("Device")[1])
   newDeviceName   = var[1]
except:
   newDeviceNumber =0
   newDeviceName =""
if newDeviceNumber != 0:   do your stuff
should give you the indigo device name & numbers if there is a new ip device added.

the try/ except is useful if the variable is blank or 0 (eg at creation)

hope that helps.

Karl

ps I have 2 cars

Posted on
Mon Jul 02, 2018 7:15 am
mundmc offline
User avatar
Posts: 1060
Joined: Sep 14, 2012

Re: Detect a new device/person on LAN and take actions

Thanks Karl,
I’ll give it a go!


Sent from my iPhone using Tapatalk

Posted on
Mon Jul 02, 2018 2:55 pm
kw123 offline
User avatar
Posts: 8363
Joined: May 12, 2013
Location: Dallas, TX

Re: Detect a new device/person on LAN and take actions

actually it is not the dev.id but the variable name eg:
Code: Select all
ipDevice07;new-10-00:1F:5B:30:E9:20
tried by deleting a device and it was recreated.

so the code should be
Code: Select all
try:
   var = indigo.devices("ipDevsNewDeviceNo").value
   var = var.split(";")
   newDeviceName   = var[1]
except:
   newDeviceName =""
if newDeviceName != "":   do your stuff

Posted on
Wed Jul 04, 2018 1:40 am
McJohn offline
User avatar
Posts: 631
Joined: Dec 18, 2012
Location: The Netherlands

Re: Detect a new device/person on LAN and take actions

Thanks for the info Karl.
We have also a question about this issue.

Fingscan Event Trigger:
New IP Device on Network;

Actions:
email the new IP device details:
(hardware vendor, MACNumber, ipNumber)

How could we do that?

Thanks for your help!

Warm regards,

John

Posted on
Wed Jul 04, 2018 2:52 am
kw123 offline
User avatar
Posts: 8363
Joined: May 12, 2013
Location: Dallas, TX

Re: Detect a new device/person on LAN and take actions

create trigger : new ip device on network, then in ACTIONS server script:
Code: Select all
# Putting a variable's data into the subject and body
ipDev = indigo.variables["ipDevsNewDeviceNo"]
ipDevVarNumber   = ipDev.value.split(";")[0]
devName = ipDev.split(";")[1]

theSubject = "new device on network " + devName
theBody = "new device on network\n"
theBody += indigo.variables["ipDevice00"].value +"\n" # this gives the headline
theBody += indigo.variables[ipDevVarNumber].value  # this writes the contents of the new variable below the header line

indigo.server.log(theBody)# also send it to the indigo log file

indigo.server.sendEmailTo("youremail@xxx.com", subject=theSubject, body=theBody)

Posted on
Wed Jul 04, 2018 8:42 am
McJohn offline
User avatar
Posts: 631
Joined: Dec 18, 2012
Location: The Netherlands

Re: Detect a new device/person on LAN and take actions

Thanks for the fast feedback Karl! Super!

One problem (sorry):

Script Error embedded script: 'Variable' object has no attribute 'split'
Script Error Exception Traceback (most recent call shown last):

embedded script, line 4, at top level
AttributeError: 'Variable' object has no attribute 'split'

Posted on
Wed Jul 04, 2018 9:37 am
autolog offline
Posts: 3988
Joined: Sep 10, 2013
Location: West Sussex, UK [GMT aka UTC]

Re: Detect a new device/person on LAN and take actions

line 4:
Code: Select all
devName = ipDev.split(";")[1]
I think should be
Code: Select all
devName = ipDev.value.split(";")[1]
:)

Posted on
Wed Jul 04, 2018 9:40 am
kw123 offline
User avatar
Posts: 8363
Joined: May 12, 2013
Location: Dallas, TX

Detect a new device/person on LAN and take actions

Yes, just typed it on my cell

indigo.variables.value gives the string.


Sent from my iPhone using Tapatalk

Posted on
Wed Jul 04, 2018 2:37 pm
mundmc offline
User avatar
Posts: 1060
Joined: Sep 14, 2012

Re: Detect a new device/person on LAN and take actions

So i've got this so far:
Code: Select all
var = indigo.variables["ipDevsNewDeviceNo"].value
indigo.server.log("New Device String: " + var)
var = var.split(";")
newDeviceName = var[1]
indigo.server.log("New Device Name:  " + newDeviceName)
subvar = var[1].split("-")
newDeviceMAC = subvar[2]
indigo.server.log("New Device MAC:  " + newDeviceMAC)
newDeviceTimeUp = indigo.devices[newDeviceName].states["lastFingUp"] # State lastFingUp of newest device
indigo.server.log("New Device Time Up: " + newDeviceTimeUp)
newDeviceIP = indigo.devices[newDeviceName].states["ipNumber"] # State ipNumber of newest device
indigo.server.log("New Device IP:  " + newDeviceIP)

indigo.variable.updateValue(indigo.variables[529430126], newDeviceName) # DEVICETRACKING_fing_devicename
indigo.variable.updateValue(indigo.variables[1683113861], newDeviceMAC) # DEVICETRACKING_mac_address
indigo.variable.updateValue(indigo.variables[96904041], str(newDeviceTimeUp)) # DEVICETRACKING_last_new_up
indigo.variable.updateValue(indigo.variables[934101919], str(newDeviceIP)) # DEVICETRACKING_ipaddress


I need to test it, but my hope is this will make new devices logging into wifi push an alert to me (I use pushover, though email will be good redundancy).

Am I correct in my assumption that new guests logging into my wifi will trigger this?
Any recommendations on how best to test it? (I plan to pick out the MAC of a known device and delete it's Device created by the plugin, though I may have to delete it's Variable as well.

Posted on
Wed Jul 04, 2018 2:49 pm
kw123 offline
User avatar
Posts: 8363
Joined: May 12, 2013
Location: Dallas, TX

Re: Detect a new device/person on LAN and take actions

the script looks fine .

to your question on new MAC device if guest login:
if a new device attaches to the network and sends ANY broadcast fing(SCAN) will catch it.


Karl

Posted on
Thu Jul 05, 2018 12:56 am
McJohn offline
User avatar
Posts: 631
Joined: Dec 18, 2012
Location: The Netherlands

Re: Detect a new device/person on LAN and take actions

Yes! It's working!

Thank you very much for the fast Service! :D

Posted on
Thu Jul 05, 2018 2:03 am
McJohn offline
User avatar
Posts: 631
Joined: Dec 18, 2012
Location: The Netherlands

Re: Detect a new device/person on LAN and take actions

Is it btw possible to give each header and content a return?
So, then the text is better readable on an iPhone.
Attachments
Screen Shot 2018-07-05 at 09.58.11.png
Screen Shot 2018-07-05 at 09.58.11.png (77.55 KiB) Viewed 4183 times

Posted on
Thu Jul 05, 2018 2:57 am
kw123 offline
User avatar
Posts: 8363
Joined: May 12, 2013
Location: Dallas, TX

Re: Detect a new device/person on LAN and take actions

Add

+”\n”

To the end of each line you want to have an extra new line



Sent from my iPhone using Tapatalk

Who is online

Users browsing this forum: No registered users and 2 guests

cron