I installed the iphoneLocator app, and it works beautifully. on the interface i can see when a phone is away or present, the stauts updates at a reasonable rate, everything works. I decided that i would create a vSwitch that would determine if both the wife’s iPhone and mine were home. for the life of me, i cannot get this thing to work. seems simple enough, but i must be missing something. here is the code i came up with. in the and statement i’ve tried number (i.e. 0) and also string (i.e. “0”), but neither work. what am i doing wrong??
– SCENE TO FIGURE IF SOMEONE IS HOME
– Device #54 wife iPhone
– Device #55 my iPhone
– Device #45 home or away switch
– MAIN BODY LOGIC FOR WHO IS AT HOME
– Get Status from phones - result is 1 for home or 0 for away
local wPhone = luup.variable_get(“urn:upnp-org:serviceId:IPhoneLocator1”,“GetPresent”,54)
local mPhone = luup.variable_get(“urn:upnp-org:serviceId:IPhoneLocator1”,“GetPresent”,55)
if (wPhone == 0 and mPhone == 0) then
– both phones gone, set switch to off
luup.call_action(“urn:upnp-org:serviceId:VSwitch1”,“SetTarget”,{ newTargetValue=“0” },45)
else
– any phone home set switch to on
luup.call_action(“urn:upnp-org:serviceId:VSwitch1”,“SetTarget”,{ newTargetValue=“1” },45)
end
I’m using the SwitchPower1 service with the “SetTarget” variable (luup.call_action) and the “Status” variable (luup.variable_get) and it’s working fine.
Now if i could only figure out what the iphonelocator “GetPresent” variable actually returns. when i call it via the dataRequest (veraIP:3480/data_request?id=action&DeviceNum=55&serviceId=urn:upnp-org:serviceId:IPhoneLocator1&action=GetPresent) i get the following which makes me think it it should be a zero
I have no idea what the hell is going on here. i tried to debug the code and put a luup.log call to show me what the variables are:
== THIS IS THE CODE ==
local wPhone = luup.variable_get(“urn:upnp-org:serviceId:IPhoneLocator1”,“Present”,54)
local mPhone = luup.variable_get(“urn:upnp-org:serviceId:IPhoneLocator1”,“Present”,55)
so my variables are both 0. why in the hell doesn’t the and logic of this statement ever make it into this part of the if statement??? i added print statements in there and it always hits the else loop even with the variables above. this is driving me crazy…
== THIS IS THE CODE ==
if (wPhone == 0 and mPhone == 0) then
– both phones gone, set switch to off
luup.log("both were 0 ")
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”,“SetTarget”,{ newTargetValue=“0” },45)
else
– any phone home set switch to on
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”,“SetTarget”,{ newTargetValue=“1” },45)
luup.log(“there was a 1 in there”)
end
== THIS IS THE LOG OUTPUT ==
50 12/03/15 14:13:53.987 luup_log:0: there was a 1 in there <0x2e48a680>
Well, the tonumber did the trick… Weird thing is that I tried the equals (==) on both numbers and strings. Apparently LUA does not do a string comparison with an equals ???.. Thanks for the help
Best Home Automation shopping experience. Shop at Ezlo!