Postupdate and UoM driving me crazy

I obviously must be missing something here…

It seems that HabPanel does not like UoM and my weather items need to be transformed from Celsius to Fahrenheit. I spent a great deal of time trying to inline convert and was not successful.

So my next plan of attack was to create dummy items with the correct Fahrenheit temperatures that work as intended on the sitemaps.

For Example, I have this item:

Number:Temperature localCurrentTemperature "Current temperature [%.0f %unit%]" <temperature> { channel="darksky:weather-and-forecast:ead7c7a1:current#temperature" }

Which generates the correct data:

image

So my plan was to create a dummy item and then postupdate it’s value

Here’s the dummy item:

Number Weather_Temperature_R "[%.0f %unit%]" 

And the rule to update it:

rule "current temp"

when
    Item Weather_Temperature changed
	
then

Weather_Temperature_R.postUpdate(Weather_Temperature.state)

end

When the rule runs, I get the Celsius value, not the Fahrenheit value that’s displayed on the sitemap…
image

What am I missing or doing wrong???

And yes, I have my settings set to the US and Imperial Units.

If HabPanel would take a Number:Temperature I would be in business.

1 Like

Have you tried Number:Temperature Weather_Temperature_R "[%.0f %unit%]" ?

1 Like

I can’t use it in HabPanel hence my desire to create a number value only

2 Likes

Try this rule example:

rule "temp"
when
	Item Weather_Temperature received update
then 
	var celsius = Weather_Temperature .state as Number
        var Number fahrenheit = (celsius * 1.8) + 32
        Weather_Temperature_R.postUpdate(fahrenheit)
end

@KidSquid EDIT: I just changed the item names to match yours. :wink:

1 Like

Because that’s the default UoM.
Check the ‘Scripts & Rules’ section of https://www.eclipse.org/smarthome/blog/2018/02/22/units-of-measurement.html .

1 Like

The chart here is incorrect?

image

1 Like

QuantityTypes can be converted to whatever compatible units you want. To use a Number:Temperature Item to update a Number Item with temperatures in Centrigrade, you can do something like this…

Weather_Temperature_R.postUpdate(Weather_Temperature.getStateAs(QuantityType).toUnit("°C").doubleValue)
1 Like

I need Fahrenheit so can I simply just switch .toUnit(“°C”) to .toUnit(“°F”) ???

1 Like

Exactly… I misread your OP. But I’m confused… how are you getting Celcius? If your locale is set properly, you should be getting Fahrenheit already and just need to strip the units.

1 Like

Color me confused as well…

I have my local/regional settings set as:


image

Which should have me set to Fahrenheit. Is their another area I need to set?

1 Like

No, that should do it. Have you restarted OH since setting it?

1 Like

yup,many times and have cleared cache and tmp

1 Like

Instead of this…

Number:Temperature localCurrentTemperature "Current temperature [%.0f %unit%]" <temperature> { channel="darksky:weather-and-forecast:ead7c7a1:current#temperature" }

Try this…

Number:Temperature localCurrentTemperature "Current temperature [%.0f °F]" <temperature> { channel="darksky:weather-and-forecast:ead7c7a1:current#temperature" }

Scott -

My original item works as it’s supposed to and when placed in Basic UI it delivers temps in Fahrenheit as expected. Where I’m having difficulty is trying to get this into HabPanel. HabPanel will not accept number:temperature so I can’t use it. It will accept Number, but when used it comes in as Celsius…hence the need to convert.

1 Like

It if uses the Item label, specifying F might just work. I do not use HABPanel.

1 Like

@ysc Can you provide any HabPanel insight here?

Why can’t I use Number:Temperature?

1 Like

It’s in the other thread you abandoned. ‘Server supplied’ state “65 °F” is a string, so you cannot format it with sprintf %.0f at the habpanel widget (You don’t need to when you format it with %.0f at the sever end).

1 Like

I did not abandon the thread…I could not get it to work so I tried another approach…and did not want to clutter the two.

So you are saying this line from HabPanel

<h2 style="margin-bottom:1em;">{{'%.0f' | sprintf:itemValue('Weather_Temperature_R')}} °F</h2>

should be:

<h2 style="margin-bottom:1em;">{(itemValue('Weather_Temperature_R')}} °F</h2>
1 Like

I just setup Darksky with a temperature Item like you have, a Number Item, and a rule like in your OP. I do not get Celsius values in a rule. BTW, this should give an error, since %unit% is only for UoM Items, but it does not…

Number Weather_Temperature_R "[%.0f %unit%]" 

The only other thing I can think of is that you have not set the location for the Darksky Local Weather and Forecast Thing and that this is somehow tripping things up. Mine is set. O wait… what version of OH are you using!?

1 Like

OH version 2.5.2

Just checked the local thing config and my coordinates are in there no other locale setting.

1 Like