Item
DateTime EvCarReady “När ska bilen vara laddad”
rule "EV ready"
when
Time cron "0 0 6 ? * * *"
then
EvCarReady.postUpdate(now.plusdays(1))
end
Error code from blockly rule execution
06:45:12.529 [WARN ] [ernal.defaultscope.ScriptBusEventImpl] - State ‘2022-09-03T06:45:12.516582+02:00[Europe/Stockholm]’ cannot be parsed for item ‘EvCarReady’.
Hi again I found out that this could work, but how do I do if I want to set nextdatee as tomorrow at 06:00 when a rule fires at for instance 14:00, in joda there was a function startoftoday or similar. But is there an equalent method for zonedatetime?
rule "EV ready"
when
Time cron "0 0 6 ? * * *"
then
EvCarReady.postUpdate (new DateTimeType(now.plusDays(1)))
Worked as a charm, I would never figured that one out myself, I will use that one but triggerd by another event now when I can have it set to 06:00 whenever the rule fires… I beleive that time is really difficult to handle. I have another project where I try to use a DateTime item in a ECMA 11 script but get stuck on errors. But this piece is one piece in the puzzle.
Note, look up the method names on ZonedDateTime, I’m going from memory here and it might be slightly different (e.g. withMinuteOfHour, withMinute, etc).
I did find some text about it but it’s a little like a needle in a haystack, it seems like I foud the correct syntax for this, but that somethoings is missing when trying to update DateTime item. I thought .toString would have worked out.
The easiest way to post a ZonedDateTime to a DateTime Item right now is to convert it to a LocalDateTime first which will strip off the troublesome time zone.
I’m in the mood of developing this a litte more just for making an item that sets the hour the car should be finished charging, but is it possible to make withHour(6) to be witHour(ev_target_clock.state)?
I’ve tried some different approaches without any luck, I’ve tried ev_target_clock.state as Number and tried to set Item state to a like this
val hour = (ev_target_clock.state as Number)
but it all endsup in error
Script execution of rule with UID 'ev-4' failed: An error occurred during the script execution: Could not invoke method: java.time.ZonedDateTime.withHour(int) on instance: 2022-11-07T09:52:06.815497+01:00[Europe/Stockholm] in ev
withHour() (and all the other with…() methods mentioned here) need an Integer as parameter, so please try
EvCarReady.postUpdate(now.plusDays(1).withHour((ev_target_clock.state as Number).intValue).withMinute(0).withSecond(0).withNano(0).toLocalDateTime.toString())
As usually all helpfull people helpsout, I’m just bad att transforming number having a hard time to get all kind Big Decimal, float, double and how to cats them in different ways.