Advertisement
JLindvig

Bibliotek_card

Mar 2nd, 2023 (edited)
1,217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 1.27 KB | None | 0 0
  1. type: markdown
  2. title: Bibliotekslån
  3. content: >-
  4.   {# CHANGE BELOW #}
  5.   {% set headers = ['', 'Titel', 'Type', 'Afleveres'] %}
  6.   {% set trim = 32 %}
  7.   {% set userStr = '### USER (X lån)' %}
  8.   {% set dateStr = 'om X DAYS (DATE)' %}
  9.   {% set dateFormat = '%-d/%-m' %}
  10.  
  11.   {# PRIVATE #}
  12.   {% set ts_now = now() | as_timestamp %}
  13.   {% set libraryUsers = states.sensor | selectattr('attributes.loans', 'defined') | selectattr('attributes.loans_overdue', 'undefined') | list %}
  14.  
  15.   {# CARD BEGIN #}
  16.   ---
  17.   {%- for libObj in libraryUsers -%}
  18.   {%- set libAttr = libObj.attributes %}
  19.   {%- set amount = libAttr.loans | length %}
  20.   {%- if amount > 0 %}
  21.  
  22.   {{ userStr.replace('USER', libAttr.user).replace('X', amount~'') }}
  23.  
  24.   |{{ headers | join(' | ') }}|
  25.   |--:|:--|:--|--:|
  26.  {%- for loan in libAttr.loans %}
  27.   {%- set days = (loan.expire_date | as_timestamp - ts_now) | timestamp_custom('%-d' ) | int(0) %}
  28.   {%- set returnStr = dateStr.replace('X', days~'' ).replace('DAYS', 'dag'~('e' if days > 1 else '')).replace('DATE', loan.expire_date | as_timestamp | timestamp_custom(dateFormat)) %}
  29.  
  30.   |{{ loop.index }}|{{ loan.title | truncate(trim, true) }}|{% if loan.type != '' %}({{ loan.type }}){% endif %}|{{ returnStr }}|
  31.   {%- endfor %}
  32.   {% endif  %}
  33.   ---
  34.   {% endfor %}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement