When the code below runs the SensorValue is reported as temperature : 182388.2
case "F":
SensorValue = 20
SensorValue = celsiusToFahrenheit(SensorValue)
sendEvent(name: "temperature", value: SensorValue, unit:"F", isStateChange: true)
log.info ("in Case F")
break
When I comment out the line " SensorValue = celsiusToFahrenheit(SensorValue)" the value 20 is reported.
I'm assuming either I'm missing something (maybe an imported library is needed). Or is it just not implemented?
John
running this:
def SensorValue = 20
log.debug celsiusToFahrenheit(SensorValue)
i get 68...
1 Like
celsiusToFahrenheit()
isn't Groovy per se but is a method provided by Hubitat's app and driver runtime environment. But yes, your code looks valid--a bit unconventional, maybe (variable names normally use camelCase
per Groovy/Java convention), but that shouldn't actually affect any outcomes.
But speaking of SensorValue
, what is that and where is it defined? If your intent was to define it inside this case
(actually, inside the switch
--the scope of any variable defined in a case
), then I'd use def sensorValue
or BigDecimal sensorValue
. (In regular Groovy scripts, variables "defined" without def
or a type have a special script-wide meaning; I'm not sure if/how Hubitat's driver environment affects this, but I'd do it as you likely intended regardless. Unless you already did somewhere we can't see, and in that case, more context might be helpful.)
3 Likes
Thank you and Mike.Maxwell ![:slight_smile: :slight_smile:](https://community.hubitat.com/images/emoji/apple/slight_smile.png?v=9)
I think I need to understand scope in groovy better.
Thank you both.