That part works perfectly of course.
What I am trying to do is if that IP address does not match the address that I am expecting then turn on a light as a way of warning me.
Code I have messed up is below.
Basically, the light never comes on.
Can anyone tell me where I am going wrong?
Thanks in advance.
Code: Select all
local getIp = 'https://api.ipify.org/?format=json'
return {
on = {
timer = { 'every minute' },
httpResponses = { 'wanIP' }
},
logging = {
level = domoticz.LOG_FORCE,
marker = '[WAN IP]'
},
execute = function(dz, devNil)
local actIP = dz.devices('Wan IP').text
if (devNil.isTimer) then
dz.log("Send WanIP request")
dz.openURL({
url = getIp,
method = 'GET',
callback = 'wanIP'
})
elseif (devNil.isHTTPResponse) then
dz.log("WanIP response")
if (devNil.ok) then -- statusCode == 2xx
newIP = devNil.json.ip
end
if newIP ~= actIP then
dz.devices('Wan IP').updateText(newIP)
end
if newIP ~= '195.150.251.189' and newIP ~= 'nil' then
execute = function(domoticz, doit)
local light = domoticz.devices('Hallway')
light.switchOn()
end
end
end
end
}