I'm trying to get a temperature humidity sensor to compare to another to determine if the amount of humidity is high and if so start an exhaust fan. Program runs fine but I want to change from a humidity comparison to a dewpoint comparison to make it more reliable. In that calculation I need to take the log() of a number. I know that I need to import java.lang.Math for the function but I cannot get it working.
I know it is the log() function causing issues because I've removed that part of the equation and it runs through the sub-routine fine. This is in a driver not and app, could that be the issue?
You never said what the exact problem was, but here's a guess: is this getting shown as null when you print the value on your log.info line? If so, that's because you're declaring this variable inside your if/else (actually two different ones, each with their own scope, only inside the if or else and no longer accessible once you're outside that block).
To fix, declare this variable somewhere before that so it is still in scope by the time you need it. Right before (and outside of) your if is one place that would work. What you wrote should work, though in Groovy you'll normally see something like this:
Typically you would use either "def" or "Double" but not both. def is used to define an untyped variable. Also be careful with doing math on doubles, you can get odd decimals, its a java thing. For the best precision decimals use type BigDecimal.
I switched back to "import java.math.BigDecimal" and everything still worked.
Thanks for the extra input on my work. It is bound to pay off in the future.
BigDecimal is imported by default in Groovy, including the Hubitat app and driver environment, and it should not be necessary to do so yourself. If you find the need to do so, something else is probably going on...