I think especially the is a problem with the date formats and calculations.
I added the timer to make sure, the at first the values for the items are calculated and sent after that. (Hope it was the right way with the timer?)
For excample i get these warnings/errors in VSCode and the log after deploying the rule:
21:46:05.225 [WARN ] [del.core.internal.ModelRepositoryImpl] - Configuration model 'bmw.rules' has errors, therefore ignoring it: [1,26]: no viable alternative at input '2019'
[2,24]: no viable alternative at input '2022'
[11,5]: no viable alternative at input 'Time'
Oh, I see. Because it takes ti,me for sendCommand to work. But … you know what you just sent as a command, why not use iit directly?
var x = some calculation
myItem.sendCommand(x)
sendTelegram(x)
Okay, I think we are not so much about format here yet, but basic Rules syntax.
var G31_V_Beginn = 09.09.2019
That’s not valid syntax. The rules parser does not know what sort of variable you want, you have not told it, so it has to guess. 09 … ah it is a Number … 09.09 … ahh a decimal Number … 09.09.2019 … oh, its not a valid number at all. Error.
I’ve little idea what you are trying to do.
It looks like comparing some kind of Item state with a fixed date/time. What kind of Item, is it a DateTime type?
The only item i rule in these rules is the item of the actual mileage of my car, this is a number item.
The idea is, to calculate how many of the appointed kilometers are already “used” and how many are left and if i am in plan with the “consumption” of the kilometers.
So i would like to set fix values for:
beginning of the contract
end of the contract
appointed km / year
km at the beginning of the contract
appointed km at the end of the contract
With these fixed values i would like to calculate the consumption in comparision with the actual date (today) and the actual mileage (number item)
My thought was, that i simply can define the static values to variables, so that i can use them in the calculation.
If i am unterstanding right, your second link describes, how to write a time into and string item.
I think this i would have to do with the “today” value to use is in the rules?
But how to set up the varialbes?
Do i just have to change “09.09.2019” to " “2019-09-09’T’00:00:00.SSSZ” ?
This thread shows you how to create a dateTime object from a string
As per that thread, the easiest way to handle all this is, is to use time in milliseconds.
Get your contract-start date as a datetime, convert to epoch.
Get your contract-end date as a datetime, convert to epoch.
Get now, convert to epoch.
Now do whatever maths you like.
now - start = time so far
end - now = time to go
end - start = contract duration
(time so far / contract duration) * total km allowed = allowed to date