Meter Rule

I have set up an OH2 system and I have a meter, that is of the item type number, and give a number with one decimal about every 10:th second. I have set up influx to store the meter value every minute.
Most of the time the system will be idle and the meter will give the same value over and over.
I want to create a rule that starts when the meter value starts to increase (i.e. the system is switched on). Then I want counter to be set to zero, and start measuring the meter (i.e. the additional consumption since the rule noticed that meter value started to increase. When the meter value stopps to increase then cycle is over (and system is back to idle), then I want the rule to wait for the next cyle, i.e. when the meter starts increasing again, the counter value shoud then be set to zero again…

Unfortunately I am not at all experienced in programming, does any one have any good suggestions of how I shall make my rule?

rule x
	when
		Item meterX received command
	then
// do something, receivedCommand stores the actual value
		Thread::sleep(100)//wait 100 millis (or more)
		if(meterX.state == receivedCommand) {meterX.postUpdate(0)}//not changed
	end

This will set the meter-value to 0, if there was no change after 100 millis, to wait for a new start,
or that, to hold the last value, but lose the first.

var long lastMillis = now.millis

rule x
	when
		Item meterX received command
	then
		if(lastMillis+500 < now.millis) {meterX.postUpdate(0)}//last received command older than x millis
		else {
// do something, receivedCommand or meterX.state stores the actual value
		}
// or do here
		lastMillis = now.millis
	end

You have to approach the correct millis.

Thanks!

I am not sure if I explaind what I wanted properly. Below is an example of the input to MeterX. The counter is what I want the rule to calculate. MeterX will be measured every 10:th second.

MeterX: 17.1; 17.1; 17.1; 18.2; 18.8; 19.1; 19.1; 19.1; 19.2
Counter: 00.0; 00.0; 00.0; 01.1; 01.7; 02.0; 02.0; 02.0; 00.1

Can your code be used for this?

I realized that I want one more functionality - if MeterX do not go “idle” (19.1; 19.1; 19.1 etc) within 15 minutes I would like to:
sendBroadcastNotification(“Check the equipment, suspected malfuntion”)