can any one tell me what is the problem in this template. i have other sensor named router1uptime and that sensor is running perfectly. but it gives me only seconds and i want to convert that second to days, hours, minutes and seconds.
router1uptime tsensor:
platform: snmp
name: 'router1uptime'
host: 192.168.254.254
baseoid: .1.3.6.1.2.1.1.3.0
version: 2c
accept_errors: true
r1uptime template:
platform: template
sensors:
r1uptime:
value_template: >
{% set time = states.sensor.router1uptime.state %}
{% set minutes = ((time % 3600) / 60) | int %}
{% set hours = ((time % 86400) / 3600) | int %}
{% set days = (time / 86400) | int %}
{%- if time < 60 -%}
Less than a minute
{%- else -%}
{%- if days > 0 -%}
{%- if days == 1 -%}
1 day
{%- else -%}
{{ days }} days
{%- endif -%}
{%- endif -%}
{%- if hours > 0 -%}
{%- if days > 0 -%}
{{ ', ' }}
{%- endif -%}
{%- if hours == 1 -%}
1 hour
{%- else -%}
{{ hours }} hours
{%- endif -%}
{%- endif -%}
{%- if minutes > 0 -%}
{%- if days > 0 or hours > 0 -%}
{{ ', ' }}
{%- endif -%}
{%- if minutes == 1 -%}
1 minute
{%- else -%}
{{ minutes }} minutes
{%- endif -%}
{%- endif -%}
{%- endif -%}
and here is the error:
2017-09-06 07:45:02 ERROR (MainThread) [homeassistant.helpers.entity] Update for sensor.r1uptime fails
Traceback (most recent call last):
File "/usr/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 223, in async_update_ha_state
yield from self.async_update()
File "/usr/lib/python3.6/asyncio/coroutines.py", line 210, in coro
res = func(*args, **kw)
File "/usr/lib/python3.6/site-packages/homeassistant/components/sensor/template.py", line 145, in async_update
self._state = self._template.async_render()
File "/usr/lib/python3.6/site-packages/homeassistant/helpers/template.py", line 102, in async_render
return self._compiled.render(kwargs).strip()
File "/usr/lib/python3.6/site-packages/jinja2/asyncsupport.py", line 76, in render
return original_render(self, *args, **kwargs)
File "/usr/lib/python3.6/site-packages/jinja2/environment.py", line 1008, in render
return self.environment.handle_exception(exc_info, True)
File "/usr/lib/python3.6/site-packages/jinja2/environment.py", line 780, in handle_exception
reraise(exc_type, exc_value, tb)
File "/usr/lib/python3.6/site-packages/jinja2/_compat.py", line 37, in reraise
raise value.with_traceback(tb)
File "<template>", line 1, in top-level template code
TypeError: not all arguments converted during string formatting