We have moved at community.getvera.com

Author Topic: Inverse switches when door is opened  (Read 275 times)

Offline Nephologen

  • Newbie
  • *
  • Posts: 4
  • Karma: +0/-0
Inverse switches when door is opened
« on: December 20, 2018, 12:41:01 pm »

I've tried to get a lamp blinking a couple of times as the door sensor is tripped.
Since I'm a newbee on LUA / Luup or whatever its called, I've copied some code on the net and changed it a bit for my purposes. (btw I've an Vera Plus).

For some reason it fails, please tell me why (it is included as part of a scene).
The most disturbing error is:
input:25: attempt to index a nil value (global 'luup')

How to address this fault?

It probably contains of a lot of syntax errors which are obvious to you, but I hope you get the idea with this code. I.e it shall notify me when I'm upstairs with a flashing light when someone is openening the door (which I usually can't here from the top floor)

Code: [Select]
local array_lights = {132} --using just one device to test for now
local original_status = {}
local current_status = {}
local delay = 1
local count = 0
local maxcount = 5

local function inverse_switch(device,currentstate)
if currentstate == "1" then
luup.call_action("urn:upnp-org:serviceId:SwitchPower1","SetTarget",{ newTargetValue=0 }, device)
return 0
luup.call_action("urn:upnp-org:serviceId:SwitchPower1","SetTarget",{ newTargetValue=1 }, device)
return 1

local function backup_status()
for i, device in ipairs(array_lights) do
original_status[i] = luup.variable_get("urn:upnp-org:serviceId:SwitchPower1","Status", device)
current_status[i] = original_status[i]

local function restore_status()
for i, device in ipairs(array_lights) do
luup.call_action("urn:upnp-org:serviceId:SwitchPower1","SetTarget",{ device, original_status[i] }, device)

--save original status

--Loop until max count is reached
while count < maxcount do
for i, device in ipairs(array_lights) do
current_status[i] = inverse_switch(device,current_status[i])

count = count + 1

--Restore original values

return true

« Last Edit: December 22, 2018, 09:46:14 am by Nephologen »