We have moved at community.getvera.com

Author Topic: Light ON if Door Open / Light Off withClose (ONLY if it was ON by Door Open)  (Read 2884 times)

Offline mysticjay

  • Full Member
  • ***
  • Posts: 184
  • Karma: +1/-1
Any input ....The off part is not working ....

Here's the scenario:
If Door Open turn light on
If Door Close turn light off (only if it was turned on by Door Open event to start with)



--Scene: Door Open
--set our var to 0
luup.variable_set("urn:upnp-org:serviceId:SwitchPower1","LightOnBySensor", 0, 10)

--whats light status
local lightStatus = luup.variable_get("urn:upnp-org:serviceId:SwitchPower1","Status", 10)

--if light was off, set our var to 1
if  lightStatus==0 then
   luup.variable_set("urn:upnp-org:serviceId:SwitchPower1","LightOnBySensor", 1, 10)
end


--Scene: Door Close
--get our var
local LightOnBySensor = luup.variable_get("urn:upnp-org:serviceId:SwitchPower1","LightOnBySensor", 10)

if LigtOnBYSensor==1 then
   return true
else
   return false
end
Vera 2 (1.1.1338), Trane TZEMT400BB3,ML IWD600S(2), ML IWS1000S(2) , FI8905W, Aeon DSB04100-ZWUS, GE 45609(2), GE 45606(2), GE 45608, GE 45614 (5), LFM-20(2), Kwikset 99100-011 (5) , Hawking HRMD1, Droid X and Xoom as Remotes, Harmony Link

Offline mcvflorin

  • Administrator
  • Hero Member
  • *****
  • Posts: 1755
  • Karma: +11/-3
luup.variable_get returns a string, so try surrounding 0 and 1 from the comparisons with double quotes.

if LigtOnBYSensor=="1" then

Offline mysticjay

  • Full Member
  • ***
  • Posts: 184
  • Karma: +1/-1
Thx mcvflorin.  Also oTi@ pointed out the variable was spelled out wrong...so let me try this again making these changes :)

Update: Got it working. Thanks for input from oTi@ and mcvflorin - Both your input pointed me in the right direction. Here's my first working script :)


Sensor tripped for Door Open, turn light ON.
-------------------------------------------------------
1.   Create a Scene
2.   Go to Events to create an Event
          a.   Select your sensor
          b.   For the Dropdown “what type of event is the trigger” , select  “ A sensor is tripped”
          c.   Select Tripped Dropdown to “Yes”
          d.   Optionally you can select your user name to get email if you check notify.
3.   Go to commands to create a command
         a.   Select the device and choose what command (On/Off)

Sensor tripped for Door Close, turn light OFF
--------------------------------------------------------

   Follow the previous steps, except in step 2.C select Tripped Down to "No"


Sensor tripped for Door Close, turn light OFF, ONLY if the light was turned on by the sensor to start with.
------------------------------------------------------------------------------------------------------------------------------------
1. For this paste this code in Lua code for  Door Open Scene
--Scene: Door Open
--set our var to 0
luup.variable_set("urn:upnp-org:serviceId:SwitchPower1","LightOnBySensor", "0", 10)

--whats light status
local lightStatus = luup.variable_get("urn:upnp-org:serviceId:SwitchPower1","Status", 10)

--if light was off, set our var to 1
if  lightStatus=="0" then
   luup.variable_set("urn:upnp-org:serviceId:SwitchPower1","LightOnBySensor", "1", 10)
end

2. Then paste this code in Lua Code for Door Close Scene
--Scene: Door Close
--get our var
local LightOnBySensor = luup.variable_get("urn:upnp-org:serviceId:SwitchPower1","LightOnBySensor", 10)

if LightOnBySensor=="1" then
   return true
else
   return false
end
« Last Edit: September 23, 2011, 12:33:14 pm by mysticjay »
Vera 2 (1.1.1338), Trane TZEMT400BB3,ML IWD600S(2), ML IWS1000S(2) , FI8905W, Aeon DSB04100-ZWUS, GE 45609(2), GE 45606(2), GE 45608, GE 45614 (5), LFM-20(2), Kwikset 99100-011 (5) , Hawking HRMD1, Droid X and Xoom as Remotes, Harmony Link