Lua code works in "Test Luup code (Lua)" window but does not work in scene window

I’m starting with a Vera Edge and I can’t get something basic. I’ve done a lot of testing and read hundreds of posts but I can’t find the solution.

The following code:

-------------------------------------------------------
-- READ devices & WRITE total
    local i
    local v=0
    local v0=0
    for i=51,64,1 do
        v0=luup.variable_get("urn:micasaverde-com:serviceId:EnergyMetering1", "Watts", i)  -- read devices
        if (v0 == nil or v0 == '') then
        else
            v=v+v0        
        end
    end
    v=math.floor(10*v+0.5)/10

    luup.variable_set("urn:upnp-org:serviceId:VContainer1", "Variable1", v, 101)  -- write on device #101

return true – of course
-------------------------------------------------------

reads the power (Watts) of devices 51 to 64, adds it and writes it to Variable1 of device # 101 (multistring).

This code works in Lua test but it doesn’t work when I bring it into a scene. I have tried declaring it as a function and calling the function with luup.call_delay or luup_call_timer but I have not gotten it to work.

Can somebody help me?
Thank you very much in advance

I answer myself.
I think adding a final blank line (seen in a tip from @akbooer) has been the solution.

1 Like

I wish I had remembered that earlier!

1 Like