12 second delay with luup.variable_get

I want to turn an outside light on when the door lock is unlocked, but only at night and only when the light previously was off. (The previous-off condition helps in deciding when to turn it back off.)

I created a scene that turns the light on with a trigger that looks for the lock being open. Then I added this luup code:

local MainEntrLightSwitchState = luup.variable_get("urn:upnp-org:serviceId:SwitchPower1", "Status", 3)
if (MainEntrLightSwitchState == "0" and luup.is_night()) then
   -- Switch is on and it is night
   return true
   return false

This works, but there is a delay of about 12 seconds between unlocking the door and the light coming on. When I only look for luup.is_night(), then the delay is less then a second. Thus is seems that the delay is caused by looking up the switch state.

I thought that luup.variable_get() looks for the state the Vera has stored and that it wouldn’t poll the switch.

Does anyone have any theories why this delay is present? Any idea how to get rid of the delay?


You thought correctly. luup.variable_get() shouldn’t be delaying anything. I’ve never seen that sort of behaviour before.

You could poke through the Luup log on the Vera to identify what the holdup is. Also I’d be interested in whether code like this experiences a delay:

local MainEntrLightSwitchState = luup.variable_get("urn:upnp-org:serviceId:SwitchPower1", "Status", 3) return luup.is_night()

I don’t know what has caused the 12 second delay (it was actually more like 13 seconds). I was able to get it down to about 3 seconds.

Here is what I did:

[ol][li]Looked at the Luup log. I found the log entry and timestamp of when the switch was reported as active. The next message in the log came 11 seconds later. Therefore this didn’t help me in finding out why the delay was present. As an afterthought, I should probably have enabled verbose logging[/li]
[li]I then tried to play around with the luup code. Even after deleting the whole code, the delay was still present. This means it wasn’t luup.variable_get() that caused the delay.[/li]
[li]After deleting the whole scene and and re-creating it, I still had the same delay.[/li]
[li]Loaded a backup from before I started the attempt to turn the light on and went step by step setting up the scene and testing it right after I made a single change. I did no longer get into the issue of this long delay.[/li][/ol]

The only difference left between my previous scene (with 13 sec delay) and the new scene (with 3 sec delay) is that I don’t have a delayed action set up within the scene. Before I turned the light on “immediately” within the scene, and off 5 minutes later. Now I only turn it on. A separate scene turns it off, triggered by a “Countdown Timer” (plugin). This should have no impact on delaying the immediate action either way, and it might not have anything to do with it. I simply stopped messing with it further since it works good enough for me now.

In the end: Issue resolved, but root cause not understood.