From 7e7b965bf38907fe3c23a9059faad6d0be2471c3 Mon Sep 17 00:00:00 2001 From: Tony Stork Date: Sun, 22 May 2022 17:52:45 -0400 Subject: [PATCH] Added logic for wife's work status --- packages/events.yaml | 42 ++++++++++++++++++++++++++++++++++++++++++ packages/presence.yaml | 2 +- sensors/time.yaml | 14 ++++++++++++++ 3 files changed, 57 insertions(+), 1 deletion(-) diff --git a/packages/events.yaml b/packages/events.yaml index 0c09b3b..1b38caf 100644 --- a/packages/events.yaml +++ b/packages/events.yaml @@ -8,6 +8,9 @@ input_boolean: school_early_release: name: School Early Release icon: mdi:bus-school + work_today: + name: Work Today + icon: mdi:briefcase input_datetime: school_first_day: @@ -163,6 +166,35 @@ automation: - service: script.turn_on entity_id: script.school_in_session + - id: cd9f921f-71c7-4e29-9aee-7421ef19bdd3 + alias: Work Today + initial_state: true + trigger: + - platform: time + at: '05:45:00' + condition: + - 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 -%} + action: + - service: input_datetime.set_datetime + target: + 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") }} + - 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") }} + - service: input_boolean.turn_on + entity_id: input_boolean.work_today + + - id: b9028665-401c-4de3-8f13-1099160b011f alias: School Reset initial_state: true @@ -173,6 +205,16 @@ automation: - service: input_boolean.turn_off entity_id: input_boolean.school_today + - id: a6eeb075-d21b-436c-983f-39188ee9b016 + alias: Work Reset + initial_state: true + trigger: + - platform: time + at: input_datetime.tina_workday_end + action: + - service: input_boolean.turn_off + entity_id: input_boolean.work_today + script: school_in_session: diff --git a/packages/presence.yaml b/packages/presence.yaml index 61241cd..2b8fe25 100644 --- a/packages/presence.yaml +++ b/packages/presence.yaml @@ -59,7 +59,7 @@ sensor: {% set person = states.person.christina_stork.state %} {%- if person in ['Wal-Mart','Kroger','Chief','Meijer'] %} Grocery Store - {% elif person in ['Chipotle','Ft Wayne Chipotle'] and is_state('binary_sensor.tina_work','on') %} + {% elif person in ['Chipotle'] and is_state('input_boolean.work_today','on') %} Work {% else %} {% if person in ['not_home','Stationary'] %} diff --git a/sensors/time.yaml b/sensors/time.yaml index 80492f7..114e788 100644 --- a/sensors/time.yaml +++ b/sensors/time.yaml @@ -18,6 +18,20 @@ {% else %} off {% endif %} + work_tomorrow: + friendly_name: 'Work Tomorrow' + value_template: >- + {%- set test=(as_timestamp(now())+ (86400)) | timestamp_custom("%Y-%m-%d",true) %} + {% if states.calendar.family_tinawork.attributes.start_time == test + " 09:00:00" %} + on + {% elif states.calendar.family_tinawork.attributes.start_time == test + " 07:00:00" %} + on + {% elif states.calendar.family_tinawork.attributes.start_time == test + " 10:00:00" %} + on + {% else %} + off + {% endif %} + - platform: time_date display_options: - 'time'