Use exec output value in rule operation

I want to calculate how much volume of water there is in my rainwater tank.
For this I use a HC-sr04 ultrasonic sensor and this is controlled and read out by a python script that is running on my Raspberry pi. This python script is working with the EXEC binding output in openhab. 

Now I try to calculate the volume of water with a rule:

rule "watervolume "
exec_command31bc7a83_output.state as Number changed
logWarn(“Controle”, “De regel ‘berekenen volume’ is zonet uitgevoerd.”)
WaterVolume.postUpdate(LiterPerCm.state as Number * (Maximumdistance.state as Number - exec_command31bc7a83_output.state as Number))


the 2 variables; LiterPerCm and Maximumdistance are defined as number-item and adjustable on my habpanel.

I can read out my exec output in a habpanel dummy but when I use the exec output in my rule, it looks like the rule doesn’t understand the exec output because it’s a string and not a number-item.

Perhaps its a String. May we see your Item definition?

That part is nonsense, it changes or doesn’t change. Remove as Number.

Thanks for the response, yes I forgot to say it’s a string.

These are the items I use in this rule. Do I have to put the exec output string in my Item definition?

Number LiterPerCm “Aantal liter per cm [%d]”
Number Maximumdistance “Maximum afstand sensor [%d]”
Number WaterVolume “Volume water (berekend) [%d]”

Okay, if you want to do maths with it, you must first convert the string to number - it’s a process called parsing.

You can also use Float.valueOf() for a decimal

Sorry, wrong subject caught… :slight_smile: