[SOLVED] Can't Convert Celsius to Fahrenheit in template widget

Hi guys. I’m having a bit of trouble and was wondering if anyone could help me. I bought some Xiaomi temperature and humidity sensors to put around my house. I am trying to convert the values from Celsius to Fahrenheit but can’t seem to figure out how to do it. I am attempting to do this in a template widget. I read on the forum that you should be able to just do the math within the widget but that doesn’t seem to work. This is what I have.

Room Temp

Temperature: {{itemValue('Room_Temperature') * 1.8 + 32}}

When I do that the value is returned as NaN. Anyone know what im doing wrong here?

Please post your item definitions

Sorry about that. Here is the items file for the gateway and one of the sensors

//Gateway
Switch Gateway_AddDevice { channel=“mihome:gateway:7c49eb1b8f29:joinPermission” }
Dimmer Gateway_Brightness { channel=“mihome:gateway:7c49eb1b8f29:brightness” }
Color Gateway_Color { channel=“mihome:gateway:7c49eb1b8f29:color” }
Dimmer Gateway_ColorTemperature { channel=“mihome:gateway:7c49eb1b8f29:colorTemperature” }
Number Gateway_AmbientLight { channel=“mihome:gateway:7c49eb1b8f29:illumination” }
Number Gateway_Sound { channel=“mihome:gateway:7c49eb1b8f29:sound” }
Switch Gateway_SoundSwitch <soundvolume_mute> { channel=“mihome:gateway:7c49eb1b8f29:enableSound” }
Dimmer Gateway_SoundVolume { channel=“mihome:gateway:7c49eb1b8f29:volume” }

//Basement Temperature and Humidity Sensor
Number:Temperature Basement_HT_Temperature { channel=“mihome:sensor_ht:158d00023d295f:temperature” }
Number:Dimensionless Basement_HT_Humidity { channel=“mihome:sensor_ht:158d00023d295f:humidity” }
Number Basement_HT_Battery { channel=“mihome:sensor_ht:158d00023d295f:batteryLevel” }
Switch Basement_HT_BatteryLow { channel=“mihome:sensor_ht:158d00023d295f:lowBattery” }

Number:Temperature Basement_HT_Temperature "[%.1f °F]" { channel=“mihome:sensor_ht:158d00023d295f:temperature” }

Should do the trick!

2 Likes

@vzorglub Beat me to it again.:rofl:

I was trying to remember how to make the degrees symbol on my linux PC.:roll_eyes:

1 Like

Thank you so much. I’m going to try this when I get home. That Xiaomi Gateway is a PIA. I’m going to reset it and start this from scratch.

I never remember I copy them from the openhab log!!

Got it,:laughing: F °

Ctrl + Shift + u (this will show an underlined u) and then the unicode value (in this case B0 ) and follow it by an enter.

So I just tried what you said and it just put the F° on there but still the C° number value. Can I put a math conversion in what you gave me to change the value?

Yes,
Change your item:

Number:Temperature Basement_HT_Temperature "[%.1f °C]" { channel=“mihome:sensor_ht:158d00023d295f:temperature” }

in your sitemap:

Text item=Basement_HT_Temperature label="Temp Basement [%.1f °F]"

And OH will handle the conversion

2 Likes

I was able to get this to work in the site map with the changes you suggested. I am trying to use the Habpanel to display this information because this is going to be a wall mounted set up. I was looking at doing this through a custom template. But it doesn’t seem to work there.

Im using the following in a custom widget {{itemValue(‘Basement_HT_Temperature’)}}

Try this

{{'% .1f' | sprintf: itemValue ('Basement_HT_Temperature'). split ('') [0]}}

That didn’t work either it just output the text

Im still learning HABPanel myself.:grinning:

Try this

{{itemValue('Basement_HT_Temperature').split(' ')[1]}}

Trust me I appreciate all your help here, I’m new to this too. When i did that it just gives me the C degree, no value

Forgot the first part.:roll_eyes:

{{'%.1f' | sprintf:itemValue('Basement_HT_Temperature').split(' ')[0]}}{{itemValue('Basement_HT_Temperature').split(' ')[1]}}

Ok that got me the value reported by the item, so now it says 21.4C. Still not in Fahrenheit

If you drop the UOM on the item, like below, what happens?

Number Basement_HT_Temperature "[%.1f °F]" { channel=“mihome:sensor_ht:158d00023d295f:temperature” }

That changed the C to an F but still the Celsius value displayed. So now it says 21.4F

Yep, that confirms that the UOM takes care of the conversion from item to sitemap only.:expressionless:

May need a rule to convert the temp.:thinking: