Advertisement
JLindvig

Next Birthday

Feb 2nd, 2020
330
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 0.85 KB | None | 0 0
  1. - platform: template
  2.   sensors:
  3.     next_birthday:
  4.       friendly_name_template: >-
  5.         {% set ns = namespace(entity_id="", prev=1000) %}
  6.         {% for birthday in states.group.birthdays.attributes.entity_id -%}
  7.           {% if states(birthday) | int < ns.prev %}
  8.             {%- set ns.entity_id = birthday -%}
  9.             {%- set ns.prev = states(birthday) | int -%}
  10.           {% endif -%}
  11.         {% endfor %}
  12.         {{ state_attr(ns.entity_id, "friendly_name") }}
  13.       value_template: >-
  14.         {% set ns = namespace(entity_id="", prev=1000) %}
  15.         {% for birthday in states.group.birthdays.attributes.entity_id -%}
  16.           {% if states(birthday) | int < ns.prev %}
  17.             {%- set ns.entity_id = birthday -%}
  18.             {%- set ns.prev = states(birthday) | int -%}
  19.           {% endif -%}
  20.         {% endfor %}
  21.         {{ ns.prev }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement