Detect a new device/person on LAN and take actions

Posted on
Thu Jul 05, 2018 7:26 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

Sorry Karl, I tried but the red errors are flying around here.

Where has the
+”\n”
to be placed in the script?

For example we want this:
(if it is possible)

new device on network

MAC-Number ;
B8:C7:5D:C6:B0:98 ;

IP-Number ;
192.168.188.141;

Time-Of-Last-Change ;
2018-07-05 08:27:19 ;

Status;
up;

N.of-Ch. ;
32705 ;

Nick-Name ;
new-10-B8:C7:5D:C6:B 0:98 ;

Hardware-Vendor ;
Apple ;

DeviceInfo ;
;




# Putting a variable's data into the subject and body
ipDev = indigo.variables["ipDevsNewDeviceNo"]
ipDevVarNumber = ipDev.value.split(";")[0]
devName = ipDev.value.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("xxxx@xxx.com", subject=theSubject, body=theBody)

Posted on
Thu Jul 05, 2018 12:25 pm
kw123 offline
User avatar
Posts: 8333
Joined: May 12, 2013
Location: Dallas, TX

Detect a new device/person on LAN and take actions

Sorry misunderstanding.

The variables are simple strings

If you want to have the individual states use value = dev.state[“xxx”]
theBody += xxx+”: “+unicode(value)+”\n”

With
dev = indigo.devices[ipdevname]

And xxx the state you line to show

And don’t use curly “




Sent from my iPhone using Tapatalk

Posted on
Fri Jul 06, 2018 1:00 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 your feedback but where did we have to place this text in the script?

use value = dev.state[“xxx”]
theBody += xxx+”: “+unicode(value)+”\n”

With
dev = indigo.devices[ipdevname]


?

Posted on
Sat Jul 07, 2018 10:58 am
kw123 offline
User avatar
Posts: 8333
Joined: May 12, 2013
Location: Dallas, TX

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

this should do it:
Code: Select all
ipDev = indigo.variables["ipDevsNewDeviceNo"]
ipDevVarNumber = ipDev.value.split(";")[0]
devName = ipDev.value.split(";")[1]
dev = indigo.devices[devName]
st = dev.states # shortcut

theSubject = "new device on network " + devName
theBody  = "new device on network: "  + devName            +"\n"
theBody += "ipNumber: "             +st["ipNumber"]        +"\n"
theBody += "MACNumber: "            +st["MACNumber"]       +"\n"
theBody += "hardwareVendor: "       +st["hardwareVendor"]  +"\n"
theBody += "indigoID: "             +str(dev.id)           +"\n"

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

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

Karl
[EDIT] fixed MACNumber typo

Posted on
Mon Jul 09, 2018 3:54 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

Thank you very much for the input Karl.
Super!

(It gaves an error at the "MACnumber".)
embedded script: 'key MACnumber not found in dict'
I discovered it has to be MACNumber with a capital N :D

(Always the hidden jokes of Karl :D )

Who is online

Users browsing this forum: No registered users and 2 guests