Hi,
I have a specific scenario where I want to pass an HTTP request command that includes the maximum value of the last 5 wind sensor readings. I have confirmed that the template variables [wind0wind-prev1], [wind0wind-prev2], [wind0wind-prev3], etc... are returning the correct values that I want, and I am trying to figure out if there is an expression available to get the maximum value from that list if template variables.
I see in the documentation there are numerical expressions "max" and "min", can that be used in this scenario? If so, what would the syntax be to take the maximum of an array of variables?
Let me know if anyone has any ideas.
Thank you very much.
Numerical expression for obtaining max from list of variables
Moderator: Mattk
Re: Numerical expression for obtaining max from list of variables
For that specific scenario I don't believe there is a specific selector but Add (+) the last/previous five(5) prev1, 2, 3, 4&5 values and divide (/) by 5
Re: Numerical expression for obtaining max from list of variables
Thanks yeah, I was going to try to calc the average instead but I can't seem to get the sum (+) expression to work. Minus, multiply and divide work fine.Mattk wrote: Tue Jan 30, 2024 1:11 am For that specific scenario I don't believe there is a specific selector but Add (+) the last/previous five(5) prev1, 2, 3, 4&5 values and divide (/) by 5
If I try this simple test passing to my MB, it seems to ignore the +100:
http://x.x.x.x/cgi-bin/template.cgi?template={*[wind0wind-act=mph.1:0]+100*}&contenttype=text/plain;charset=iso-8859-1
But - , * and / work as expected. Is it because + is a special character in the URL?
Re: Numerical expression for obtaining max from list of variables
Actually, looks like the “+” expression is working for me when I put it in the actual HTTP request URL in MB. So I’ve got that working to get the average of the last 5 wind sensor readings.
It would be good if I could get the max, but this works for now. Thanks!
It would be good if I could get the max, but this works for now. Thanks!
Re: Numerical expression for obtaining max from list of variables
Sorry where did I get the average from? You wanted the Max over the previous 5 instances. However Sum (+) does work ok as in the following average mock up to email.
Avg5#Avg5={*([wind0wind-prev1]+[wind0wind-prev3]+[wind0wind-prev5])/3*}
Need to think some more regard the Max from the prevx instances.
Avg5#Avg5={*([wind0wind-prev1]+[wind0wind-prev3]+[wind0wind-prev5])/3*}
Need to think some more regard the Max from the prevx instances.