Hello,

i am using the bmw connected drive scipt to log the mileage of my bmw.

Now i would like to create a rule, which informs me to the actual status of my used and avaible kilometers.

Therefore i created the following variables and rule to get the informations in a telegram message.

My problem is, that i am not really familiar with formatting the values in the right way. it would be great, if you could help me to complete my rule.

Thanks in advance,

Alex

```
var G31_V_Beginn = 09.09.2019
var G31_V_Ende = 08.09.2022
var G31_KM_Start = 12345
var G31_KM_Ziel = 72345
var G31_KM_pa = 20000
// Berechnung zu KM-Verbrauch
rule "Berechnung verfügbare Kilometer"
when
Time Time cron "0 0 0 1/1 * ? *" or
Item Bmw_ForceUpdate changed to ON
then
// Verbleibende Tage Vertragslaufzeit
// = Vertragsende - heute
Bmw__G31_Rest_Tage.sendCommand(G31_V_Ende - today)
createTimer(now.plusSeconds(3)) [ sendTelegram("bot1","Noch verbleibende Zeit bis zum Vertragsende: "+Bmw__G31_Rest_Tage.state+" Tage")]
// Verbleibende KM Vertragslaufzeit gesamt
// = "Ziel_KM" - "Start_KM" - "aktuelle KM"
Bmw_G31_Summe_Rest_KM.sendCommand(G31_KM_Ziel - G31_KM_Start - Bmw_mileage)
createTimer(now.plusSeconds(3)) [ sendTelegram("bot1","Noch verbleibende Kilometer bis zum Vertragsende: "+Bmw_G31_Summe_Rest_KM.state+" km")]
// Verbleibende KM täglicher Durchschnitt
// = "Bmw_G31_Summe_Rest_KM" / "Bmw__G31_Rest_Tage"
Bmw_G31_Taegl_Rest_KM.sendCommand( ((G31_KM_pa * 3) - Bmw_mileage) / Bmw__G31_Rest_Tage )
createTimer(now.plusSeconds(3)) [ sendTelegram("bot1","Noch verbleibende Kilometer - tägl. Durchschnitt: "+Bmw_G31_Taegl_Rest_KM.state+" km")]
// Abweichung aktueller KM-Verbrauch zu urspr. Plan
// = ( ("Vertrags_KM" / "Vertagslaufzeit") * "Tage seit Laufzeitbeginn" ) - "aktuelle KM"
Bmw_G31_Diff_Verbr_KM.sendCommand( (((G31_KM_pa * 3) / (G31_V_Ende - G31_V_Start )) * (heute - G31_V_Start)) - Bmw_mileage )
createTimer(now.plusSeconds(3)) [ sendTelegram("bot1","Abweichung zum geplanten KM-Verbrauch: "+Bmw_G31_Diff_Verbr_KM.state+" km")]
end
```