Skip to content

Instantly share code, notes, and snippets.

@blakadder
Created January 13, 2019 13:42
Show Gist options
  • Save blakadder/7263d4504a2404c08035ce9f8566e829 to your computer and use it in GitHub Desktop.
Save blakadder/7263d4504a2404c08035ce9f8566e829 to your computer and use it in GitHub Desktop.
value_template: >
{% set time = states('sensor.nasbox_uptime')|int %}
{% 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 -%}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment