ipDevice variable is gone by the time my script runs

Posted on
Tue Aug 28, 2018 2:02 pm
jtburgess offline
User avatar
Posts: 77
Joined: Jan 17, 2018
Location: NJ

ipDevice variable is gone by the time my script runs

When a device IP address changes, it'd be really nice if I could get the OLD and NEW IP addresses to include in my email, like the log does.
I haven't figured out how do to that, yet, but this is close...

I assigned an IP address to a WAP in my DHCP server, so it is fixed.
I see this in the indigo log:
fingscan MAC#:0C:80:63:0B:EF:B2 -- old IP: 192.168.0.015 ; new IP number: 192.168.0.126 to switch off changed message: edit this device and select no msg
Trigger IP address changed
Script Error embedded script: 'key name ipDevice16 not found in database'
Script Error Exception Traceback (most recent call shown last):

embedded script, line 10, at top level
KeyError: 'key name ipDevice16 not found in database'


My script looks like this:
Code: Select all
import re
splitRE = re.compile(r' *; *')

emailAddress = "xxxxx@yyyyy.org"
emailSubject = "fingscan discovered a device with a changed IP Address"

tmp = indigo.variables["ipDevsNewDeviceNo"].value
ipVariableChanged = tmp[:tmp.find(';')]

newDevTmp = indigo.variables[ipVariableChanged].value
newDevValues = splitRE.split(newDevTmp)
# D0:03:4B:05:C9:9B ; 192.168.0.22 ; 2018-08-25 11:17:49 ;up; 1 ; new-0-D0:03:4B:05:C9:9B ;  Apple ; ; ; ;  usePingUP-0;
# values now in list: mac, IP, date, state, ?, nickname, vendor, ?, usePing?,
deviceIP  = newDevValues[1]
deviceName= newDevValues[5]
vendor    = newDevValues[6]

emailBody = "fingscan discovered device IP variable %s, name=%s has a new IP address: %s, vendor=%s" % (ipVariableChanged, deviceName, deviceIP, vendor)

indigo.server.sendEmailTo(emailAddress, subject=emailSubject, body=emailBody)

The two variables mentioned above have values:
ipDevsNewDeviceNo ipDevice16;new-0-C8:02:8F:0E:16:CC
ipDevsNewIPNumber ipDevice29;TPlink WAP Kitchen

It looks like not only did the IP address change (as expected), but the ipDeviceNN also changed.
And the variable 'ipDevice16' (which is really the old device) no longer existed when my code ran and tried to access it on line 10.

I should point out that this code often works, so the device variable doesn't always change.
I don't know why it assigned a new ipDeviceNN this time.
How about you delete the device after calling any action scripts, when necessary
and include the IP address in the ipDevs.... variables?

It'd also be nice to be able to use the device Name which I assign, not its nickname, because that is almost always new-N-MACaddress

Posted on
Tue Aug 28, 2018 2:40 pm
kw123 offline
User avatar
Posts: 8335
Joined: May 12, 2013
Location: Dallas, TX

Re: ipDevice variable is gone by the time my script runs

Can’t check right now have only my phone.
Can look at it on the weekend.


Sent from my iPhone using Tapatalk

Posted on
Wed Aug 29, 2018 7:51 am
jtburgess offline
User avatar
Posts: 77
Joined: Jan 17, 2018
Location: NJ

Re: ipDevice variable is gone by the time my script runs

No hurry. I'm away this weekend, so I won't see your reply until Tuesday.

Posted on
Thu Aug 30, 2018 11:28 pm
kw123 offline
User avatar
Posts: 8335
Joined: May 12, 2013
Location: Dallas, TX

Re: ipDevice variable is gone by the time my script runs

that requires a little deeper digging. I will be home next weekend.

karl

Posted on
Sat Sep 08, 2018 9:31 am
kw123 offline
User avatar
Posts: 8335
Joined: May 12, 2013
Location: Dallas, TX

Re: ipDevice variable is gone by the time my script runs

new version posted:
added variable ipDevsOldNewIPNumber

ipDevsOldNewIPNumber is set when a device changes its ip number
contents: devName/mac#/oldIP/newIP
you can use it with
Code: Select all
items= (indigo.variables["ipDevsOldNewIPNumber"].value).split("/")

then
items[0] = devName
items[1] = mac#
...


Code: Select all
dev = indigo.devices[items[0]]
will give you the device dict that changed IP number
With this you should be able to get everything.
Instead of using the variables, use eg dev.states["vendor"] to get the other info.


Hope that does it.

Karl

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 3 guests