String conversion to value for comparison

Tags: #<Tag:0x00007f6174c9f5b8>

Hi folks!

Working with openhab2 on a Raspberry.
What I want to do:
I would like to use the photovoltaics as light sensor. When the PV-power drops below 50W it is dark and the rollershutters should go down. Above 70W the rollershutters should go up.

I used the following rule for opening in the morning which basically worked, the rollershutters moved.

rule “Morgen_Rolladen_Hoch”
when
Item Wechselrichter_Dach_PVSTRING_1_POWER changed
then
logInfo(“rules”, “Rule when Morgen durchlaufen”)
logInfo(“rules”, Wechselrichter_Dach_PVSTRING_1_POWER.state.toString)
if (Wechselrichter_Dach_PVSTRING_1_POWER.state.toString > “70”) {
logInfo(“rules”, "Rule if morgen durchlaufen ")
Rolladen_ArbZi_Taster.sendCommand(UP)
}
end

The same rule using < “50” for the shutting in the evening.

Unfortunately the rollershutters moved all day.

  • 0-49: down
  • 70-99: up
  • 100-499: down
  • 700-999: up
  • 1000-4999: down
    I figured out that the .state looks like this: “1231.0349121094 W”. So the state is interpreted as a string not as a value. I think I have to convert the string to a value.
    I searched the community and the internet for a comparable issue and tried (without any success) different ways which could solve my problem:
  • Math.round(x)
  • x.intValue
  • var Number vergleich = ((Wechselrichter_Dach_PVSTRING_1_POWER.state) as DecimalType).floatValue

Here again what I get if I write Wechselrichter… to the log:
Wechselrichter_Dach_PVSTRING_1_POWER (Type=NumberItem, State=2020.8254394531 W, Label=PV_Strang1_Leistung, Category=energy)

Can anyone describe a working solution for such a problem? Do I have to use any imports?

Thx

The state is not a string, but a QuantityType - a number with units

@rossko57
Yes, now working. Thanks!!!
Such easy… I feel stupid.

Quantity Type is one of the clumsier parts of openHAB to work with in rules, it is not obvious how to deal with it.