I could not get that to work. My rule just fails silently when it gets to that line. I tried replacing the . with :: for the proper way to access static methods and values. This is probably one of those cases where I’m willing to give up some CPU efficiency to gain some easier to read and understand the code:
MyDateTimeItem.postUpdate(now.toString)
I’m sure with a little work I could figure out what the error is, but for now I wouldn’t recommend that approach for converting from Joda to DateTimeType when the toString works so well, at least in the case where we are posting the update or sending a command.
I also experienced the “deprecated-notification” today and wanted to code according to the new standards.
I however didn’t find how to convert the milliseconds back to a DateTimeType, as the wiki is also deprecated.
I want to post an update to a DateTime item.
How to do this?
My goal is to store the time when the wasing mashine starts and update another item when it finishes with the washing duration (starttime - now). Maybe you got a better idea of how to do this, if so, please let me know
rule "test time difference"
when
Time cron "*/10 * * * * ?"
then
val calendar = java.util.Calendar::getInstance
calendar.timeInMillis = now.millis - (Waschkueche_Waschmaschine_startZeit.state as DateTimeType).zonedDateTime.toInstant.toEpochMilli
Waschkueche_Waschmaschine_letzteZykluszeit.postUpdate(new DateTimeType(calendar))
end
This works but I want to solve it according to the new standard.
Thanks for your help
Maybe it is unusual to store time differences in a DateTime item.
I should maybe better use a Number item.
Can anyone show me how to format the Number item from milliseconds to hours and minutes in the sitemap?
I’m also having trouble with the deprecation of DateTime in the latest build using JSR223,
Can you give me a hint what the new coding standards would be?
Wouldn’t it be a good idea to update the documentation’s sample code? The sample code on the Rules page of the documentation is itself now deprecated… hardly a good start for those trying to fight their way through the absurd DateTimeType vs Joda DateTime wrangle for the first time.
Hello, I think I’m having some problems about the DataTimeType and I have to say that the manipulation of DataTimeType items it’s something new for me. I opened a new discussion because I didn’t want to go too off-topic in this one but this is certainly related.
My problem about extracting data from a DataTimeType item is described here
if anybody could help me about that it would be very appreciated!
Bye.
(Sorted_Date.state as DateTimeType).getZonedDateTime.toInstant.toEpochMilli
Please don’t user Designer any more. It is about two years out of data at this point and never worked correctly for OH 2. Please use VSCode with the openHAB extension.
Personally, I find it easier to convert DateTimeTypes to Joda DateTimes and work with that:
val jdt = new DateTime(Sorted_Date.state.toString)
I used “new” designer, suggested in migration tutorial:
### Eclipse SmartHome Designer As mentioned above, there is a new Integrated Development Environment (IDE) for openHAB 2 configurations, Eclipse SmartHome Designer. The old openHAB Designer is not compatible with openHAB 2.