# Rule that depends on light value delivered by Hue Binding's light sensor

**URL:** <https://community.openhab.org/t/rule-that-depends-on-light-value-delivered-by-hue-bindings-light-sensor/150757>\
**Category:** Scripts & Rules\
**Tags:** hue\
**Created:** [October 28, 2023, 9:47pm UTC](https://community.openhab.org/t/rule-that-depends-on-light-value-delivered-by-hue-bindings-light-sensor/150757 "2023-10-28T21:47:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Torsten555](https://community.openhab.org/letter_avatar_proxy/v4/letter/t/f475e1/32.png) [@Torsten555](https://community.openhab.org/u/Torsten555)\
**Post date:** [October 28, 2023, 9:47pm UTC](https://community.openhab.org/t/rule-that-depends-on-light-value-delivered-by-hue-bindings-light-sensor/150757/1 "2023-10-28T21:47:49Z")

</div>

Hello,

I have a Philips hue motion and light sensor that I use via the hue binding in OpenHAB 4.0.

In OpenHAB 2, I could write a rule that depended on the light delivered by the sensor very simply, e.g. using a condition like  
`
I_OG_Deckensensor_Helligkeit.state < 2
`

`
However, in OpenHAB 4 this does not work anymore, cause the Item now contains a value that consists of the number and the appended “lx” for “lux”, e.g. “0 lx”. This somehow cannot be handled by me in an OpenHAB rule anymore because everything I try leads to exceptions, e.g.

    val int helligkeit = Integer::parseInt(I_OG_Fl_Deckensensor_Helligkeit.state)

results in

[ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule failed: For input string: “0 lx” in lights

There seems to be no way to extract the number from that number + string concatenation delivered by the sensor to perform comparisons on that. I also tried simple castings, usage of .toString and more, it just does not work. Any ideas how to proceed?
Thanks, Torsten`

---

<div class="post-metadata">

**Author:** ![Rivi](https://community.openhab.org/letter_avatar_proxy/v4/letter/r/ce7236/32.png) [@Rivi](https://community.openhab.org/u/Rivi)\
**Post date:** [October 28, 2023, 10:12pm UTC](https://community.openhab.org/t/rule-that-depends-on-light-value-delivered-by-hue-bindings-light-sensor/150757/2 "2023-10-28T22:12:11Z")

</div>

Oh, we’re just discussing something like that [over here](https://community.openhab.org/t/cpu-temp-notification-problems-with-values-comparision/150750).

---

<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:** [October 28, 2023, 11:27pm UTC](https://community.openhab.org/t/rule-that-depends-on-light-value-delivered-by-hue-bindings-light-sensor/150757/3 "2023-10-28T23:27:41Z")

</div>

It’s not that complex, it’s called units of measurement (UoM) or QuantityType, so the value is followed by the unit.  
There are two options to work with UoM, either strip the unit or add it.

```auto
val helligkeit = (I_OG_Fl_Deckensensor_Helligkeit.state as Number).intValue

```

will strip the unit.  
It’s better not to use primitives. `int` is a primitive, while `Integer` is an object, but you don’t need to set the type of the value at all.

The other option is this:

```auto
if(I_OG_Fl_Deckensensor_Helligkeit.state < 2 | lx)

```

Sometimes you’ll have to use quotes:

```auto
if(I_OG_Fl_Deckensensor_Helligkeit.state < 2 | "lx")

```

and to be honest, I prefer the first option 🙂 but both are valid.

---

<div class="post-metadata">

**Author:** ![Torsten555](https://community.openhab.org/letter_avatar_proxy/v4/letter/t/f475e1/32.png) [@Torsten555](https://community.openhab.org/u/Torsten555)\
**Post date:** [October 29, 2023, 1:28pm UTC](https://community.openhab.org/t/rule-that-depends-on-light-value-delivered-by-hue-bindings-light-sensor/150757/4 "2023-10-29T13:28:42Z")

</div>

Thanks a lot, worked for me!  
I still would call it quite complex, though! 🙂

---

<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:** [October 29, 2023, 2:26pm UTC](https://community.openhab.org/t/rule-that-depends-on-light-value-delivered-by-hue-bindings-light-sensor/150757/5 "2023-10-29T14:26:13Z")

</div>

> [@Torsten555](#):
>
> I still would call it quite complex, though!

Yes, but it’s not that it would need another thread to study 🙂

The whole point is to understand the difference between (for instance) `15` and `15 °C`.
