Files
Home-Assistant-Configs/custom_templates/time.jinja

58 lines
2.0 KiB
Django/Jinja

{% macro timer_duration(input_number) %}
{{ (states(input_number)) | int * 60 }}
{% endmacro %}
{% macro current_time_12hr() %}
{{ now().strftime('%-I:%M %p') }}
{% endmacro %}
{% macro current_time_24hr() %}
{{ now().strftime('%H:%M') }}
{% endmacro %}
{% macro current_date_input() %}
{{ now().strftime('%Y-%m-%d') }}
{% endmacro %}
{% macro input_datetime_12hr(entity) %}
{{ state_attr(entity,'timestamp') | int | timestamp_custom('%-I:%M %p', False) }}
{% endmacro %}
{% macro input_datetime_12hr_with_date(entity) %}
{{ state_attr(entity,'timestamp') | int | timestamp_custom('%-I:%M %p') }}
{% endmacro %}
{% macro current_date_readout() %}
{{ states('sensor.today_is') }}, {{ as_timestamp(now()) | timestamp_custom('%B %d %Y') }}
{% endmacro %}
{% macro calendar_event_today(calendar) %}
{{ as_timestamp(strptime(state_attr(calendar,'start_time'), '%Y-%m-%d %H:%M:%S')) | timestamp_custom("%Y-%m-%d") == now().strftime("%Y-%m-%d") }}
{% endmacro %}
{% macro set_time_from_calendar(calendar,start_or_end) %}
{{ as_timestamp(strptime(state_attr(calendar,start_or_end), '%Y-%m-%d %H:%M:%S')) | timestamp_custom("%H:%M") }}
{% endmacro %}
{% macro read_time_from_calendar(calendar,start_or_end) %}
{{ as_timestamp(strptime(state_attr(calendar,start_or_end), '%Y-%m-%d %H:%M:%S')) | timestamp_custom("%I:%M %p") }}
{% 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() %}
{% from 'easy_time.jinja' import custom_time %}
{{ custom_time('calendar.tony_s_twitch_schedule','week,day,hour,minute') }}
{% endmacro %}