Advertisement
314ma

Untitled

Mar 5th, 2025 (edited)
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 1.70 KB | None | 0 0
  1. data:
  2.   timestamp: >-
  3.     {%- macro next_time(input_id) -%}
  4.       {{ (today_at(states(input_id)) + iif(states(input_id) < now().strftime("%H:%M:%S"), timedelta(days=1), timedelta())) | as_timestamp }}
  5.     {%- endmacro %}
  6.     {%- macro get_range(checkpoint, start_entity, end_entity) -%}
  7.     {%- set next_range_start=next_time(start_entity) | float %}
  8.     {%- set range_end=next_time(end_entity) | float %}
  9.     {%- set range_start = iif(next_range_start > range_end, next_range_start - 86400, next_range_start) -%}
  10.     {%- set checkpoint_in_range = (range_start < checkpoint <= range_end) %}
  11.       {{ [checkpoint_in_range, range_end] | to_json }}
  12.     {%- endmacro %}
  13.     {%- set in_minutes = (now() + timedelta(minutes=states('input_number.delay_duration')|int(180)) | as_timestamp %}
  14.     {%- set is_morning, morning_end = get_range(in_minutes, 'input_datetime.morning_start_output', 'input_datetime.morning_end_output') | from_json %}
  15.     {%- set is_day, day_end = get_range(in_minutes,         'input_datetime.day_start_output',     'input_datetime.day_end_output'    ) | from_json %}
  16.     {%- set is_evening, evening_end = get_range(in_minutes, 'input_datetime.evening_start_output', 'input_datetime.evening_end_output') | from_json %}
  17.     {%- set is_night, night_end = get_range(in_minutes,     'input_datetime.night_start_output',   'input_datetime.night_end_output'  ) | from_json %}
  18.     {%- if is_morning %}{{ morning_end }}
  19.     {%- elif is_day %}{{ day_end }}
  20.     {%- elif is_evening %}{{ evening_end }}
  21.     {%- elif is_night %}{{ night_end }}
  22.     {%- else %}{{ in_minutes }}{%- endif %}
  23. target:
  24.   entity_id: input_datetime.salon_na_parterze_kinkiet_przy_lozku_opoznienie
  25. action: input_datetime.set_datetime
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement