Are you sure that value is a simple, numeric data type?
The example from the docs implies that it may not be. You may want to set the value template to just return value without any modifications so you can see the type of value normally returned, then update the template accordingly.
My goal is to have an SNMP sensor that works and looks like the uptime sensor from the system monitor integration. From my understanding I need to convert the ticks that are fetched via SNMP to seconds. ANd to get the last boot time I must substract it from the timestamp of now(). And for the device_class timestamp this has to be an object in ISO time format.
Do you have any other segestions?
EDIT: WHen I just ooutput the value, I get 44865222 which seams reasonable.
With your code home assistant complains: ValueError: Invalid datetime: sensor.serverraum_donna_uptime has timestamp device class but provides state 2024-03-20 19:09:13.040710+01:00:<class ‘str’> resulting in ‘‘str’ object has no attribute ‘tzinfo’’.
I tried several things to convert the date to iso format but everything results in an unavaliable sensor. I find this date and time stuff really confusing.