I’m struggling with converting Unix timestamp (e.g. “1422616466”) into DateTime.
UX Timestamp I receive from OwnTracks and following rule handles it:
I’ve added following code to handle timestamp information:
var String tst = transform(“JSONPATH”, “$.tst”, json)
var DateTime time = new DateTime((tst as Long) * 1000L)
sendCommand(lastStatusUpdate, time)
The error message:
[ERROR] [o.o.c.s.ScriptExecutionThread ] - Error during the execution of rule ‘MqttPostionParse’: Cannot cast java.lang.String to java.lang.Long
great, that worked. There were some other errors in the code, so pasting working solution for completeness:
import org.joda.time.*
...
var String tst = transform("JSONPATH", "$.tst", json)
var DateTime time = new DateTime(Long::parseLong(tst) * 1000L)
lastStatusUpdate.postUpdate(new DateTimeType(time.toString))
Do you have a solution for that , I have the sane problem, but I do not parse at the moment from JSON and date epoch is coming to ITEM, I would like to create similar rool for that, convert from epoch to date time OpenHab java rule code convention.