if you’re using yaml, ensure the entity has device_class: timestamp
If you’re using the UI, just select timestamp for the ‘show as’. Don’t add a unit of measurement or state class.
In the UI, it should show a relative time. It will still update every second, but the result should always be the same if your clock is in sync with the sensor.
Then exclude sensor.rt_ac57u_v3_6548_uptime from history.
Lastly, if you can control the state of sensor.rt_ac57u_v3_6548_uptime, I recommend altering it to output a time in seconds when it started. It will be a static number and then you can just let HA do the calculation for you if you set the device_class to timestamp. No template needed.
You can convert your existing Template Sensor to a Trigger-based Template Sensor and use a Time Pattern Trigger set to whatever time interval you prefer. The following example will update every 5 minutes.
template:
- trigger:
- platform: time_pattern
minutes: '/5'
sensor:
- name: Router Uptime
unique_id: abc123xyz456
state: >
{% set uptime = states('sensor.rt_ac57u_v3_6548_uptime') | int(0) %}
{% set years = uptime // 31536000 %}
{% set months = (uptime % 31536000) // 2592000 %}
{% set days = (uptime % 2592000) // 86400 %}
{% set hours = (uptime % 86400) // 3600 %}
{% set minutes = (uptime % 3600) // 60 %}
{{ '%dy ' % years if years else '' }}{{ '%dm ' % months if months else '' }}{{ '%dd ' % days if days else '' }}{{ '%dh ' % hours if hours else '' }}{{ '%dm' % minutes if minutes else '' }}
NOTE
Currently, a Trigger-based Template Sensors can only be defined via YAML. So if your existing Template Sensor was defined via the UI (as a Template Sensor helper) you’ll need to delete it and create the Trigger-based version shown in the example above.
Pretty sure his issue is that sensor.rt_ac57u_v3_6548_uptime is updating once a second and flooding his logs. sensor.rt_ac57u_v3_6548_uptime is the source sensor, so it just needs to be excluded from logbook