Feature request: Additional Math functions

Hi. Currently, rule machine supports basic math functions and also abs(), negate() rand() round(); I've used the all.

If it
a) is easy and
b) wouldn't consume too much memory on the Hubitat,
then math functions such as sin, cos, tan, pow, ln, log would be tremendously useful in implementing models related to real-world stuff like solar/power/circadian-cycles/process-lags/temperature-predictions etc.

Currently, I'm using crude polynomial approximations which are a) inaccurate and b) quite the PITA to code in RuleMachine. A quick search of the forum finds only one similar feature request (3 years ago), but maybe folks don't know how useful these functions are until they have them?

Thanks for considering the request.
M.

2 Likes

I don't have an answer for you but perhaps it is already available.

I've seen Hubitat has the ability to import certain special libraries. Some of these I've found in the documentation, some I've not found or not yet needed. Perhaps what you need is already available.

  • import hubitat.helper.ColorUtils
  • import groovy.transform.Field
  • import java.text.SimpleDateFormat
  • import hubitat.zigbee.zcl.DataType
  • import hubitat.helper.HexUtils
  • import groovy.json.JsonOutput
  • import groovy.json.JsonSlurper
  • import java.math.BigDecimal
  • import org.codehaus.groovy.runtime.EncodingGroovyMethods
  • import java.security.MessageDigest
  • ?????. getDefaultImports()

And I've found...

// Java program for sin() method
import java.util.*;
1 Like

That will help for a custom app, which might be something the OP would be interested in doing, but it won't help with Rule Machine (the question at hand). :smiley: On a related note, I just tried this in webCoRE and didn't find any, either.

(And on another related note, if you are interested in writing a custom app, there are several new docs on the docs site to help you get started.)

2 Likes

I thought webcore had power? But no trig functions.

That maybe...I only tried the trig functions.

1 Like

I'll look into it...

3 Likes

those math functions are already there. here is an example of my code calling them.. I did not need any import.. this was in the tesla driver if you want to take a look

1 Like

Because you are using the name of the Math class in your call to these methods (as opposed to, say, a static import).

But the original question was about Rule Machine, anyway, not custom apps/drivers, and Bruce has addressed that now.

4 Likes

new release of webcore adds

math functions: sin, cos, tan, atan2, log, toradians, todegrees

available now for hpm

6 Likes