This sensor works well, but when displaying in Lovelace I get the Linux/Epoch time:
1558025641214
What value template should I use? In the dev template tester the following returns 1558025641214:
{{states.sensor.ping.state | timestamp_local}}
I presume because the state isn’t of the right type. However using as_timestamp() returns None.
Once I get it working in the dev tool, how should I apply it in config? Things I have tried are:
{{state | timestamp_local}}
or even
{{timestamp_local}}
?
A follow up question: presumably using a value template changes the sensor read out for anything downstream. Is it possible to keep the Linux time for the sensor value and only format it for the Lovelace card?
What are you using in Node-Red to generate this timestamp (expressed in micromilliseconds, not seconds)?
FWIW, Javascript (JS) expresses timestamps in micromilliseconds whereas Unix timestamps are in seconds. If you’re using Date.now() to generate the JS timestamp, divide it by a 1000 before publishing it for use by Home Assistant. This will spare you having to convert it for each and every sensor that receives a JS timestamp. On the other hand, if you only plan to have one sensor receiving the value, I guess it makes no difference who performs the conversion (Home Assistant or Node-Red) and Petro’s suggestion will definitely do the trick.
Do you all mean milliseconds? Either way the solution works, so thanks all.
@123 I used the simple Inject with default settings. I also agree with your assessments - Node-RED has a Moment node that does an equivalent “right thing” too. I just wanted to know for completion, partly because there will be sensors that I won’t have control over.
I still have the open (but related) question about raw data. Is there any way to recover the raw data for downstream requirements? The only solution I can think of is to create two sensors.
Milli, yes! My mistake. I’ve updated my original post.
My knowledge of Lovelace’s capabilities is insufficient to answer your question (sensor state is a timestamp but displayed in Lovelace UI as date/time).