Jump to content

Welcome to Smart Home Forum by FIBARO

Dear Guest,

 

as you can notice parts of Smart Home Forum by FIBARO is not available for you. You have to register in order to view all content and post in our community. Don't worry! Registration is a simple free process that requires minimal information for you to sign up. Become a part of of Smart Home Forum by FIBARO by creating an account.

 

As a member you can:

  •     Start new topics and reply to others
  •     Follow topics and users to get email updates
  •     Get your own profile page and make new friends
  •     Send personal messages
  •     ... and learn a lot about our system!

 

Regards,

Smart Home Forum by FIBARO Team


stack index 1, expected number, received number: not a numeric type that fits exactly an integer error


Recommended Posts

Posted

Hi, since the last update I cannot have a timeout formula like 

fibaro.setTimeout(1000*60*60*5.5, function()
If i have this 5.5 that multiplies any other big number, the result is this error message:
[ERROR] [SCENE4]: stack index 1, expected number, received number: not a numeric type that fits exactly an integer (number maybe has significant decimals) (bad argument into 'int(unsigned int, const sol::basic_protected_function, false, sol::basic_reference >&)')
 
Changing it to 6 worked fine. I believe this is a bug that should be fixed.
 
Regards
 
 
Posted

No, it's not a bug. Allowing a decimal number is a bug.  Truncate it to a whole number if you need to

Please login or register to see this code.

or redefine the function to allow a decimal but truncate it

Please login or register to see this code.

...if you have that problem in many places in your code.

  • Like 2
  • 3 weeks later...
Posted

Hey Guys, I'm having the same issue recently regarding a wake up automation on my lights. In the morning, I've my bedroom lights to gradually go up at a specific time, for about 15 min. 

 

The last few days (after the update) it stopped working and I'm getting a similar error - stack index 1, expected number, received number: not a numeric type that fits exactly an integer (number maybe has significant decimals) (bad argument into 'void(unsigned int)')

 

I don't have decimals set by myself on the code and the increments on light and timer values are all integer also. Any idea of what could be causing this?

 

Thanks

 

The code I'm using:

--[[
%% properties
%% globals
--]]
 
_ledstripe = 171; --light id
_spotlight = 41; --light id
_maxValue = 100; --Max value you want the light to be
_duration = 15; --The time in minutes to go to the max level
 
fibaro.call(_ledstripe, "setValue",0);
fibaro.call(_spotlight, "setValue",0);
fibaro.sleep(200);
fibaro.debug('Start Wake-up Light');
duration = 60 *tonumber(_duration);
duration = duration /_maxValue;
for variable = 0, _maxValue - 1, 1 do
 local newValue = tonumber(fibaro.getValue(_ledstripe, "value")) + 1;
 fibaro.debug('Increase value to ' ..  newValue);
 --Increases the value of the lamp
 fibaro.call(_ledstripe, "setValue", newValue);
 fibaro.call(_spotlight, "setValue", newValue);
 --Waits before the next step
   fibaro.sleep(duration *1000);
end
fibaro.sleep(30 *60 *1000);
fibaro.call(_ledstripe, "turnOff"); --turn OFF
fibaro.call(_spotlight, "turnOff"); --turn OFF
Posted

duration = duration /_maxValue; -- result in float/decimal number
 :
 --Waits before the next step
   fibaro.sleep(duration *1000); -- call sleep with decimal number
end
Posted (edited)

Thanks jgab, not sure why/how that would result in a float/decimal number.

 

_duration = 15

_maxValue = 100

 

during the sequence I do:

duration = _duration*60 - This would be 15*60=900

duration = duration /_maxValue - This would then be 900/100 = 9 which is not a float/decimal number.

 

Not sure I'm following your logic / results there :S

 

(Still not getting why...but applied the math.floor () suggested and is back working 🤷‍♂️ - Thanks for your help jgab)

Edited by Bruno Nunes
Posted (edited)

Please login or register to see this link.



3.4.1 – 

Please login or register to see this link.

Lua supports the following arithmetic operators:

  • +: addition
  • -: subtraction
  • *: multiplication
  • /: float division
  • //: floor division
  • %: modulo
  • ^: exponentiation
  • -: unary minus

With the exception of exponentiation and float division, the arithmetic operators work as follows: If both operands are integers, the operation is performed over integers and the result is an integer. Otherwise, if both operands are numbers or strings that can be converted to numbers (see 

Please login or register to see this link.

), then they are converted to floats, the operation is performed following the usual rules for floating-point arithmetic (usually the IEEE 754 standard), and the result is a float.

Exponentiation and float division (/) always convert their operands to floats and the result is always a float. Exponentiation uses the ISO C function pow, so that it works for non-integer exponents too.

Floor division (//) is a division that rounds the quotient towards minus infinity, that is, the floor of the division of its operands.

Modulo is defined as the remainder of a division that rounds the quotient towards minus infinity (floor division).

In case of overflows in integer arithmetic, all operations wrap around, according to the usual rules of two-complement arithmetic. (In other words, they return the unique representable integer that is equal modulo 264 to the mathematical result.)

 

This was a bit different in the case of Lua 5.2 that only had the 'number' type. So, I expect that external C libraries just casted it to an int and it worked. These days 5.3> Lua's numbers are either float or integers(hidden behind a common 'number' type, but we can use math.type(..) to check), but when external C libraries gets a number they need to make an decision if it's a float or an integer...

Edited by jgab
  • Like 1

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...