This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

2 byte floating compare
#1
Hello.

I am a little confused how compare 2 byte float values. I have group 2/0/0 with Brightness value in 2 byte floating point and suffix used - 3 LUX.  have compare this value with set point? I tried made set point also in 2 byte floating, not a working idea.. How better compare or before convert my value to numbers? Will it work if setpoint = 0? 

I tried like this:

value = tonumber(event.getvalue())
setpoint = tonumber(grp.getvalue('20/0/5'))
if value >= setpoint then
grp.write('20/2/0', 1)
else
  grp.write('20/2/0', 0)
end
But error... :
User script:2: bad argument #2 to 'tonumber' (number expected, got string)
stack traceback:
[C]: in function 'tonumber'
User script:2: in main chunk

How do my task better? Where better read about values converting/compare in LUA?
Reply
#2
You don't need to call tonumber, the result of event.getvalue and grp.getvalue is already a number if proper data type is set.
Code:
value = event.getvalue()
setpoint = grp.getvalue('20/0/5')
Reply


Forum Jump: