Postupdate and UoM driving me crazy

Hmmm… how about…

1 Like

Ok - Progress…

@rossko57 was on to something here…I re-read his comments and made the following changes.

I changed my line in HabPanel from:

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

to

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

Which gives me a display of temp in Fahrenheit! YAY!..but the value contains a decimal + 3 digits.

image

My items contains formatting which should keep it as a whole number…right?

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

There’s something you have to do in HABpanel to select “use server formatting” which should use the [stuff] like the other sitemap based UIs.

1 Like

Unfortunately, no. The API doesn’t apply the formatting, it’s left to the client, which is weird indeed since the server would be in the best position to do it. It’ll improve in 3.0, but in 2.5 that’s what you have to deal with. And since states are not really numbers because the unit is affixed to it, the client “sprintf” fails, so what you have to do is split the value and the unit, sprintf the first part and append the unit back, like so:

<h2 style="margin-bottom:1em;">
{{('%.0f' | sprintf:itemState('Weather_Temperature').split(' ')[0]) + ' ' +
itemState('Weather_Temperature').split(' ')[1}}
</h2>

@ysc

Glad to see I wasn’t completely off base… :stuck_out_tongue:

So I’ve taken your code:

      <h2 style="margin-bottom:1em;">{{('%.0f' | sprintf:itemState('Weather_Temperature2').split(' ')[0]) + ' ' +itemState('Weather_Temperature2').split(' ')[1}}</h2>

With my item:

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

and I get…a mess


It breaks all of my other items on the page as well

1 Like

it’s missing a ] before the }}

2 Likes

Learnt something, I was sure it did do number format too, and was wrong there.

Why do you keep regressing to %unit% ? It’ll default, which ought to be right for you … but after all this trouble you can just tell it to do F regardless.
“[%.0f °F]”

2 Likes

Yup - that was it…

Many thanks,

Squid :squid:

3 Likes

@ysc

Thank you for the assistance on this, with your formatting I finally have Fahrenheit values where I want them. I never would have figured out the split without your guidance.

As an FYI - when I first dropped the code into HabPanel I was still seeing Celsius values… I went and checked to make sure all of my regional settings were correct, and indeed they were. Then about 3 minutes past posting the code they changed. I don’t know if it was something cached, but each line I updated with the new code took a couple of minutes to show the Fahrenheit value.

Again…many thanks!

Squid :squid:

1 Like

Your Item is updated by a weather binding. That only happens periodically.

1 Like

But wouldn’t the UoM convert the current value?

1 Like