# I gave up on OH 2.3 Unit of Measure (UM)

**URL:** <https://community.openhab.org/t/i-gave-up-on-oh-2-3-unit-of-measure-um/52273>\
**Category:** Scripts & Rules\
**Tags:** rules, state, temperature\
**Created:** [September 25, 2018, 4:25pm UTC](https://community.openhab.org/t/i-gave-up-on-oh-2-3-unit-of-measure-um/52273 "2018-09-25T16:25:24Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Catskinner](https://community.openhab.org/letter_avatar_proxy/v4/letter/c/a183cd/32.png) [@Catskinner](https://community.openhab.org/u/Catskinner)\
**Post date:** [September 25, 2018, 4:25pm UTC](https://community.openhab.org/t/i-gave-up-on-oh-2-3-unit-of-measure-um/52273/1 "2018-09-25T16:25:24Z")

</div>

I basically decided that using units of measure might be a good idea but not for me. For the last 2 days something that should be as easy as evaluating in a rule if the temperature outside is higher than a set threshold became a saga of frustration and trial by errors.

The problem root cause was that the temperature item was defined as a Number:Temperature type and I could not find an easy way to strip the UM from the item state in order to evaluate it against a plain numeric value.

So in the end I thought that I really don’t need this aggravation eating my free time and do what I used to do prior to 2.3, meaning getting and storing the temp sensor results as simple numeric values, which makes everything much simpler in rules and using the sitemap to format the temperature symbol. It works perfectly well that way, but that’s probably because I’m an idiot.

Can someone explain to me why do I really need UM in the items definition and if I really need it, how can I strip the extra text from the item state so that something as simple as deciding if 25 is really higher than 20 will not become a chore?

TIA

---

<div class="post-metadata">

**Author:** ![H102](https://community.openhab.org/user_avatar/community.openhab.org/h102/32/25595_2.png) [@H102](https://community.openhab.org/u/H102)\
**Post date:** [September 25, 2018, 4:33pm UTC](https://community.openhab.org/t/i-gave-up-on-oh-2-3-unit-of-measure-um/52273/2 "2018-09-25T16:33:40Z")

</div>

Did you try using Your\_Item.state as Number in your rules?

---

<div class="post-metadata">

**Author:** ![Catskinner](https://community.openhab.org/letter_avatar_proxy/v4/letter/c/a183cd/32.png) [@Catskinner](https://community.openhab.org/u/Catskinner)\
**Post date:** [September 25, 2018, 4:35pm UTC](https://community.openhab.org/t/i-gave-up-on-oh-2-3-unit-of-measure-um/52273/3 "2018-09-25T16:35:36Z")

</div>

I tried. You can’t use this method because the results are stored as text with the centigrade symbol.

---

<div class="post-metadata">

**Author:** ![H102](https://community.openhab.org/user_avatar/community.openhab.org/h102/32/25595_2.png) [@H102](https://community.openhab.org/u/H102)\
**Post date:** [September 25, 2018, 4:45pm UTC](https://community.openhab.org/t/i-gave-up-on-oh-2-3-unit-of-measure-um/52273/4 "2018-09-25T16:45:05Z")

</div>

How are you getting the outdoor temp in OH, what binding or sensor is used?

---

<div class="post-metadata">

**Author:** ![Catskinner](https://community.openhab.org/letter_avatar_proxy/v4/letter/c/a183cd/32.png) [@Catskinner](https://community.openhab.org/u/Catskinner)\
**Post date:** [September 25, 2018, 4:52pm UTC](https://community.openhab.org/t/i-gave-up-on-oh-2-3-unit-of-measure-um/52273/5 "2018-09-25T16:52:55Z")

</div>

It’s a netatmo weather station. When UM are active the result might come as 30.12345678 ? (? being the symbol for Celsius). This is stored as a text and good luck trying to revert it back into a numeric value.

---

<div class="post-metadata">

**Author:** ![Udo\_Hartmann](https://community.openhab.org/user_avatar/community.openhab.org/udo_hartmann/32/70871_2.png) [@Udo\_Hartmann](https://community.openhab.org/u/Udo_Hartmann)\
**Post date:** [September 25, 2018, 4:54pm UTC](https://community.openhab.org/t/i-gave-up-on-oh-2-3-unit-of-measure-um/52273/6 "2018-09-25T16:54:26Z")

</div>

Well, you don’t **need** UoM, but it would ease some stuff:

- automatically change from e.g. “1500 mA” to “1.5 A”
- automatically change from Fahrenheit to Celsius or Kelvin
- use metric sensors in “imperial” regions and vice versa

to get the value without the unit, just use

```auto
(My_UoM_item.state as QuantityType<Number>)

```

---

<div class="post-metadata">

**Author:** ![Catskinner](https://community.openhab.org/letter_avatar_proxy/v4/letter/c/a183cd/32.png) [@Catskinner](https://community.openhab.org/u/Catskinner)\
**Post date:** [September 25, 2018, 5:00pm UTC](https://community.openhab.org/t/i-gave-up-on-oh-2-3-unit-of-measure-um/52273/7 "2018-09-25T17:00:59Z")

</div>

Yo are right, **I** don’t need it if it turns simple tasks such as deciding if 25C is higher than 20C into a chore. Other who might need to decide if 25C is higher than 68F might find it interesting but I’m not one of them and I seriously doubt this kind of calculation is performed more often than mine.

---

<div class="post-metadata">

**Author:** ![christoph\_wempe](https://community.openhab.org/user_avatar/community.openhab.org/christoph_wempe/32/70848_2.png) [@christoph\_wempe](https://community.openhab.org/u/christoph_wempe)\
**Post date:** [September 25, 2018, 5:14pm UTC](https://community.openhab.org/t/i-gave-up-on-oh-2-3-unit-of-measure-um/52273/8 "2018-09-25T17:14:39Z")

</div>

I discovered yesterday that I have the same problem after I changed my items a few daays ago.

With @Udo_Hartmann post I think I fixed my rules now.

But I had to append ` .doubleValue`.

So Instead of `SunAzimuth.state` I now use:

```auto
var SunPositionAzimuth = (SunAzimuth.state as QuantityType<Number>).doubleValue

```

---

<div class="post-metadata">

**Author:** ![wborn](https://community.openhab.org/user_avatar/community.openhab.org/wborn/32/55946_2.png) [@wborn](https://community.openhab.org/u/wborn)\
**Post date:** [September 25, 2018, 6:24pm UTC](https://community.openhab.org/t/i-gave-up-on-oh-2-3-unit-of-measure-um/52273/9 "2018-09-25T18:24:31Z")

</div>

> [@Catskinner](#):
>
> I could not find an easy way to strip the UM

Don’t give up and strip off units! Just use something like:

```php
if (TemperatureItem.state >= 20|°C) {
    // insert code here
}

```

See also Scripts & Rules in this [Eclipse SmartHome blog](https://www.eclipse.org/smarthome/blog/2018/02/22/units-of-measurement.html).

---

<div class="post-metadata">

**Author:** ![jb4711](https://community.openhab.org/user_avatar/community.openhab.org/jb4711/32/72312_2.png) [@jb4711](https://community.openhab.org/u/jb4711)\
**Post date:** [September 25, 2018, 6:30pm UTC](https://community.openhab.org/t/i-gave-up-on-oh-2-3-unit-of-measure-um/52273/10 "2018-09-25T18:30:43Z")

</div>

Hi,

I just implemented UoM in my binding and like it a lot ([Home Connect binding - #47 by mstehle](https://community.openhab.org/t/home-connect-addon-looking-for-beta-testers/49702/47)). The binding is fetching values from a cloud service - The problem is that this API is able to return °C or °F values. With UoM I can easily process the values, regardless of the passed unit.

Another point I like is the unit conversion. The following example is converting seconds to minutes: `Text item=GeschirrspLer_RemainingProgramTime label="Restliche Programmlaufzeit [%d min]" icon="time"`.

Heres a example of evaluating UoM states in rules:

```auto
        var power = Waschmaschine_Leistung.state
        if (power < 0.2|"W") Washingmachine_OpState.postUpdate(MODE_OFF)
        else if (power > 9|"W") Washingmachine_OpState.postUpdate(MODE_ACTIVE)
        else if (power < 4.4|"W") {

```

---

<div class="post-metadata">

**Author:** ![Catskinner](https://community.openhab.org/letter_avatar_proxy/v4/letter/c/a183cd/32.png) [@Catskinner](https://community.openhab.org/u/Catskinner)\
**Post date:** [September 25, 2018, 6:36pm UTC](https://community.openhab.org/t/i-gave-up-on-oh-2-3-unit-of-measure-um/52273/11 "2018-09-25T18:36:04Z")

</div>

I think I tried that too and it also didn’t work. The thing is that I’m using and playing all the time with OH because it’s my hobby and hobbies are supposed to be fun and educative.

Struggling with UM was neither of them, so while I appreciate the argument of Udo, that UM have some value for converting units, it’s a value that is completely irrelevant in rules where it just add a layer of complexity.

---

<div class="post-metadata">

**Author:** ![wborn](https://community.openhab.org/user_avatar/community.openhab.org/wborn/32/55946_2.png) [@wborn](https://community.openhab.org/u/wborn)\
**Post date:** [September 25, 2018, 6:39pm UTC](https://community.openhab.org/t/i-gave-up-on-oh-2-3-unit-of-measure-um/52273/12 "2018-09-25T18:39:04Z")

</div>

If you don’t like units. AFAIK UoM is backwards compatible.  
So when you define your items you could also try using `Number` instead of `Number:Temperature`

---

<div class="post-metadata">

**Author:** ![Catskinner](https://community.openhab.org/letter_avatar_proxy/v4/letter/c/a183cd/32.png) [@Catskinner](https://community.openhab.org/u/Catskinner)\
**Post date:** [September 25, 2018, 6:47pm UTC](https://community.openhab.org/t/i-gave-up-on-oh-2-3-unit-of-measure-um/52273/13 "2018-09-25T18:47:01Z")

</div>

Which is exactly what I did in the end.

But in case you didn’t notice this backward compatibility isn’t obvious. When 2.3 was released the UM were presented in such a way that I believed it was mandatory to define an item with temperature as Number:Temperature.

---

<div class="post-metadata">

**Author:** ![christoph\_wempe](https://community.openhab.org/user_avatar/community.openhab.org/christoph_wempe/32/70848_2.png) [@christoph\_wempe](https://community.openhab.org/u/christoph_wempe)\
**Post date:** [September 25, 2018, 7:10pm UTC](https://community.openhab.org/t/i-gave-up-on-oh-2-3-unit-of-measure-um/52273/14 "2018-09-25T19:10:17Z")

</div>

> [@wborn](#):
>
> Don’t give up and strip off units! Just use something like:
> 
> ```auto
> if (TemperatureItem.state >= 20|°C) {
> // insert code here
> }
> 
> ```
> 
> See also Scripts & Rules in this [Eclipse SmartHome blog](https://www.eclipse.org/smarthome/blog/2018/02/22/units-of-measurement.html).

I think this should be mentioned in the docs.

> **[QuantityType - Units Of Measurement](https://www.openhab.org/docs/concepts/units-of-measurement.html#quantitytype)**
>
> To express measured values in a scientific correct unit the framework supports units of measurement. By using quantified decimal values in state updates and commands, the framework is able to automatically convert values to a desired unit which may...

It would be really usefull for everyone who reads that page.  
Especially with some examples.

But thanks for that link anyway. 🙂

---

<div class="post-metadata">

**Author:** ![wborn](https://community.openhab.org/user_avatar/community.openhab.org/wborn/32/55946_2.png) [@wborn](https://community.openhab.org/u/wborn)\
**Post date:** [September 26, 2018, 12:30am UTC](https://community.openhab.org/t/i-gave-up-on-oh-2-3-unit-of-measure-um/52273/15 "2018-09-26T00:30:36Z")

</div>

> [@christoph\_wempe](#):
>
> I think this should be mentioned in the docs

I’ve created a documentation issue for this:

> <https://github.com/openhab/openhab-docs/issues/782>
>
> The documentation should explain how to compare QuantityType values when using U…oM.
> 
> It's unknown to many that \`QuantityType\` values can be used directly in comparisons. Often users think they should get hold of the numerical value by using a method or parsing the string value. Instead you can use comparison operators directly, e.g.:
> 
> \`\`\`php
> if (TemperatureItem.state \>= 20|°C) {
> // insert code here
> }
> \`\`\`
> 
> \---
> 
> For examples, see the following community threads:
> 
> \* \[OpenHAB2 Parsing Strings\](https://community.openhab.org/t/openhab2-parsing-strings/46560?u=wborn)
> \* \[I gave up on OH 2.3 Unit of Measure (UM)\](https://community.openhab.org/t/i-gave-up-on-oh-2-3-unit-of-measure-um/52273?u=wborn)
> 
> \---
> 
> Eclipse SmartHome has a \[UoM Blog\](https://www.eclipse.org/smarthome/blog/2018/02/22/units-of-measurement.html) where this is explained in the "Scripts & Rules" section.
> 
> \---
> 
> In the openHAB documentation this should probably be explained in: 
> https://www.openhab.org/docs/configuration/rules-dsl.html#number-item
> 
> For discoverability a reference could be added to that section in: 
> https://www.openhab.org/docs/concepts/units-of-measurement.html

---

<div class="post-metadata">

**Author:** ![vzorglub](https://community.openhab.org/user_avatar/community.openhab.org/vzorglub/32/17166_2.png) [@vzorglub](https://community.openhab.org/u/vzorglub)\
**Post date:** [September 26, 2018, 6:15am UTC](https://community.openhab.org/t/i-gave-up-on-oh-2-3-unit-of-measure-um/52273/16 "2018-09-26T06:15:55Z")

</div>

Just came accross this yesterday. Using `*state as Number` used to be enough even with UoM  
But since a recent snapshot, the `*.state as QuantityType<Number>).doubleValue` as become mandatory.  
Any change to revert back to what it was. Much easier for everyone, especially newbies.

---

<div class="post-metadata">

**Author:** ![chzimm](https://community.openhab.org/user_avatar/community.openhab.org/chzimm/32/37331_2.png) [@chzimm](https://community.openhab.org/u/chzimm)\
**Post date:** [January 3, 2019, 5:42pm UTC](https://community.openhab.org/t/i-gave-up-on-oh-2-3-unit-of-measure-um/52273/17 "2019-01-03T17:42:15Z")

</div>

Hi!  
I’m stuck with the UoM’s. I have a rule that reacts when a thermostat is changed from a certain temperature.  
Since the UoM’s is no longer “4.5” but “4.5 ° C”.  
Here is my (old) rule:

```
 when Item OG_BUERO_ST changed from 4.5

```

How do I catch that?

– Christoph

---

<div class="post-metadata">

**Author:** ![Catskinner](https://community.openhab.org/letter_avatar_proxy/v4/letter/c/a183cd/32.png) [@Catskinner](https://community.openhab.org/u/Catskinner)\
**Post date:** [January 3, 2019, 5:52pm UTC](https://community.openhab.org/t/i-gave-up-on-oh-2-3-unit-of-measure-um/52273/18 "2019-01-03T17:52:31Z")

</div>

My solution was to strip and delete all the UoM from the items definition which brought back the simple report of numerical values only. I found UoM to be a pain in the butt to deal with and completely unnecessary for my purposes.

---

<div class="post-metadata">

**Author:** ![chzimm](https://community.openhab.org/user_avatar/community.openhab.org/chzimm/32/37331_2.png) [@chzimm](https://community.openhab.org/u/chzimm)\
**Post date:** [January 3, 2019, 5:57pm UTC](https://community.openhab.org/t/i-gave-up-on-oh-2-3-unit-of-measure-um/52273/19 "2019-01-03T17:57:07Z")

</div>

This can be a workaround but not what I want. I’m sure the developers have thought of something and also a solution for it. Unfortunately, the documentation is not (yet) the best. Generally I would like to use the UoM’s.

– Christoph

---

<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:** [January 3, 2019, 6:03pm UTC](https://community.openhab.org/t/i-gave-up-on-oh-2-3-unit-of-measure-um/52273/20 "2019-01-03T18:03:22Z")

</div>

> [@chzimm](#):
>
> when Item OG\_BUERO\_ST changed from 4.5

Have you tried  
` Item OG_BUERO_ST changed from 4.5|°C`  
or  
` Item OG_BUERO_ST changed from 4.5|"°C"`

[Next page](https://community.openhab.org/t/i-gave-up-on-oh-2-3-unit-of-measure-um/52273.md?page=2)
