# Postupdate and UoM driving me crazy

**URL:** <https://community.openhab.org/t/postupdate-and-uom-driving-me-crazy/93898>\
**Category:** Scripts & Rules\
**Tags:** postupdate, uom\
**Created:** [March 1, 2020, 6:44pm UTC](https://community.openhab.org/t/postupdate-and-uom-driving-me-crazy/93898 "2020-03-01T18:44:12Z")\
**Posts on this page:** 11\
**Page:** 2

<div class="post-metadata">

**Author:** ![5iver](https://community.openhab.org/user_avatar/community.openhab.org/5iver/32/21201_2.png) [@5iver](https://community.openhab.org/u/5iver)\
**Post date:** [March 1, 2020, 10:22pm UTC](https://community.openhab.org/t/postupdate-and-uom-driving-me-crazy/93898/21 "2020-03-01T22:22:47Z")

</div>

Hmmm… how about…

> [@Postupdate and UoM driving me crazy](https://community.openhab.org/t/postupdate-and-uom-driving-me-crazy/93898/13):
>
> 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" }

---

<div class="post-metadata">

**Author:** ![KidSquid](https://community.openhab.org/user_avatar/community.openhab.org/kidsquid/32/3985_2.png) [@KidSquid](https://community.openhab.org/u/KidSquid)\
**Post date:** [March 1, 2020, 10:53pm UTC](https://community.openhab.org/t/postupdate-and-uom-driving-me-crazy/93898/22 "2020-03-01T22:53:39Z")

</div>

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:

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

```

to

```csv
<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](https://community-openhab-org.s3.dualstack.eu-central-1.amazonaws.com/original/3X/5/1/51a6794fd236217c9c8c25be084acd23738b3877.png)

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

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

```

---

<div class="post-metadata">

**Author:** ![rossko57](https://community.openhab.org/user_avatar/community.openhab.org/rossko57/32/70263_2.png) [@rossko57](https://community.openhab.org/u/rossko57)\
**Post date:** [March 1, 2020, 11:15pm UTC](https://community.openhab.org/t/postupdate-and-uom-driving-me-crazy/93898/23 "2020-03-01T23:15:22Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ysc](https://community.openhab.org/letter_avatar_proxy/v4/letter/y/e480ec/32.png) [@ysc](https://community.openhab.org/u/ysc)\
**Post date:** [March 2, 2020, 12:28am UTC](https://community.openhab.org/t/postupdate-and-uom-driving-me-crazy/93898/24 "2020-03-02T00:28:23Z")

</div>

> [@KidSquid](#):
>
> My items contains formatting which should keep it as a whole number…right?

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:

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

```

---

<div class="post-metadata">

**Author:** ![KidSquid](https://community.openhab.org/user_avatar/community.openhab.org/kidsquid/32/3985_2.png) [@KidSquid](https://community.openhab.org/u/KidSquid)\
**Post date:** [March 2, 2020, 1:26am UTC](https://community.openhab.org/t/postupdate-and-uom-driving-me-crazy/93898/25 "2020-03-02T01:26:15Z")

</div>

> [@ysc](#):
>
> 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

@ysc

Glad to see I wasn’t completely off base… 😛

So I’ve taken your code:

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

```

With my item:

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

```

and I get…a mess

 ![image](https://community-openhab-org.s3.dualstack.eu-central-1.amazonaws.com/original/3X/0/0/0060fea5f89a9c9c6c6917ed4b80261ded898f55.png)  
It breaks all of my other items on the page as well

---

<div class="post-metadata">

**Author:** ![ysc](https://community.openhab.org/letter_avatar_proxy/v4/letter/y/e480ec/32.png) [@ysc](https://community.openhab.org/u/ysc)\
**Post date:** [March 2, 2020, 1:35am UTC](https://community.openhab.org/t/postupdate-and-uom-driving-me-crazy/93898/26 "2020-03-02T01:35:23Z")

</div>

it’s missing a ] before the }}

---

<div class="post-metadata">

**Author:** ![rossko57](https://community.openhab.org/user_avatar/community.openhab.org/rossko57/32/70263_2.png) [@rossko57](https://community.openhab.org/u/rossko57)\
**Post date:** [March 2, 2020, 1:46am UTC](https://community.openhab.org/t/postupdate-and-uom-driving-me-crazy/93898/27 "2020-03-02T01:46:24Z")

</div>

> [@ysc](#):
>
> The API doesn’t apply the formatting

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

> [@KidSquid](#):
>
> Number:Temperature Weather\_Temperature2 “[%.0f %unit%]”

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]”

---

<div class="post-metadata">

**Author:** ![KidSquid](https://community.openhab.org/user_avatar/community.openhab.org/kidsquid/32/3985_2.png) [@KidSquid](https://community.openhab.org/u/KidSquid)\
**Post date:** [March 2, 2020, 5:14am UTC](https://community.openhab.org/t/postupdate-and-uom-driving-me-crazy/93898/28 "2020-03-02T05:14:28Z")

</div>

> [@ysc](#):
>
> it’s missing a ] before the }}

Yup - that was it…

Many thanks,

Squid 🦑

---

<div class="post-metadata">

**Author:** ![KidSquid](https://community.openhab.org/user_avatar/community.openhab.org/kidsquid/32/3985_2.png) [@KidSquid](https://community.openhab.org/u/KidSquid)\
**Post date:** [March 4, 2020, 2:49am UTC](https://community.openhab.org/t/postupdate-and-uom-driving-me-crazy/93898/29 "2020-03-04T02:49:28Z")

</div>

@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 🦑

---

<div class="post-metadata">

**Author:** ![rossko57](https://community.openhab.org/user_avatar/community.openhab.org/rossko57/32/70263_2.png) [@rossko57](https://community.openhab.org/u/rossko57)\
**Post date:** [March 4, 2020, 10:45am UTC](https://community.openhab.org/t/postupdate-and-uom-driving-me-crazy/93898/30 "2020-03-04T10:45:30Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![KidSquid](https://community.openhab.org/user_avatar/community.openhab.org/kidsquid/32/3985_2.png) [@KidSquid](https://community.openhab.org/u/KidSquid)\
**Post date:** [March 4, 2020, 11:49pm UTC](https://community.openhab.org/t/postupdate-and-uom-driving-me-crazy/93898/31 "2020-03-04T23:49:58Z")

</div>

But wouldn’t the UoM convert the current value?

[Previous page](https://community.openhab.org/t/postupdate-and-uom-driving-me-crazy/93898.md?page=1)
