- platform: snmp
version: 2c
scan_interval: 60
accept_errors: true
name: "Router Uptime"
host: 192.168.1.1
port: 161
community: root
baseoid: 1.3.6.1.2.1.25.1.1.0
value_template: >-
{% set timetick = value | int %}
{% set minutes = ((timetick % 360000) / 6000) | int%}
{% set hours = ((timetick % 8640000) / 360000) | int %}
{% set days = (timetick / 8640000) | int %}
{%- if timetick < 6000 -%}
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 hr
{%- else -%}
{{ hours }} hrs
{%- endif -%}
{%- endif -%}
{%- if minutes > 0 -%}
{%- if days > 0 or hours > 0 -%}
{{ ', ' }}
{%- endif -%}
{%- if minutes == 1 -%}
1 min
{%- else -%}
{{ minutes }} min
{%- endif -%}
{%- endif -%}
Error:
Invalid config for [sensor.snmp]: invalid template (TemplateSyntaxError: Unexpected end of template. Jinja was looking for the following tags: 'endif'. The innermost block that needs to be closed is 'if'.) for dictionary value @ data['value_template']. Got "{% set timetick = value | int %} {% set minutes = ((timetick % 360000) / 6000) | int%} {% set hours = ((timetick % 8640000) / 360000) | int %} {% set days = (timetick / 8640000) | int %} {%- if timetick < 6000 -%}\n Less than a minute\n{%- else -%}\n {%- if days > 0 -%}\n {%- if days == 1 -%}\n 1 day\n {%- else -%}\n {{ days }} days\n {%- endif -%}\n {%- endif -%}\n {%- if hours > 0 -%}\n {%- if days > 0 -%}\n {{ ', ' }}\n {%- endif -%}\n {%- if hours == .... (See ?, line ?). Please check the docs at https://home-assistant.io/components/sensor.snmp/
Sorry I wanted to incorporate a component that will tell me the uptime of my router and I couldn’t see where you put you config so I looked it up in the docs and found this: https://www.home-assistant.io/components/snmp/ so I put it under device_tracker
Looking at it now, I think I should’ve put it under sensor ?
That document is for presence detection not uptime.
You should be able to find a program to look at the traps such as SNMP walk to get a list of the OIDS the one you want is a Timetick type OID and will probably be near the top of the list.