Turning on light if Motion and Brightness below X

Hi Expert
I am trying to write the above however I hit error when testing the Luup code from if onwards.
Anyone able to advise?

It seems stating a variable cannot have any formula e.g.
local brightness = tonumber(luup.variable_get(“urn:micasaverde-com:serviceId:LightSensor:1”,“CurrentLevel”,sensorID))

local lightID = 292
local sensorID = 205
local dim = 4
local status =luup.variable_get(“urn:upnp-org:serviceId:SwitchPower1”, “Status”, lightID)
local brightness = luup.variable_get(“urn:micasaverde-com:serviceId:LightSensor:1”,“CurrentLevel”,sensorID)
local isNight = luup.is_night()
local bright = tonumber(brightness)
if status == “0” then
if bright < dim or isNight then
return true
end
else
return false
end
end

Hi,

Luup.variable_get returns two values on success. The value and a timestamp. tonumber takes two arguments, the number and the base. For the latter you want to use 10, but you are passing the timestamp in your example so tonumber will fail. You can rewrite in one line as follows:

local brightness = tonumber((luup.variable_get("urn:micasaverde-com:serviceId:LightSensor:1","CurrentLevel",sensorID)),10)

However, if your luup.variable_get fails your code will still fail.

Cheers Rene