I was able to set up runtime as a sensor and a template sensor for parsing the seconds.
# added to type definitions section in \config\custom_components\ecowitt\const.py:
TYPE_RUNTIME = "runtime"
# added to SENSOR_TYPES = section in \config\custom_components\ecowitt\const.py
#
# Name, unit_of_measure, type, device_class, icon, metric=1, state_class
#
TYPE_RUNTIME: (
"Runtime",
None,
TYPE_SENSOR,
None,
"mdi:run-fast",
0,
None,
),
#
#
This will get you a sensor.runtime with a running seconds total from the device's start.
To see it parsed in weeks, days, hours, minutes, and seconds you can use a template sensor.
template:
- sensor:
- name: "Ecowitt Uptime Long"
state: >-
{%- set uptime = states.sensor.runtime.state | round -%}
{%- set sep = ', ' -%}
{%- set TIME_MAP = {
'week': (uptime / 604800) % 604800,
'day': (uptime / 86400) % 7,
'hour': (uptime / 3600) % 24,
'minute': (uptime / 60) % 60,
'second': (uptime % 60)
}
-%}
{%- for unit, duration in TIME_MAP.items() if duration >= 1 -%}
{%- if not loop.first -%}
{{ sep }}
{%- endif -%}
{{ (duration | string).split('.')[0] }} {{ unit }}
{%- if duration >= 2 -%}
s
{%- endif -%}
{%- endfor -%}
{%- if uptime < 1 -%}
just now
{%- endif -%}