Page 1 of 1

[solved] Are any math functions usable in rules?

Posted: 05 Mar 2019, 20:10
by dampa
Here is my situation. I have a 12 LED ring to be used as a clock. What I want to do is light an led based on the minutes. With the 12:00 o'clock position being led 1, 1 o'clock position is led 2, 2 o'clock position is led 3 etc,

Between hh:00 and hh:04 led 1 should be lit, between hh:05 to hh:09 led 2 should be lit etc.

In the rules you have assess to %sysmin% which gives out the curent minute so at 7:02 %sysmin% is 2. If I code %sysmin%+5/5 I would get 1.4 and if I put that into a taskvalue with no decimal places you will get 1 - so far so good.

Now lets look at what happens at 7:03 - 3+5/5 = 1.6 but when I put it into the task value, it rounds up to 2 lighting the wrong led.

In most computer languages you can get just the integer portion of the value - is it possible to do in the rules?

Re: Are any math functions usable in rules?

Posted: 05 Mar 2019, 20:36
by grovkillen
No you don't get a integer no. You can replace like this though:

Code: Select all

%syshour%%sysmin%
Given clock being 12:30 that would be replaced with 1230 which is an integer.

Re: Are any math functions usable in rules?

Posted: 05 Mar 2019, 20:59
by dampa
Ahh but that doesn't address my issue ie I need to range 1-60 to 1-12 ie i can grab %sysmin% and it the time is 3:04 then the 04 should be ranged to 1 while 3:05 will range to 2

If I use the formula mm+5/5 and could truncate the decimal portion I would be fine


Wait, I found an answer. I was using that formular and storing it in a task value. That taskvalue was used to set the neopixel LED number. Originally the task value was set to have no decimal places and so it was always rounding causing the issue. By changing the taskvalue to have a decimal point itr works!!

I'm guessing that the neopixel must be dumping the decimal portion of the number!!

Re: [solved] Are any math functions usable in rules?

Posted: 09 Mar 2019, 00:50
by schnurzel59
Hi,
The math functions are a bit confusing. The following examples speak for themselves.
TaskValueSet,11,4,465-789 --- = -324 ok
TaskValueSet,11,4,45/7-------- = 6,4286 ok
TaskValueSet,11,4,3*98 -------- =294 ök
TaskValueSet,11,4,2^57 -------- =144115188075855870
18 digits are stored without any problems.But only if it is a potency of 2.
A direct entry of 123456789123 becomes too123456790528.
"TaskValueSet,11,4,123456789123"
The entered value is overwritten immediately after it is displayed in the devices.

TaskValueSet,11,4,3+6 -------- =3 ?????????????
Addition does not work ????
Hard to understand
Beste Grüße
Martin

Re: [solved] Are any math functions usable in rules?

Posted: 09 Mar 2019, 09:16
by grovkillen
Please report this on GitHub

Re: [solved] Are any math functions usable in rules?

Posted: 04 Jul 2019, 23:19
by happytm
Dampa,

Did you get your 12 led clock working. If so can you post your rule set please.Also wondering if it is possible to use two different colors for hour and minute leds.

Thanks

Re: [solved] Are any math functions usable in rules?

Posted: 05 Jul 2019, 01:34
by happytm
I tried to create 12 led clock using neopixel(basic) and dummy sensor task with quad selected as sensors. I came up with following rules which seems to do the job.I know there must be better way to do it so please correct the rules for better.

on clock#time do
timerSet,1,5

TaskValueSet,12,1,%sysmin%/5
TaskValueSet,12,2,[dummy#minutenow]-1
TaskValueSet,12,3,%syshour%
if [dummy#hournow]>12
TaskValueSet,12,3,[dummy#hournow]-12
endif
TaskValueSet,12,4,[dummy#hournow]-1

if [dummy#minutenow]=[dummy#hournow]
neopixel,[dummy#minutenow],255,255,255
else
neopixel,[dummy#minutenow],0,55,0
neopixel,[dummy#minutenow],0,0,255
neopixel,[dummy#minuteprev],0,0,0
neopixel,[dummy#hournow],255,0,0
neopixel,[dummy#hourprev],0,0,0

endif

endon



on Rules#timer=1 do

neopixel,1,0,55,0
timerSet,2,1

endon

on Rules#timer=2 do

neopixel,1,0,0,0
timerSet,1,5

endon

Thanks

Re: [solved] Are any math functions usable in rules?

Posted: 04 Jan 2020, 00:01
by skwaruch
The exponentiation doesn't work.
TaskValueSet,11,4,2^57 = 0.
Do you know why?

Re: [solved] Are any math functions usable in rules?

Posted: 04 Jan 2020, 12:34
by TD-er
Intermediate values will be kept as float, so you may loose precision after 6 or 7 decimals.
2^50 should yield a value of about 10^15, but it may not be exact anymore.
Not sure how the float to string will handle that value as it may represent it something like 1.234e15 and I am not sure if the parsing will handle the "e" correctly.
So it may consider the value to be an invalid numerical and return 0.

That's a bug.

Can you test with lower values to see if it does work with lower values?
And please report it as an issue on GitHub.

Re: [solved] Are any math functions usable in rules?

Posted: 04 Jan 2020, 12:41
by skwaruch
2^2 = 0
2^1 = 0

exponentiation does not work on the old version,
I uploaded a new one and it works

Re: [solved] Are any math functions usable in rules?

Posted: 05 Jan 2020, 01:18
by TD-er
So it is no longer an issue?

Re: [solved] Are any math functions usable in rules?

Posted: 06 Jan 2020, 16:02
by skwaruch
Yes, everything OK