Template macros
This commit is contained in:
4
custom_templates/lighting.jinja
Normal file
4
custom_templates/lighting.jinja
Normal file
@ -0,0 +1,4 @@
|
||||
{% macro get_brightness_pct(entity_id) %}
|
||||
{% set current = state_attr(entity_id,'brightness') %}
|
||||
{{ ((current / 255) * 100) | float | round(2) }}
|
||||
{% endmacro %}
|
44
custom_templates/speech.jinja
Normal file
44
custom_templates/speech.jinja
Normal file
@ -0,0 +1,44 @@
|
||||
{% macro greeting() %}
|
||||
{% if now().strftime('%H')|int < 12 %}
|
||||
{{ [
|
||||
"Good morning. ",
|
||||
"Top of the morning to you laddy. ",
|
||||
] | random }}
|
||||
{% elif now().strftime('%H')|int >= 12 and now().strftime('%H')|int < 17 %}
|
||||
{{ [
|
||||
"Greetings earthling. ",
|
||||
"Good afternoon. ",
|
||||
"How do you do, fellow kids? ",
|
||||
] | random }}
|
||||
{% else %}
|
||||
{{ [
|
||||
"Good evening. ",
|
||||
"The grandest of evenings to you. "
|
||||
] | random }}
|
||||
{% endif %}
|
||||
{% if is_state('binary_sensor.morning','on') %}
|
||||
Today is {{ states('sensor.today_is') }}, {{ as_timestamp(now()) | timestamp_custom('%B %d %Y') }}.
|
||||
{% endif %}
|
||||
It is {{ now().strftime("%I:%M %p") }}.
|
||||
{% endmacro %}
|
||||
|
||||
{% macro greeting_nodate() %}
|
||||
{% if now().strftime('%H')|int < 12 %}
|
||||
{{ [
|
||||
"Good morning. ",
|
||||
"Top of the morning to you laddy. ",
|
||||
] | random }}
|
||||
{% elif now().strftime('%H')|int >= 12 and now().strftime('%H')|int < 17 %}
|
||||
{{ [
|
||||
"Greetings earthling. ",
|
||||
"Good afternoon. ",
|
||||
"How do you do, fellow kids? ",
|
||||
] | random }}
|
||||
{% else %}
|
||||
{{ [
|
||||
"Good evening. ",
|
||||
"The grandest of evenings to you. "
|
||||
] | random }}
|
||||
{% endif %}
|
||||
It is {{ now().strftime("%I:%M %p") }}.
|
||||
{% endmacro %}
|
19
custom_templates/time.jinja
Normal file
19
custom_templates/time.jinja
Normal file
@ -0,0 +1,19 @@
|
||||
{% macro timer_duration(input_number) %}
|
||||
{{ (states(input_number)) | int * 60 }}
|
||||
{% endmacro %}
|
||||
|
||||
{% macro current_time_12hr() %}
|
||||
{{ now().strftime("%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 %}
|
Reference in New Issue
Block a user