[solved] Are any math functions usable in rules?

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
dampa
Normal user
Posts: 87
Joined: 19 Jul 2018, 01:48

[solved] Are any math functions usable in rules?

#1 Post by dampa » 05 Mar 2019, 20:10

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?
Last edited by dampa on 05 Mar 2019, 21:00, edited 1 time in total.

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Are any math functions usable in rules?

#2 Post by grovkillen » 05 Mar 2019, 20:36

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.
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

dampa
Normal user
Posts: 87
Joined: 19 Jul 2018, 01:48

Re: Are any math functions usable in rules?

#3 Post by dampa » 05 Mar 2019, 20:59

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!!

User avatar
schnurzel59
Normal user
Posts: 32
Joined: 18 Feb 2019, 12:41
Location: Germany
Contact:

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

#4 Post by schnurzel59 » 09 Mar 2019, 00:50

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
Greetings Martin

Oh God, my English is horrible.

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

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

#5 Post by grovkillen » 09 Mar 2019, 09:16

Please report this on GitHub
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

happytm
Normal user
Posts: 107
Joined: 15 Aug 2016, 17:53

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

#6 Post by happytm » 04 Jul 2019, 23:19

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

happytm
Normal user
Posts: 107
Joined: 15 Aug 2016, 17:53

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

#7 Post by happytm » 05 Jul 2019, 01:34

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

skwaruch
New user
Posts: 8
Joined: 03 Jan 2020, 14:08

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

#8 Post by skwaruch » 04 Jan 2020, 00:01

The exponentiation doesn't work.
TaskValueSet,11,4,2^57 = 0.
Do you know why?

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

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

#9 Post by TD-er » 04 Jan 2020, 12:34

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.

skwaruch
New user
Posts: 8
Joined: 03 Jan 2020, 14:08

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

#10 Post by skwaruch » 04 Jan 2020, 12:41

2^2 = 0
2^1 = 0

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

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

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

#11 Post by TD-er » 05 Jan 2020, 01:18

So it is no longer an issue?

skwaruch
New user
Posts: 8
Joined: 03 Jan 2020, 14:08

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

#12 Post by skwaruch » 06 Jan 2020, 16:02

Yes, everything OK

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 20 guests