New to Coding - What is wrong with this?

I want a light to turn at night and turn back off in 10 minutes when a door is opened and ONLY if the light is not already on. I have the scene correct I believe but I think I have something wrong with the code. Can someone please help? The scene does work because the light only comes on at night but seems to shut off in 10 minutes regardless of the switch state.

[code]local function checkDayNight()
local dID = 71
local allow = false
local status = luup.variable_get(“urn:rts-services-com:serviceId:DayTime”,“Status”,dID)
return ((status == “1”) == allow)
end

local function checkLight()
local dID = 13
local allow = false
local status = luup.variable_get(“urn:micasaverde-com:serviceId:ZWaveDevice1”,“Status”,dID)
return ((status == “1”) == allow)
end

return checkDayNight() and checkLight()[/code]

Your code looks OK and, from what you say, appears to be working.

The scene does work because the light only comes on at night but seems to shut off in 10 minutes regardless of the switch state.

Which switch state do you mean? How exactly do you want this to work?

Explain a little more about your scene. What are the triggers? How have you defined the actions? Do you have an immediate action to turn the light on and a delayed one to turn it off? Did you place this code in the scene’s main LUUP tab?

Trigger - door contact switch through alarm system

Action - turns on light immediately - delay turns off light in 10 minutes

Yes the code is placed in the scenes LUUP tab.

The door does turn the light on. The delay does turn the light off. It only does it when it is “night”. The problem is that when I enter through the door, I will let the scene run and when it turns the light off after the delay I will turn it back on. If I go throught the door again, 10 minutes later it turns it off again. I would like it to check the state of the switch and if the switch is already on, I do not want it to run the script so the light just stays on.

I have double checked the dId and I am using the device ID and not the alternate Id. Is this correct?

Should return ((status == “1”) == allow) be return ((status == “0”) == allow) maybe? I’m not sure what state the switch is in returns which status.

Thanks for the help.

luup.variable_get("urn:micasaverde-com:serviceId:ZWaveDevice1","Status",dID)

This is the WRONG service ID!

To see how to get the correct serviceID:
http://forum.micasaverde.com/index.php/topic,18679.msg201301.html#msg201301

Thanks Richard. I got the service ID from the advanced tab but I did not realize that there are several service IDs. I will check it when I get home.

Thank you.

Richard,

You were correct. But you already knew that… the serviceID was incorrect and now it works perfectly.

Thank you.