Logic Machine Forum
Take object and record on new object - 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: Take object and record on new object (/showthread.php?tid=3111)



Take object and record on new object - Hugo - 17.01.2021

Is my first scrip, help is very welcome:

powerin = grp.getvalue('1/1/2')
powerout = grp.getvalue('3/1/5')
COP = powerout / powerin
grp.write ('4/1/1', COP)


There should be an "IF" in. The COP should only be calculated if the powerout is bigger than 0 becouse powerout can be up to -7000W heat power and COP should be 0 in that case (is already written to a defreezing obiject by the counter itself so "-" values are to ignoere).


RE: Take object and record on new object - Seijboldt - 18.01.2021

Hi,
I'd probably do it something like this:
Tag both Powerin and powerout objects with something like COP and have the script execute if the group is triggered.

Powerin = grp.getvalue('1/1/2')
Powerout = grp.getvalue('3/1/5')
COP = Powerout / Powerin
if COP > 0 then grp.checkwrite('2/0/157', COP, 1)
end


RE: Take object and record on new object - admin - 18.01.2021

If you want to write zero when COP value is negative you can simply apply math.max:
Code:
COP = math.max(0, Powerout / Powerin)



RE: Take object and record on new object - Hugo - 18.01.2021

Thanks to both of you.