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

If you check the logs, does the second item (Basement_HT_Temperature1) post the temp in Fahrenheit?

2018-12-13 11:26:20.869 [ome.event.ItemUpdatedEvent] - Item ‘Basement_HT_Temperature1’ has been updated.

But like you said i might have to wait for it to update again

The item is updated, if you add the second item to your sitemap it should post the Fahrenheit reading.

This should be all that’s needed to see the temp on BasicUI.

Text item=Basement_HT_Temperature1 

Verify the above is working then move to your widget.

ok i will try this out and report back. Thank you guys again for all your help. I’m determined to get this working!

Just to let everyone know, I was able to get this working by using JavaScript. Here is what worked for me.

Item:
Number Basement_HT_JavaTemp “Temperature [JS(convert.js):%s F]” { channel=“mihome:XXXXXXXXX:temperature” }

Then wrote a JavaScript file and put it in the openhab2/transform directory

(function(i) {
//Converts °C to °F or °F to °C.
var res = i.split(" ");

//Check requested scale
if(res[1] == "F"){
	var degrees = (res[0] * (9/5)) + 32;
	var scale = " F";
} else if (res[1] == "C") {
	var degrees = (res[0] - 32) * (5/9);		
	var scale = " C";
} else {
	//No scale passed
	var degrees = 1000;
	var scale = " ERROR";
}

//Return result with one decimal accuracy
return +degrees.toFixed(1) + scale;
})(input)

Doing this I was able to report the value into a dummy widget and it reported correctly. Then I used this to make a custom widget template with various code could on the forums to give me the desired result. Here is the code to the widget.

<h4>Basement</h4>
<div class="row">
<div class="col-xs-6"><span><widget-icon iconset="'smarthome-set'" icon="'temperature'" /> 
</span>Temp</div>
<div class="col-xs-6"><span><widget-icon iconset="'smarthome-set'" icon="'drop'" /> 
</span>Humidity</div>
</div>

<div class="row">
<div class="col-xs-6"><span style="color: cyan; font-size: 20pt">{{itemValue('Basement_HT_JavaTemp')}} 
</span></div>
<div class="col-xs-6"><span style="color: cyan; font-size: 20pt">{{'%.1f' | 
sprintf:itemValue('Basement_HT_Humidity')}}</span></div>
</div>

And here is the result.
basement

Special thanks to H102 and vzorglub for all their help with this!

2 Likes