Display the uptime of the router

I try to show the time of the router by taking information with the baseoid.

I use mib browser software and there time shows something else.

Image:

This is my code:

  - platform: snmp
    host: 192.168.1.1
    baseoid: 1.3.6.1.2.1.25.1.1.0
    name: 'OpenWrt Uptime 1'
    value_template: >-
      {% set time = (value | int) | int %}
      {% set minutes = ((time % 360000) / 6000) | int%}
      {% set hours = ((time % 8640000) / 360000) | int %}
      {% set days = (time / 8640000) | int %}
        {%- if time < 60 -%}
          Less then 1 min
          {%- else -%}
          {%- if days > 0 -%}
            {{ days }}d
          {%- endif -%}
          {%- if hours > 0 -%}
            {%- if days > 0 -%}
              {{ ' ' }}
            {%- endif -%}
            {{ hours }}hr
          {%- endif -%}
          {%- if minutes > 0 -%}
            {%- if days > 0 or hours > 0 -%}
              {{ ' ' }}
            {%- endif -%}
            {{ minutes }}min
          {%- endif -%}
        {%- endif -%} 

I found on the net :-(.

Can someone help me fix the code?

This is what I have you will have to change the baseoid:

- platform: snmp
  version: 2c
  scan_interval: 60
  accept_errors: true
  name: "Router Uptime"
  host: !secret router
  port: 161
  community: !secret snmp_read 
  baseoid: 1.3.6.1.2.1.1.3.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 -%}
      {%- endif -%}

Thanks for the answer, I get an error:

my code:

  - 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/

Oops sorry my bad I missed the last endif off when I copied it. I have edited the original post.

Thank you very much. work

I’m on 0.93.2 and it’s giving me errors

And I don’t have any new device trackers showing
Do I need any additional software like OP is using mib browser?

title: Config Warning
message: Your configuration contains extra keys that the platform does not support (but were silently accepted before 0.88). Please find and remove the following.This will become a breaking change.

- [version], [accept_errors], [name], [port], [value_template].  (See /config/configuration.yaml, line 372). 
Offending data: {"platform": "snmp", "version": "2c", "scan_interval": "<redacted>", "accept_errors": true, "name": "Router Uptime", "host": "<redacted>", "port": 161, "community": "<redacted>", "baseoid": "<redacted>", "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 -%}\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 == 1 -%}\n      1 hr\n    {%- else -%}\n      {{ hours }} hrs\n    {%- endif -%}\n  {%- endif -%}\n  {%- if minutes > 0 -%}\n    {%- if days > 0 or hours > 0 -%}\n      {{ ', ' }}\n    {%- endif -%}\n    {%- if minutes == 1 -%}\n      1 min\n    {%- else -%}\n      {{ minutes }} min\n    {%- endif -%}\n  {%- endif -%}\n{%- endif -%}"}```

I am not quite sure what you mean. This was about interrogating SNMP to get the router uptime nothing todo with device trackers.

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 ?

Correct is it working now?

Unfortunately not, it’s just blank

here’s my config

  - platform: snmp
    version: 2c
    scan_interval: 60
    accept_errors: true
    name: "Router Uptime"
    host: 192.168.1.1
    port: 161
    community: public 
    baseoid: 1.3.6.1.2.1.4.22.1.2
    value_template: >-

I have DDWRT so I swapped the basoid for the one in the Docs

I have enabled SNMP on the DDWRT but can’t find a way to find out its OID
Problem is I don’t know how to find out what SNMP version I have

Maybe I should just use the DDWRT component?

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.