The problem is that it always adds 1 more day.
For example if the time is 22h, 10m, on the dashboard I see 1d, 22h, 10m.
If the real time is 2d, 10h, 5m on the dashboard I see 3d, 10h, 5m.
It always adds 1 more day…how can I fix it?
A timestamp is not just a plain number of seconds, it’s a date/time expressed as the number of seconds since 01/01/1970 00:00.
“%d” is not a number of days, it’s the day of the month of the timestamp.
406356, as a timestamp, is the 5th of January 1970, 16:52
If days are not that important, you could also set the “duration” device class on the sensor, so that HA knows to display the number as a duration, e.g.
. I also tried other templates found on the forum, none work. I really don’t know how to do it.
Blockquote
Logger: homeassistant.util.logging
Source: util/logging.py:168
First occurred: 12:16:00 (1 occurrences)
Last logged: 12:16:00
Exception in message_received when handling msg on ‘router/1118876940/uptime’: ‘411876’ Traceback (most recent call last): File “/usr/src/homeassistant/homeassistant/components/mqtt/debug_info.py”, line 44, in wrapper msg_callback(msg) File “/usr/src/homeassistant/homeassistant/components/mqtt/sensor.py”, line 292, in message_received _update_state(msg) File “/usr/src/homeassistant/homeassistant/components/mqtt/sensor.py”, line 243, in _update_state payload = self._template(msg.payload, PayloadSentinel.DEFAULT) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File “/usr/src/homeassistant/homeassistant/components/mqtt/models.py”, line 251, in async_render_with_possible_json_value rendered_payload = self._value_template.async_render_with_possible_json_value( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File “/usr/src/homeassistant/homeassistant/helpers/template.py”, line 735, in async_render_with_possible_json_value return _render_with_context(self.template, compiled, **variables).strip() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File “/usr/src/homeassistant/homeassistant/helpers/template.py”, line 2179, in _render_with_context return template.render(**kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^ File “/usr/local/lib/python3.11/site-packages/jinja2/environment.py”, line 1301, in render self.environment.handle_exception() File “/usr/local/lib/python3.11/site-packages/jinja2/environment.py”, line 936, in handle_exception raise rewrite_traceback_stack(source=source) File “”, line 1, in top-level template code TypeError: unsupported operand type(s) for //: ‘str’ and ‘int’
Not going to able to help you with anything specific. But maybe point you in the right direction.
A lot of the time these offsets in time are due to timezone differences because there is a difference between your local timezone and the timezone that it thinks it should be.
It’s an uptime. Just output the raw value, then add unit_of_measurement: s and device_class: duration. The front end will convert the time into d hh:mm:ss