[SOLVED] Rule problem now.minusDays with variable

Hello again,
I have the following Problem with a rule. If These rules is executed, I get the following error:

Rule ‘Stromzähler Verbrauch aktuell’: An error occurred during the script execution: index=1, size=1

The rule:

rule "Stromzähler Verbrauch aktuell"
when
	Item test_switch changed
	//Time is midnight
then
	var int weekday = now.getDayOfWeek			//Montag = 1 ... Sonntag = 7
	//Verbrauch Tag aktuell
    postUpdate(Stromzaehler_Verbrauch_1T_aktuell, (Stromzaehler_Stand.deltaSince(now.withTimeAtStartOfDay(),"influxdb") as DecimalType))
	

	//Verbrauch Woche aktuell
	if (now.getDayOfWeek.intValue == 1) {
		postUpdate(Stromzaehler_Verbrauch_7T_aktuell, (Stromzaehler_Stand.deltaSince(now.withTimeAtStartOfDay(),"influxdb") as DecimalType))
		var Number temp4 = Stromzaehler_Verbrauch_7T_aktuell.state
		logInfo("rule", "Der Stromverbauch der aktuellen Woche wurde berechnet und beträgt: " +String.format("%.2f",(temp4).floatValue())+ " kWh")	
	}
	else {
		logInfo("rule", "Test")
		var int calc1 = weekday-1
		var Number calc11 = calc1 as Number
		logInfo("rule", "Test2")
		var Number calc2 = Stromzaehler_Stand.deltaSince(deltaSince(now.minusDays(calc11)),"influxdb")
		var Number calc3 = Stromzaehler_Stand.deltaSince(now.withTimeAtStartOfDay(),"influxdb")
		var Number calc4 = calc2 + calc3
		postUpdate(Stromzaehler_Verbrauch_7T_aktuell, calc4)
		logInfo("rule", "Der Stromverbauch der aktuellen Woche wurde berechnet und beträgt: " +String.format("%.2f",(calc4).floatValue())+ " kWh")	
	}

	
	logInfo("rule", "Stromverbraeuche wurden berechnet")	
end```


I think there is an error with the variable but I don't know what to do.

Any ideas?

Thanks for your help guys!

Do you get any logs from this Rule or just the error?

Are you certain that the calls to deltaSince are returning a value instead of null?

Oh sorry, log Test and Test2 are visible in the karaf log. I think this Expression is the problem:

var Number calc2 = Stromzaehler_Stand.deltaSince(deltaSince(now.minusDays(calc11)),"influxdb")

Thank you for your help.

The call to now.someMethod(number), the number must be an int
Therefore calc11 must be an int

    var int calc1 = weekday - 1
    var int calc11 = calc1

Or you could get rid of call11 altogether:

    var int calc1 = weekday - 1
    ...
    var Number calc2 = Stromzaehler_Stand.deltaSince(deltaSince(now.minusDays(calc1)),"influxdb") as Number
    ...

No, also the same error. I erase var calc11 (was only a test). But VSCode Shows me the following error:

Invalid number of arguments. The method deltaSince(Item, AbstractInstant) is not applicable for the arguments (DateTime)
Type mismatch: cannot convert from DecimalType to AbstractInstant

What is wrong?

    var Number calc2 = Stromzaehler_Stand.deltaSince(now.minusDays(calc1),"influxdb") as Number

What the ……
That was it! Perfect! Thank you very much. I have missed the forest for the trees:-)

Thank you!