[Solved] String item to number item

I have a string (AQ_RX_c1) item with state e.g.
266mV or 8.16pH

String  AQ_RX_c1	"AQRXStringc1 [%s]" 
Number  AQ_RX_c2	"AQRXNumberc2 [%s]"

The rule I use is triggered by a switch
I can sucessfully remove to mV or pH but it remains a string.

I want to use the string as number in a different item ( AQ_RX_c2) for further calculation.

How can I achieve that in a rule?

thank you for your support!

How does the AQ_RX_c1 get populated? If it uses a binding that can use transformations you can remove the mV or pH before it gets to the Item in the first place and only require the Number Item.

I think this is a case where you will get a better solution if you provide more context (full Item config, relevant rules, and a better explanation of what you are trying to achieve). I can just tell you how to do what you ask but I’m almost certain there are better ways that do not even require the second Item or Rules to do it.

Hi Rich,
thank you for your reply.

Of course I can provide more details.

Item uses JSONPATH to read from a websourcein my LAN (attached as a txt file)

String  AQ_RX	"AQRX [%s]"   ( AQ ) { http="<[$.components.sensors[003].actual)]" }

Then it is beeing trimmed in a rule

		Item   Switch_dummy changed
		var String redoxstr = AQ_RX.state.toString().replace("mV", "") // Cut off unit
            AQ_RX_c1.postUpdate(redoxstr) // Send String C1 Variable to item

Now it is trimmed but I need a number for additional calculations based on the number

kind regards


OK, in that case since you are already using a transformation you will not be able to easily do this all in a transformation (unless you are good with JavaScript).

So once you have extracted just the number just send it to the Number Item.


Assuming the string in redoxstr is a valid Number, the parsing of the String to a Number will be handled for you. If it isn’t a valid number you will need to do some additional manipulations to the String (e.g. trim to remove white space) to convert it into a valid number.

Thank you Rich,

but how do I trim the String to remove whitespaces? (currently 4 spaces are coming in front of the number)

Got it:

		AQ_RX_c2.postUpdate(redoxstr.trim()) // Send Number C2 Variable to item

now I have it available as number!

thanks for your support!

FYI, in case you don’t need/want the second item, you could always just convert the redoxstr variable for use in the rule with Double::parseDouble(redoxstr).