OwnTracks timestamp to DateTime

I am getting my location from OwnTracks. The timestamp is send as a Unix Timestamp:

Number   Presence_RobertPhone_Timestamp "Timestamp [%d]"    <clock>    (Presence_RobertPhone) {mqtt="<[ext:owntracks/robert/iphone:state:JSONPATH($.tst)]"} 

This shows a decimal.

I could change this to a DateTime through a rule (link below), but would like to keep it simple.

Is there a way to combine the current JSONPATH transformation with, for example, a JS transformation in one line, something like JS(JSONPATH($.tst), epoch2datetime.js)

Probably. I don’t know the js code to convert epoch to a date time type but it should be possible. Though you still h a very to write the code so probably not saving anything using js verses rules.

Have you tried making the Item just be a Datetime instead of Number? OH may be smart enough to convert it for you.

I was thinking of something like this (haven’t tried yet):

My JS code/solution would be reusable across items (if I need to track multipe phones or other timestamps in the future). If I can create a oneliner, than the items file would be the only place to define something. With rules I would need to create a rule for each item. (Yes, I know, perhaps lambda’s would work). I like to have DRY code. :grin:

Tried that. Item returns NULL in the log if I do. :disappointed:


1 Like