Force Template Sensor to Not Output in Scientific Notation?

Is there a way to make sure that the output of a template sensor is not in scientific notation? I have the following sensor which simply displays the timestamp of the current day at midnight:

- platform: template
      value_template: >-
        {{ as_timestamp(states('')) * 1000000000 - (25200*1000000000) | float}}

But the output is 1.6272576e+18, where I want it simply to output 1627257600000000000. Is this possible? If so, how? Thanks!

Use int instead of float, and use brackets to ensure you’re int-ing all of it:

{{ (as_timestamp(states('')) * 1000000000 - (25200*1000000000)) | int }}

Why are you going to nanoseconds, though?

Wow, didn’t think it would be as simple as that… Thanks!

I’m using nanoseconds for the timestamp because using the “write data” function in Home Assistant’s InfluxDB add-on’s Chronograf interface only accepts timestamps in nanoseconds for some reason. Seconds won’t work for me, and I plan on writing specific data to my database every day (manually), so having the timestamp ready to go makes it much easier.

Splitting hairs, but writing it like below seems clearer (and maybe more efficient) to me

{{ (as_timestamp(states(''))|int - 25200 ) * 1000000000 }}
1 Like