I’ am slowly moving my OH1 setup to OH2. I have most basic things working, and have moved on to the “next level” of issues. Most I can fix/workaround, but one I am stumped with. I have a JS transform I use to convert MQTT timestamp strings to an OpenHab DateTime item.
This is received from various owntracks devices in the format:
owntracks/homeassistant/andrew {"t":"p","tst":1461590348,"acc":0,"_type":"location","alt":0,"lon":<redacted>,"p":101.3717041015625,"lat":<redacted>,"batt":100,"tid":"AC"}
owntracks/homeassistant/wendy {"tst":1461584027,"acc":65,"_type":"location","alt":24,"lon":<redacted>,"vac":17,"p":101.0577392578125,"lat":<redacted>,"batt":95,"tid":"WC"}
owntracks/homeassistant/andrewipad {"t":"p","tst":1461537070,"acc":0,"_type":"location","alt":0,"lon":<redacted>,"p":101.3188552856445,"lat":<redacted>,"batt":84,"tid":"AC"}
where “tst” is the timestamp in unix format.
This is the old (OH1) working version:
Item:
DateTime NickEventLastUpdate "Nick's Phone Last Event Update [%1$tm/%1$td/%1$tY %1$tH:%1$tM:%1$tS]" <clock> (gPeople) { mqtt="<[proliant:owntracks/Nick/iPhone/event:state:JS(mqttitude-timestamp.js)]" }
mqttitude-timestamp.js:
var location = eval('(' + input + ')');
var cal = new java.util.GregorianCalendar();
cal.setTimeInMillis(location.tst*1000);
var t = new org.openhab.core.library.types.DateTimeType(cal);
result = t;
This gives me an error in OH2 java.lang.ClassNotFoundException: org.openhab.core.library.types.DateTimeType
, OK I thought, the old reference is probably wrong, so I replaced it with:
var location = eval('(' + input + ')');
var cal = new java.util.GregorianCalendar();
cal.setTimeInMillis(location.tst*1000);
//var t = new org.openhab.core.library.types.DateTimeType(cal);
var t = new org.eclipse.smarthome.core.library.types.DateTimeType(cal);
result = t;
Which gives me a similar error java.lang.ClassNotFoundException: org.eclipse.smarthome.core.library.types.DateTimeType
.
There must be a reasonable way to convert a json unix timestamp string to a DateTime object, maybe javascript isn’t fully there yet, or I don’t understand the syntax.
Anyone know how to make this work in OH2?
Thanks,