Rule with a state value [%0.f W] and reading the number eg > 10

Running in to some problems with a rule.

I have a scripts that turns on a fan if the drawn power is higher than the standby power.
This item I formatted: Number:Energy Xbox_Watt “Xbox Watt [%.0f W]”
Thus, the reading is eg “10 W”

My rule is:
if ((Xbox_Watt.state > 30) || (Denon_Watt.state > 10))

But, this doesnt work because it reads 10 W

How to fix this?

Your rule is comparing a State with an integer, which will not work. You need to compare QuantityType to QuanityType or integer to integer. Use something like…

if (Xbox_Watt.getStateAs(QuantityType) > 30|W || Denon_Watt.getStateAs(QuantityType) > 10|W) {

Many people in this forum, like me, will find your username offensive. If you are wondering why your posts are not being replied to, you may want to consider this. Since you are using a new account, you may want to change your username or create a new account.

Thanks!
This solution works.

about the forum name, this is the name I used since my 13th or so, Use it in all games, forums and so on.
Changing the name to something different makes the link to the history and other forums/games go lost, and that is a shame, so that is why I keep using the name on all sites and forums and games.
Sorry if I offend you, not the intent of the name.

EDIT:
Why the |W after the number?
Do I need this as a |kWh if I use [%.3f kWh] and as a |% if it is with [%.%%]?

Fundamentals - openHAB can deal with Quantity Types, which are a number with units. Two parts to the value.
500 is just a number
500 cm is a meaningful measure of length.
0.5 m is exactly the same measure of length, just presented in a different way.

You can’t compare just-a-number with a length. Is 500 m less then 10?
Who knows, ten what? Miles, inches?
But you can (and the rule can) compare 500 m with 10 km

Don’t know quite what that %%% means, but let’s give examples

[%.3f kWh]
That’s you choosing how you want this value to be displayed.

Number:Energy yourItem ...
This is the part that makes it a Quantity
Number someItem ...
This is just a number Item

The | bar thing is only about how to write a Quantity in a rule. It’s just a magic character so that the rules interpreter knows when it sees 30 | W that you mean 30W, and not 30 with variable W

1 Like