Dear community,
I would like to ask for your help. I have a WiFi device and I query its uptime via SNMP. I get the following:
snmpwalk -v1 -c public iso.3.6.1.2.1.1.3.0
iso.3.6.1.2.1.1.3.0 = Timeticks: (1812421400) 209 days, 18:30:14.00
I would like to display this on the home assistant interface. I wrote this in the configuration.yaml file:
- platform: snmp
name: "wifi_uptime"
version: "1"
host: <device ip>
community: public
baseoid: iso.3.6.1.2.1.1.3.0
accept_errors: true
state_class: measurement
scan_interval: 10
This returns this result: 1812421400
How can I remove the two 0’s from the end?
Then, how can I convert the map minute into an understandable date format?
Unfortunately, this doesn’t work for me:
- platform: template
sensors:
wifi_uptime_human_readable:
friendly_name: "Wifi Uptime"
unit_of_measurement: ""
value_template: >-
{% set uptime_seconds = (states('sensor.wifi_uptime') | int) // 100 %}
{% set years = uptime_seconds // (365 * 24 * 3600) %}
{% set months = (uptime_seconds % (365 * 24 * 3600)) // (30 * 24 * 3600) %}
{% set days = (uptime_seconds % (30 * 24 * 3600)) // (24 * 3600) %}
{% set hours = (uptime_seconds % (24 * 3600)) // 3600 %}
{% set minutes = (uptime_seconds % 3600) // 60 %}
{% set seconds = uptime_seconds % 60 %}
{{ years }} years, {{ months }} months, {{ days }} days, {{ hours }} hours, {{ minutes }} minutes, {{ seconds }} seconds
I get this as a result: unknown
I must be wrong as I am new to yaml. Where is the mistake, what am I doing wrong?