Convert Int32 to String

Hi, has anyone a solution for convert a Int32 value to a String value.

I received a timestamp from a device as Int32 Value.
I would like to convert this value to a real Date / Time display, but the as_datetime function will only accept String parameter.

During my search I can’t found a solution.

May somebody, has another solution.

Thanks.

Please provide an example.
States are always strings, it doesn’t matter what it is received as, it is stored as a string.

We need to see more information to understand what is going wrong when passing it to the as_datetime function.

Thanks for quick response:

I receive an integer from a modus device.

configuration.yaml

modbus:

sensors:

timestamp – Anzeige korrigieren

- name: device_timestamp
  slave: 1
  address: 1052
  data_type: uint32
  swap: word
  precision: 0
  scale: 1

the result as sample is 1705159412

however to get a real date / Time , I want to use as_datetime as a function in a costum template.

Why do you think that doesn’t work though?
That converts to Sat Jan 13 2024 15:23:32 GMT+0000 for me.
I don’t see why:

{{ (states('sensor.device_timestamp')|as_datetime).isoformat() }}

Isn’t doing the job?
Like I said - ALL states are stored internally in the database as strings, it doesn’t matter what the source type was.

The states(sensor) function ONLY returns a string.

(you need the isoformat bit if the sensor you are creating has a device class of timestamp)

Thanks, your solution ist working perfectly,
I’m new to Home Assistant, I spend a several hours to find this solution. However I can’t find the completely description for the as_datetime function.

It’s under this section: