Logic Machine Forum
from watt to kilowatt - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: from watt to kilowatt (/showthread.php?tid=5422)



from watt to kilowatt - mai - 20.05.2024

I have done this scritp to change the value from watt/h to kilowatt/h. But it gives me always 0. Why??

-------------------------------------------------------------------------------
function kilowatt()
 
    local value = event.getvalue('32/2/16')
   
 
    if value then
     
        local new_value = value * 0.001
       
        return new_value
    else
     
   
    end
end

local valor = kilowatt()

 
    grp.write('32/2/16', valor)


RE: from watt to kilowatt - admin - 20.05.2024

You need to use a different object/group address to store the kW value. Otherwise your script is an infinite loop which will overload LM.

Simplified version of this script (32/2/17 must not be the triggering object):
Code:
kw = event.getvalue() / 1000
grp.checkupdate('32/2/17', kw)