[solved] Are any math functions usable in rules?
Moderators: grovkillen, Stuntteam, TD-er
[solved] Are any math functions usable in rules?
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?
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.
- grovkillen
- Core team member
- Posts: 3621
- Joined: 19 Jan 2017, 12:56
- Location: Hudiksvall, Sweden
- Contact:
Re: Are any math functions usable in rules?
No you don't get a integer no. You can replace like this though:
Given clock being 12:30 that would be replaced with 1230 which is an integer.
Code: Select all
%syshour%%sysmin%
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
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you
Re: Are any math functions usable in rules?
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!!
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!!
- schnurzel59
- Normal user
- Posts: 32
- Joined: 18 Feb 2019, 12:41
- Location: Germany
- Contact:
Re: [solved] Are any math functions usable in rules?
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
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.
Oh God, my English is horrible.
- 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?
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
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you
Re: [solved] Are any math functions usable in rules?
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
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?
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
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?
The exponentiation doesn't work.
TaskValueSet,11,4,2^57 = 0.
Do you know why?
TaskValueSet,11,4,2^57 = 0.
Do you know why?
Re: [solved] Are any math functions usable in rules?
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.
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?
2^2 = 0
2^1 = 0
exponentiation does not work on the old version,
I uploaded a new one and it works
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?
So it is no longer an issue?
Re: [solved] Are any math functions usable in rules?
Yes, everything OK
Who is online
Users browsing this forum: No registered users and 43 guests