Template macros

This commit is contained in:
2023-04-05 20:08:52 -04:00
parent bb37a240d0
commit 2ec072af86
12 changed files with 111 additions and 84 deletions

View File

@ -271,8 +271,8 @@ sensor:
friendly_name: "Basement Studio Lights - Brightness Actual"
unique_id: dee4dc84-a6a0-4150-903e-5b8bd436d962
value_template: >
{% set current = state_attr('light.basement_studio_lights','brightness') %}
{{ ((current / 255) * 100) | float | round(2) }}
{% from 'lighting.jinja' import get_brightness_pct %}
{{ get_brightness_pct('light.basement_studio_lights') }}
availability_template: "{{ is_state('light.basement_studio_lights','on') }}"
unit_of_measurement: '%'
icon_template: mdi:brightness-percent
@ -321,8 +321,8 @@ sensor:
friendly_name: "Living Room Lights - Brightness Actual"
unique_id: e557022a-184f-4111-bb6a-6c0869cce42c
value_template: >
{% set current = state_attr('light.living_room_lights','brightness') %}
{{ ((current / 255) * 100) | float | round(2) }}
{% from 'lighting.jinja' import get_brightness_pct %}
{{ get_brightness_pct('light.living_room_lights') }}
availability_template: "{{ is_state('light.living_room_lights','on') }}"
unit_of_measurement: '%'
icon_template: mdi:brightness-percent
@ -585,7 +585,9 @@ automation:
target:
entity_id: timer.living_room_motion_timer
data:
duration: "{{ (states('input_number.living_room_lights_off_delay') | int ) * 60 }}"
duration: >
{% from 'time.jinja' import timer_duration %}
{{ timer_duration('input_number.living_room_lights_off_delay') }}
- conditions:
- condition: trigger
id: timer-finished
@ -773,7 +775,9 @@ automation:
target:
entity_id: timer.basement_studio_door_timer
data:
duration: "{{ (states('input_number.basement_studio_lights_off_delay') | int ) * 60 }}"
duration: >
{% from 'time.jinja' import timer_duration %}
{{ timer_duration('input_number.basement_studio_lights_off_delay') }}
- conditions:
- condition: trigger
id: basement-occupied
@ -799,7 +803,9 @@ automation:
target:
entity_id: timer.basement_studio_door_timer
data:
duration: "{{ (states('input_number.basement_studio_lights_off_delay') | int ) * 60 }}"
duration: >
{% from 'time.jinja' import timer_duration %}
{{ timer_duration('input_number.basement_studio_lights_off_delay') }}
- conditions:
- condition: trigger
id: timer-finished

View File

@ -200,10 +200,11 @@ script:
entity_id: input_datetime.kallen_school_day_start
data:
time: >
{% from 'time.jinja' import set_time_from_calendar %}
{% if is_state('input_boolean.two_hour_delay','on') %}
11:00
{% else %}
{{ as_timestamp(strptime(state_attr('calendar.kallen_school_days','start_time'), '%Y-%m-%d %H:%M:%S')) | timestamp_custom("%H:%M") }}
{{ set_time_from_calendar('calendar.kallen_school_days','start_time') }}
{% endif %}
- delay:
seconds: 1

View File

@ -281,9 +281,8 @@ automation:
- if:
- condition: template
value_template: >
{%- if as_timestamp(strptime(state_attr('calendar.kallen_school_days', 'start_time'), '%Y-%m-%d %H:%M:%S')) | timestamp_custom("%Y-%m-%d") == now().strftime("%Y-%m-%d") %}
true
{%- endif -%}
{% from 'time.jinja' import calendar_event_today %}
{{ calendar_event_today('calendar.kallen_school_days') }}
then:
- service: script.kallen_school_today
- service: input_boolean.turn_on
@ -418,13 +417,15 @@ script:
entity_id: input_datetime.kallen_school_day_end
data:
time: >
{{ as_timestamp(strptime(state_attr('calendar.kallen_school_days','end_time'), '%Y-%m-%d %H:%M:%S')) | timestamp_custom("%H:%M") }}
{% from 'time.jinja' import set_time_from_calendar %}
{{ set_time_from_calendar('calendar.kallen_school_days','end_time') }}
- service: input_datetime.set_datetime
target:
entity_id: input_datetime.kallen_school_day_start
data:
time: >
{{ as_timestamp(strptime(state_attr('calendar.kallen_school_days','start_time'), '%Y-%m-%d %H:%M:%S')) | timestamp_custom("%H:%M") }}
{% from 'time.jinja' import set_time_from_calendar %}
{{ set_time_from_calendar('calendar.kallen_school_days','start_time') }}
- service: input_boolean.turn_on
entity_id:
- input_boolean.kallen_school_today

View File

@ -32,9 +32,8 @@ automation:
- if:
- condition: template
value_template: >
{%- if as_timestamp(strptime(state_attr('calendar.family_tinawork','start_time'), '%Y-%m-%d %H:%M:%S')) | timestamp_custom("%Y-%m-%d") == now().strftime("%Y-%m-%d") %}
true
{%- endif -%}
{% from 'time.jinja' import calendar_event_today %}
{{ calendar_event_today('calendar.family_tinawork') }}
then:
- service: script.tina_work_today
- service: input_boolean.turn_on
@ -59,13 +58,15 @@ script:
entity_id: input_datetime.tina_workday_start
data:
time: >
{{ as_timestamp(strptime(state_attr('calendar.family_tinawork','start_time'), '%Y-%m-%d %H:%M:%S')) | timestamp_custom("%H:%M") }}
{% from 'time.jinja' import set_time_from_calendar %}
{{ set_time_from_calendar('calendar.family_tinawork','start_time') }}
- service: input_datetime.set_datetime
target:
entity_id: input_datetime.tina_workday_end
data:
time: >
{{ as_timestamp(strptime(state_attr('calendar.family_tinawork','end_time'), '%Y-%m-%d %H:%M:%S')) | timestamp_custom("%H:%M") }}
{% from 'time.jinja' import set_time_from_calendar %}
{{ set_time_from_calendar('calendar.family_tinawork','end_time') }}
- service: input_boolean.turn_on
target:
entity_id: input_boolean.work_today
@ -84,9 +85,8 @@ script:
- if:
- condition: template
value_template: >
{%- if as_timestamp(strptime(state_attr('calendar.family_tinawork','start_time'), '%Y-%m-%d %H:%M:%S')) | timestamp_custom("%Y-%m-%d") == now().strftime("%Y-%m-%d") %}
true
{%- endif -%}
{% from 'time.jinja' import calendar_event_today %}
{{ calendar_event_today('calendar.family_tinawork') }}
then:
- service: script.tina_work_today
else:

View File

@ -22,9 +22,8 @@ automation:
condition:
- condition: template
value_template: >
{%- if as_timestamp(strptime(state_attr('calendar.tony_s_twitch_schedule','start_time'), '%Y-%m-%d %H:%M:%S')) | timestamp_custom("%Y-%m-%d") == now().strftime("%Y-%m-%d") %}
true
{%- endif -%}
{% from 'time.jinja' import calendar_event_today %}
{{ calendar_event_today('calendar.tony_s_twitch_schedule') }}
action:
- service: script.tony_stream_today
@ -67,7 +66,8 @@ script:
entity_id: input_datetime.tony_streaming_start_time
data:
time: >
{{ as_timestamp(strptime(state_attr('calendar.tony_s_twitch_schedule','start_time'), '%Y-%m-%d %H:%M:%S')) | timestamp_custom("%H:%M") }}
{% from 'time.jinja' import set_time_from_calendar %}
{{ set_time_from_calendar('calendar.tony_s_twitch_schedule','start_time') }}
- service: input_boolean.turn_on
entity_id: input_boolean.tony_streaming_today