I would have expected that to work on Rules DSL. What’s not clear here is how that line fails. There is no error in the log.
Right now you have a java.time.ZonedDateTime in changed_at_time. You started with a ZonedDateTime and manipulated it’s state but did change it’s type.
Running with this, here is how it would be done with a Duration.
val myDur = Duration.ofHours(hours).plusMinutes(minutes)
val charged_at_time = now.plus(myDur)
There could be times where working with a duration might be easier, I’m not sure this is one of them.
But overall, I think it would make sense to just calculate the minutes and forget the hours. I think the following would work:
val time_to_charge = TeslaM3_time_to_full_charge.state as Number // It's better to cast to Number than DecimalType
val minutes = Math:round(time_to_charge * 60)
TeslaM3_time_charged.postUpdate(now.plusMinutes(minutes).toString())
Using a Duration gives you some convenience functions that might prove useful.
val time_to_charge = TeslaM3_time_to_full_charge.state as Number
val dur = Duration.ofMinutes(time_to_charge * 60)
// dur.toString() will print the duration in ISO8601 format, e.g. 6 hours 45 minutes would be PT6h45m
// dur.toHours() gives you just the hours
// dur.toMinutesPart() gives you the minutes after subtracting the hours
TeslaM3_time_charged.postUpdate(now.plus(dur).toString())
Again, thank you for your detailed explanation… always appreciate your’s too rossko57
The Tesla API returns “time_charged_to_set_level” as decimal number. I am too lazy calculating the end time in my head, as it will change based on solar PV power levels.
Right, but you can convert that number to just minutes and save a step calculating the hours. That’s the point of my reductions. now.plusHours(5).plusMinutes(10) is the same as now.plusMinutes(310).