Simple LUUP variable read out fails

Hi All,

I’m trying to learn LUUP through trial and error but for the moment it is mostly error :), so can someone help me a hand.

I have a light sensor with ID number 43, with device id: urn:schemas-micasaverde-com:device:LightSensor:1 & the light level sits in the variable CurrentLevel.

So as test I have created the following LUUP code:

local lul_light = luup.variable_get("urn:schemas-micasaverde-com:device:LightSensor:1","CurrentLevel", 43) if (tonumber(lul_light) < 50) then return false end

When executing this in the “test luup code” I always get code failed. Can someone explain to me what I’m doing wrong?

PS: The give a full picture, I want to create a timer that starts when the desired light level is reached (and keeps above the level during the duration of the timer), when the timer ends there should be send out a notification.

Perhaps also have a look at this snippet (all the way at the bottom).

Thanks, that is what I was looking for.

A quick related question, do I best work with a countdown timer in LUUP or do I need to use an external plugin? In the case of the external plugin, how can you multiple plugins? Ex: when timer reaches 0, then do this with plugin 2.

You may find it easier to achieve this with the Program Logic Timer Switch (PLTS) plugin. If you define your light sensor level as a Device Property, you can arrange the timer to trigger when the light level exceeds some value. You can reset the timer if the light level drops below your threshold. When the time interval elapses, the output turns on. You can define an action for this to switch whatever you want.

For example:

Input Device Property
LightLevel: LightSensor(43) CurrentLevel

Conditions
Interval:
Reset: Off
SwitchMode: Delayed Toggle/Explicit Reset

Condition Expressions
Reset: LightLevel < 50
Trigger: LightLevel > 50

Actions
On:

It easy to add additional terms to this logic if required.