Problem converting a value

I am trying to take a number and get the formatting correct. I get this as an example:

11495:09:33:20 - The original pre-converted value would be in hundredths of a second.

- platform: snmp
    scan_interval: 90
    name: ups_uptime
    host: 192.168.10.14
    baseoid: 1.3.6.1.2.1.1.3.0 
    accept_errors: true
    value_template: >
      {% set total_seconds = value | int / 100 %}
      {% set days = total_seconds // (24 * 3600) %}
      {% set hours = (total_seconds % (24 * 3600)) // 3600 %}
      {% set minutes = (total_seconds % 3600) // 60 %}
      {% set seconds = total_seconds % 60 %}
      {{ days }} days, {{ hours }} hours, {{ minutes }} minutes, {{ seconds }} seconds
    unit_of_measurement: time

Not quite sure what is wrong with this and admittedly found it online and trying to make it work for what I would want.

Thanks

Try it like this. As a note time is not a unit of measure and your actual output is a string not a time. Also, need to split your value to get the first digits before doing your calcs.

I am assuming only the first set of digits is the time you want in 100ths sec.

- platform: snmp
    scan_interval: 90
    name: ups_uptime
    host: 192.168.10.14
    baseoid: 1.3.6.1.2.1.1.3.0 
    accept_errors: true
    value_template: >
        {% set total_seconds = value.split(":")[0] | int(0) %}
        {% set days = total_seconds // (24 * 3600) | int(0) %}
        {% set hours = (total_seconds % (24 * 3600)) // 3600 %}
        {% set minutes = (total_seconds % 3600) // 60 %}
        {% set seconds = total_seconds % 60 %}
        {{ days }} days, {{ hours }} hours, {{ minutes }} minutes, {{ seconds }} seconds

An example of what should be converted is this:

993574200 - this would be ever changing over time. The only way it would start over is if the UPS itself was restarted. I hope this helps. I will try your modified code and let you know I make out.

This is the raw data before conversion

2024-05-15T23:28:43+00:00

So how do you get from the example on your first post to this. And how do you see converting a datetime (in your above second post) to a time delta (what it looks like you are trying to output?

And what exactly is your issue?

I read in the value from an oid using Paessler SNMP Tester. That value is expressed as a ASN_TIMETICKS.

Not sure if this helps but here is the HA error using modified code

Logger: homeassistant.components.sensor
Source: helpers/entity_platform.py:580
integration: Sensor (documentation, issues)
First occurred: 8:34:22 PM (1 occurrences)
Last logged: 8:34:22 PM

Error adding entity sensor.ups_uptime for domain sensor with platform snmp
Traceback (most recent call last):
File “/usr/src/homeassistant/homeassistant/components/sensor/init.py”, line 663, in state
numerical_value = float(value) # type:ignore[arg-type]
^^^^^^^^^^^^
ValueError: could not convert string to float: ‘11500 days, 5 hours, 3 minutes, 20 seconds’

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File “/usr/src/homeassistant/homeassistant/helpers/entity_platform.py”, line 580, in _async_add_entities
await coro
File “/usr/src/homeassistant/homeassistant/helpers/entity_platform.py”, line 892, in _async_add_entity
await entity.add_to_platform_finish()
File “/usr/src/homeassistant/homeassistant/helpers/entity.py”, line 1358, in add_to_platform_finish
await self.async_added_to_hass()
File “/usr/src/homeassistant/homeassistant/components/snmp/sensor.py”, line 214, in async_added_to_hass
await self.async_update()
File “/usr/src/homeassistant/homeassistant/components/snmp/sensor.py”, line 230, in async_update
self._process_manual_data(raw_value)
File “/usr/src/homeassistant/homeassistant/helpers/trigger_template_entity.py”, line 239, in _process_manual_data
self.async_write_ha_state()
File “/usr/src/homeassistant/homeassistant/helpers/entity.py”, line 1009, in async_write_ha_state
self._async_write_ha_state()
File “/usr/src/homeassistant/homeassistant/helpers/entity.py”, line 1132, in _async_write_ha_state
state, attr, capabilities, shadowed_attr = self.__async_calculate_state()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/usr/src/homeassistant/homeassistant/helpers/entity.py”, line 1067, in __async_calculate_state
state = self._stringify_state(available)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/usr/src/homeassistant/homeassistant/helpers/entity.py”, line 1015, in _stringify_state
if (state := self.state) is None:
^^^^^^^^^^
File “/usr/src/homeassistant/homeassistant/components/sensor/init.py”, line 665, in state
raise ValueError(
ValueError: Sensor sensor.ups_uptime has device class ‘None’, state class ‘None’ unit ‘time’ and suggested precision ‘None’ thus indicating it has a numeric value; however, it has the non-numeric value: ‘11500 days, 5 hours, 3 minutes, 20 seconds’ (<class ‘str’>)

You still have unit of measure in your sensor def.

Ok, so based on your second example and not the first example, your def is correct except you need to remove the unit of measure line.

And if you just want a time delta value which will look like this…

Screenshot_20240516_020325_Home Assistant

You can just do

- platform: snmp
    scan_interval: 90
    name: ups_uptime
    host: 192.168.10.14
    baseoid: 1.3.6.1.2.1.1.3.0 
    accept_errors: true
    value_template: >
        {{ timedelta(value / 100 / 3600 / 24) }}

sorry got pulled away. this does look cleaner than what the web interface reports. I will play around with this. thank you for assistance.