[solved] Are any math functions usable in rules?

Moderators: Voyager, BertB, rtenklooster, Stuntteam, grovkillen, TD-er

Post Reply
Message
Author
dampa
Normal user
Posts: 28
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
Normal user
Posts: 2995
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: 28
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
Normal user
Posts: 2995
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:

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests