Im trying to take my home to the next level with a LUA scene.
My code runs fine in the test but doesnt run in the scene.
Can anyone give me some hints?
Im trying to set the temperature in a room depending on my mode.
my code is as folows:
local tHome = 20.0
local tAway = 14.0
local tNight = 18.0
local tVacation = 10.0
local tSet = 10.0
local lul_mode =luup.variable_get(“urn:micasaverde-com:serviceId:HouseModes1”,“HMode”, 32)
local lul_temp = luup.variable_get(“urn:upnp-org:serviceId:TemperatureSensor1”,“CurrentTemperature”, 14)
if (tonumber(lul_mode) == 1) then
tSet = tHome
end
if (tonumber(lul_mode) == 2) then
tSet = tAway
end
if (tonumber(lul_mode) == 3) then
tSet = tNight
end
if (tonumber(lul_mode) == 4) then
tSet = tVacation
end
if (tonumber(lul_temp) < tSet) then
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”, “SetTarget”, {newTargetValue = “1”}, 28)
end
if (tonumber(lul_temp) > tSet) then
luup.call_action(“urn:upnp-org:serviceId:SwitchPower1”, “SetTarget”, {newTargetValue = “0”}, 28)
end
Can you explain what you mean by it works find in test but not in a scene?
Assuming you meant you ran the LUA code in the develope app test lua area and it worked?
When you paste the same code into a scene and run the scene manually it does not work?
Or are you trying to trigger the scene some how and that is what is not working?
Try using the debug procedure KWIKLOG as described in the conditional scenes sticky thread:
function kwikLog(message, clear)
if bTrace == 1 then
local socket = require("socket")
local time = socket.gettime() or os.time()
local tms = string.format(".%03d ",math.floor (1000 * (time % 1)))
local stamp = os.date("%d %b %Y %T",math.floor(time)) .. tms
local mode = "a+"
if clear then mode = "w+" end
local file = io.open("/www/kwikLog.txt", mode)
file:write(stamp .. (message or "") .. "\n")
file:close()
end
end
I place the above in the startup code section. I use the global “bTrace” variable so that I can start or stop logging at anytime.
I then place kwiklog statements inside my problem scene (remember to set bTrace to true):