{% from 'easy_time.jinja' import custom_time %} {% macro timer_duration(input_number) %} {{ (states(input_number)) | int * 60 }} {% endmacro %} {% macro current_time(type,hr) %} {% set hr = hr|default(24) %} {% if type == 'datetime' %} {% if hr == 12 %} {{ now().strftime('%Y-%m-%d %-I:%M %p') }} {% elif hr == 24 %} {{ now().strftime('%Y-%m-%d %H:%M:%S') }} {% endif %} {% elif type == 'time' %} {% if hr == 12 %} {{ now().strftime('%-I:%M %p') }} {% elif hr == 24 %} {{ now().strftime('%H:%M:%S') }} {% endif %} {% elif type == 'date' %} {{ now().strftime('%Y-%m-%d') }} {% endif %} {% endmacro %} {% macro current_date_input() %} {{ now().strftime('%Y-%m-%d') }} {% endmacro %} {% macro input_datetime_read(entity) %} {% if state_attr(entity,'has_date') == true %} {{ state_attr(entity,'timestamp') | int | timestamp_custom('%-I:%M %p') }} {% elif state_attr(entity,'has_date') == false %} {{ state_attr(entity,'timestamp') | int | timestamp_custom('%-I:%M %p', False) }} {% endif %} {% endmacro %} {% macro current_date_readout() %} {{ states('sensor.today_is') }}, {{ as_timestamp(now()) | timestamp_custom('%B %d %Y') }} {% endmacro %} {% macro calendar_event_today(calendar) %} {% if state_attr(calendar,'start_time') %} {{ as_timestamp(strptime(state_attr(calendar,'start_time'), '%Y-%m-%d %H:%M:%S')) | timestamp_custom("%Y-%m-%d") == now().strftime("%Y-%m-%d") }} {% endif %} {% endmacro %} {% macro time_from_calendar(calendar,start_or_end,action,operator,hours,minutes) %} {% set base = as_timestamp(strptime(state_attr(calendar,start_or_end), '%Y-%m-%d %H:%M:%S')) | int %} {% if minutes is defined %} {% set mod = ((hours * 60) * 60) + (minutes * 60) | int %} {% elif hours is defined %} {% set mod = (hours* 60) * 60 | int %} {% endif %} {% if action == 'set' %} {% set ts = "%H:%M" %} {% elif action == 'read' %} {% set ts = "%-I:%M %p" %} {% endif %} {% if operator is defined %} {% if operator == 'add' %} {{ (base + mod) | timestamp_custom(ts) }} {% elif operator == 'subtract' %} {{ (base - mod) | timestamp_custom(ts) }} {% endif %} {% else %} {{ base | timestamp_custom(ts) }} {% endif %} {% endmacro %} {% macro datetime_from_calendar(calendar,start_or_end,action,operator,days,hours,minutes) %} {% set base = as_timestamp(strptime(state_attr(calendar,start_or_end), '%Y-%m-%d %H:%M:%S')) | int %} {% if minutes is defined %} {% set mod = ((((days * 24) * 60) * 60) + (hours* 60) * 60) + (minutes * 60) | int %} {% elif hours is defined %} {% set mod = (((days * 24) * 60) * 60) + (hours* 60) * 60 | int %} {% elif days is defined %} {% set mod = ((days * 24) * 60) * 60 | int %} {% endif %} {% if action == 'set' %} {% set ts = "%Y-%m-%d %H:%M:%S" %} {% elif action == 'read' %} {% set ts = "%Y-%m-%d %-I:%M %p" %} {% endif %} {% if operator is defined %} {% if operator == 'add' %} {{ (base + mod) | timestamp_custom(ts) }} {% elif operator == 'subtract' %} {{ (base - mod) | timestamp_custom(ts) }} {% endif %} {% else %} {{ base | timestamp_custom(ts) }} {% endif %} {% endmacro %} {% macro set_datetime(hours,minutes,seconds) %} {% if seconds is defined %} {{ (as_timestamp(now()) + (((hours * 60) * 60) + (minutes * 60)) + seconds) | int | timestamp_custom('%Y-%m-%d %H:%M:%S') }} {% elif minutes is defined %} {{ (as_timestamp(now()) + ((hours * 60) * 60) + (minutes * 60)) | int | timestamp_custom('%Y-%m-%d %H:%M:%S') }} {% else %} {{ (as_timestamp(now()) + (hours* 60) * 60) | int | timestamp_custom('%Y-%m-%d %H:%M:%S') }} {% endif %} {% endmacro %} {% macro ct() %} {{ ((now().hour * 60 + now().minute) * 60 ) }} {% endmacro %} {% macro next_twitch_stream() %} {{ custom_time('calendar.tony_s_twitch_schedule','week,day,hour') }} {% endmacro %}