In trouble with a simple arithmetic operation

Hi,
I am trying to calculate a numeric value based on outside temperature, but the result makes me confused. I am sure I do something totally wrong. :slight_smile:

Outside temperature item config
Number:Temperature Temp_Outside "Kinti hőmérséklet [%.1f °C]" (Temperatures, Outside) { channel="onewire:basic:bridge:outside_temp:temperature" }

Calculation
I am trying to calculate seconds based on outside temp. to create a timer.
var tempasnumber = Temp_Outside.state as Number
var fireplace_mode_time = 900 - (tempasnumber * 60)
In case of %C outside temp. it should result 300, but I get -15789.00 Could you please help me to fix this simple calculation?

Thank you,

It’s not a Number, it’s a Number:Temperature. That means it carries units of measurement. You need to convert it to a plain old number if you need to combine it with values of other units.

var tempasnumber = (Temp_Outside.state as QuantityType<Temperatuer>).floatValue

or something like that. You might want to log out that the floatValue is as it’s possible for the Item to be carrying the temp as a different unit (e.g. degrees F) but you wouldn’t know it because it converts to to C for you.

2 Likes

Thank you :+1: