Simple calculation rule for item

Hi,

I’ve setup simple rule to change my current Voltage value returned from KNX from mV to V. So, it’s just dividing the Voltage value by 1000 and update new item with that new value.
However, I don’t see that this rule is fired at all. No log info etc.

Here is my rule:

    rule "Voltage calculation" //divide by 1000 for better visualization
    when   
   		 //Item Bus_Voltage received update
   		 Time cron "0 */5 * * * ?"
    then   
 			var Number Volt = Bus_Voltage.state as DecimalType   
    		var Number xx = Volt/1000
			postUpdate(Bus_Voltage_Visu, xx)
			logInfo("Rules", "Voltage value updated to: "+Bus_Voltage_Visu.state)
    end

and items:

Number Bus_Voltage				"Napięcie [%.1f V]"			<voltage>				(Power)			{knx="10/0/3"}
Number Bus_Voltage_Visu			"Napięcie [%.1f V]"			<voltage>				(Power)	

I see that original voltage value in mV is coming from KNX and gets updated correctly for Bus_Voltage item:
2017-03-08 14:18:57.619 [DEBUG] [.binding.knx.internal.bus.KNXBinding] - Wrote value ‘29941.760000000002’ to datapoint ‘command DP 10/0/3 Bus_Voltage, DPT main 0 id 9.001, low priority’

Appreciate your hint for that.

Regards,
Krzysztof.

You are using a Timecron which fires every 5 minutes, did you wait for the next 5 minute Intervall?

Yes. sure. I’ve made it timecron to make it simple for now as I thought ‘received update’ condition was not triggered somehow.

I tried your code (with changed items to fit my system) like this:

rule "Voltage calculation" //divide by 1000 for better visualization
    when   
       Item E10_1 received update or Time cron "0 */5 * * * ?"
    then   
      var Number Volt = E10_1.state as DecimalType   
        var Number xx = Volt/1000
      postUpdate(TestNumber, xx)
      logInfo("Rules", "Voltage value updated to: "+TestNumber.state)
    end

and I’m getting this log:

19:06:01.373 [INFO ] [eclipse.smarthome.model.script.Rules] - Voltage value updated to: 0.00129900

Maybe there is an error in an earlier rule in the same rules file that prevents this one being parsed correctly.

Exactly. This was it. I see it’s impossible to declare variables in other places in .rules file than on top of it.
I had the earlier rule with 2 variables defined like:

var Number counter = 0
var Number lastCheck = 0

I moved them to top of the file and see that problem is gone.

Thanks Rossko and Jurgen for helping out!