I have this line in my configuration.yaml
template: !include_dir_merge_list template_sensors/
and this is the uptime.yaml file in my template_sensors folder:
- sensor:
- name: "System Uptime"
unique_id: last_boot_time
state: >
{% set up_time = as_timestamp(now()) - as_timestamp(states('sensor.last_boot')) %}
{% if up_time == 0 %}
Just restarted...
{% else %}
{% set minutes = (up_time // 60) | int %}
{% set hours = (minutes // 60) %}
{% set days = (hours // 24) %}
{% set weeks = (days // 7) %}
{% set minutes = (minutes % 60) %}
{% set hours = (hours % 24) %}
{% set days = (days % 7) %}
{% macro phrase(value, name) %}
{%- set value = value %}
{%- set end = 's' if value > 1 else '' %}
{{- '{} {}{}'.format(value, name, end) if value | int > 0 else '' }}
{%- endmacro %}
{% set text = [ phrase(weeks, 'week'), phrase(days, 'day'), phrase(hours, 'hr'), phrase(minutes, 'min') ] | select('!=','') | list | join(', ') %}
{% set last_comma = text.rfind(',') %}
{% if last_comma != -1 %}
{% set text = text[:last_comma] + ' and' + text[last_comma + 1:] %}
{% endif %}
{{ text }}
{% endif %}
attributes:
minutes: "{{ ((as_timestamp(now()) - as_timestamp(states('sensor.last_boot'))) |int)/60 }}"
hours: "{{ ((as_timestamp(now()) - as_timestamp(states('sensor.last_boot'))) |int)/60/60 }}"
days: "{{ ((as_timestamp(now()) - as_timestamp(states('sensor.last_boot'))) |int)/60/60/24 }}"
weeks: "{{ ((as_timestamp(now()) - as_timestamp(states('sensor.last_boot'))) |int)/60/60/24/7 }}"
- name: "HA Uptime minutes"
unique_id: uptime_minutes
state: "{{ state_attr('sensor.home_assistant_uptime','minutes') }}"
unit_of_measurement: "minutes"
- name: "Home Assistant Uptime"
unique_id: home_assistant_uptime
state: >
{% set up_time = as_timestamp(now()) - as_timestamp(states('sensor.uptime')) %}
{% if up_time == 0 %}
Just restarted...
{% else %}
{% set minutes = (up_time // 60) | int %}
{% set hours = (minutes // 60) %}
{% set days = (hours // 24) %}
{% set weeks = (days // 7) %}
{% set minutes = (minutes % 60) %}
{% set hours = (hours % 24) %}
{% set days = (days % 7) %}
{% macro phrase(value, name) %}
{%- set value = value %}
{%- set end = 's' if value > 1 else '' %}
{{- '{} {}{}'.format(value, name, end) if value | int > 0 else '' }}
{%- endmacro %}
{% set text = [ phrase(weeks, 'week'), phrase(days, 'day'), phrase(hours, 'hr'), phrase(minutes, 'min') ] | select('!=','') | list | join(', ') %}
{% set last_comma = text.rfind(',') %}
{% if last_comma != -1 %}
{% set text = text[:last_comma] + ' and' + text[last_comma + 1:] %}
{% endif %}
{{ text }}
{% endif %}
attributes:
minutes: "{{ ((as_timestamp(now()) - as_timestamp(states('sensor.uptime'))) |int)/60 }}"
hours: "{{ ((as_timestamp(now()) - as_timestamp(states('sensor.uptime'))) |int)/60/60 }}"
days: "{{ ((as_timestamp(now()) - as_timestamp(states('sensor.uptime'))) |int)/60/60/24 }}"
weeks: "{{ ((as_timestamp(now()) - as_timestamp(states('sensor.uptime'))) |int)/60/60/24/7 }}"
The problem I’m having is that while sensor.uptime_minutes shows up in HA, the other two do not. There doesn’t seem to be anything wrong with the templates according to the dev tools template tab, and I’m not sure where to look in the logs to find anything.
Can anyone see the problem?