[SOLVED] Unknown variable or command '-' In Rule

Actually, I think the issue is in the numbers you are receiving from the device. There is nothing in your code that would cause a negative number. So the negative number has to be coming from the sensor. Look in events.log to see what it was updated to when the result of the calculation goes down.

Log out each part of the calculation as well and make sure they make sense. But this is a super simple formula. There is nothing there that would cause a negative number.

That’s rather my point, the timing is outside of openHABs control. This does not seem like a good plan for a time sensitive application - integrating the lux over time. Don’t use it as the “tick” to drive your clockwork, just use it as a sensor.

Well, I went back to the basics and did some more research and tried a few things and found this to be just as simple as can be. Well, at least this is working…
Item

Number DLI_Daily_Counter "DLI Daily Counter [%.2f]"

Rule

rule "Count of the DLI Total"

when 
	Item racksensor1_DLI received update
then
	DLI_Daily_Counter.postUpdate((DLI_Daily_Counter.state as Number) + (racksensor1_DLI.state as Number / 12))
		
end

and that’s all it took. Probably what you guys were trying to tell me but was just not registering. Some turkey and suddenly it made sense…

Thanks so much guys!

1 Like

So, presumably this should work then?
val Number DLI_Daily = 0

DLI_Daily = DLI_Daily + (racksensor1_DLI.state as Number / 12)

I am asking because I am struggling with a simlar issue, where I define a Number at top of the rule and run through loops incresing the value along the way.

Yes, that should work because DLI_Daily in that case gets initialized to 0 and you can do math with 0.

But - don’t forget val is for immutable value. You cannot ever change it. If you propose to change it later, make it a var

Sorry - of course - that’s what I have. :slight_smile:

That makes sense and would have been my guess.
However with my code below, it does not work with Food:

rule "analyze expenditure"
when
	Item Fin_Chk received command OFF
then
	logInfo("+++ FINANCE", "$$$ - Fin Check triggered.")

	var Number Food = new DecimalType()
	val results = executeCommandLine("cat /etc/openhab2/html/tmp/text.csv",5000)
	val array1 = results.toString.split("\n")

	for(var i=7; i<array1.length; i++) {
		var String client = ""
		var String money = ""
		var Number amount = new DecimalType()
		val myList = array1.get(i).toString.split(";")
		// extract client and transaction amount
		client = myList.get(3)
		money = myList.get(7)
				if(client.contains("xxx")) {
					Food = Food + DecimalType.valueOf(money) // 
					logInfo("+++ FINANCE", "Food costs updated to: " + Food + " EUR")
				}
			}
		}
	logInfo("+++ FINANCE", "Cost items have been updated")
end

I get:
Rule 'analyze expenditure': null

Disregard my rule above.
I just figured out that a the part with “money” caused the issue