Improve current_time macro

This commit is contained in:
2023-11-06 12:51:54 -05:00
parent b863d7f004
commit 4b21639690
5 changed files with 35 additions and 32 deletions

View File

@ -4,19 +4,22 @@
{{ (states(input_number)) | int * 60 }}
{% endmacro %}
{% macro current_time(hr,date) %}
{% if hr == 12 %}
{{ now().strftime('%-I:%M %p') }}
{% elif hr == 24 %}
{% if date is defined %}
{% if date == 'withdate' %}
{{ now().strftime('%Y-%m-%d %H:%M:%S') }}
{% elif date == 'nodate' %}
{{ now().strftime('%H:%M') }}
{% endif %}
{% else %}
{{ now().strftime('%H:%M') }}
{% 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 %}