Author Topic: Lua snippets in ui7 scene help!  (Read 1105 times)

Offline adamroff

  • Sr. Newbie
  • *
  • Posts: 21
  • Karma: +0/-0
Lua snippets in ui7 scene help!
« on: May 02, 2016, 12:34:46 am »
Ok, so I've been reading how to write some basic lua code and have successfully got the logs in terminal to help me debug some of my syntax errors, so it seems my code should work now however, its not and i can't quite figure out why.

Heres what I'm trying to achieve:
I have 3 virtual switches
i have 2 instances of iPhone detector one for me and one for my partner, these turn on and off 2 of my VS when someone is home or not(labeled laurasHome and AdamsHome).
the third VS is labeled HouseOccupied and i would like this one to control something only if my house is not occupied by myself or my partner (i.e. when i leave leave the geofence i need to check if my partner is still home or not... if she is still home, do nothing, if not, turn off the lights)

So far my scene (HouseIsNotOccupied) goes like this:
 2 device triggers
trigger 1 - LaurasHome is turned off
Luup added to trigger

local Adam_Home = luup.variable_get("urn:upnp-org:serviceId:SwitchPower1", "Status", 95)
  if (Adam_Home == 0)
     then
      return true
else
return false
  end

Trigger 2 - Adam'sHome is turned off
Luup added to trigger

  local Laura_Home = luup.variable_get("urn:upnp-org:serviceId:SwitchPower1", "Status", 96)
   if (Laura_Home == 0)
     then
      return true
else
return false
  end

Device action - Immediately HouseOccupied Off.


So far i have tried this scene with the same lua code in each trigger minus the "return false" and it seems to run without checking the status of the other switch.
Now i have the  "return false" line in there it doesn't seem to run at all...

I have been operating under the assumption that if there is any luup connected to any trigger, vera should execute the code and if the return value is true, move on to the action. if it returns false then stop the scene execution?

My first attempt was both of the luup codes combined into something like :
get status of both switches and save to the appropriate variables
if (adam_home == 0)
and
(laura_home == 0)
then
return true
end

this also didn't seem to work how i was hoping....
i feel like I'm really close to cracking this, please let me know if i have made a fatal error as its my first real attempt at using luup to create conditional scenes.

Thanks all!
Adam
 

Offline RichardTSchaefer

  • Master Member
  • *******
  • Posts: 10091
  • Karma: +763/-142
Re: Lua snippets in ui7 scene help!
« Reply #1 on: May 02, 2016, 07:50:52 am »
For scene's not returning anything (i.e. a code path that does not execute a return statement)  is treated as returning TRUE.

Offline adamroff

  • Sr. Newbie
  • *
  • Posts: 21
  • Karma: +0/-0
Re: Lua snippets in ui7 scene help!
« Reply #2 on: May 02, 2016, 08:46:43 am »
For scene's not returning anything (i.e. a code path that does not execute a return statement)  is treated as returning TRUE.

so would a better approach  to this be to flip my variables around?
i.e.
if "this" == 1
then
return false
end