From 140fb403134adc51a70e01db3dc17217b8ea1527 Mon Sep 17 00:00:00 2001
From: Jeffrey Stone <thejeffreystone@gmail.com>
Date: Sun, 7 Jun 2020 19:32:41 -0400
Subject: [PATCH] Adding school year and day trackers to tune audible messages:

---
 config/packages/daily.yaml  | 14 +++++++++++++-
 config/packages/events.yaml | 34 ++++++++++++++++++++++++++++++++++
 2 files changed, 47 insertions(+), 1 deletion(-)

diff --git a/config/packages/daily.yaml b/config/packages/daily.yaml
index 2bea296..74d248a 100755
--- a/config/packages/daily.yaml
+++ b/config/packages/daily.yaml
@@ -15,7 +15,7 @@ automation:
     action:
       - service: clean_up_snapshots_service.clean_up
 
-  # Nightly Entity Refresh - For all those sensors that need a little push
+  # Morning Entity Refresh - For all those sensors that need a little push
   - id: daily_entity_refresh
     alias: Daily Entity Refresh
     initial_state: 'on'
@@ -27,4 +27,16 @@ automation:
         entity_id: sensor.today_is 
       - service: homeassistant.update_entity
         entity_id: sensor.holiday
+  
+  # Nightly Entity Refresh - For all those sensors that need a little push
+  - id: daily_entity_refresh2
+    alias: Daily Entity Refresh2
+    initial_state: 'on'
+    trigger: 
+    - platform: time
+      at: '17:00:00'
+    action:
+      - service: homeassistant.update_entity
+        entity_id: sensor.school_tomorrow
+      
     
\ No newline at end of file
diff --git a/config/packages/events.yaml b/config/packages/events.yaml
index fe82472..a0b3621 100755
--- a/config/packages/events.yaml
+++ b/config/packages/events.yaml
@@ -10,6 +10,40 @@ input_boolean:
     name: Rex Manning audio
     icon: mdi:speaker-wireless
 
+input_datetime:
+  school_first_day:
+    name: First Day of School
+    has_date: true
+    has_time: false
+    initial: '2020-08-05'
+  school_last_day:
+    name: Last Day of School
+    has_date: true
+    has_time: false
+    initial: '2021-05-26'
+  school_day_start:
+    name: School Day Start
+    has_date: false
+    has_time: true
+    initial: '07:45:00'
+  school_day_end:
+    name: School Day End
+    has_date: false
+    has_time: true
+    initial: '14:45:00'
+
+sensor:
+  - platform: template
+    sensors:
+      school_start_days2go:
+        value_template: '{{ (((states.input_datetime.school_first_day.attributes.timestamp)-as_timestamp(now())) | int /60/1440) | round(0) }}'
+        unit_of_measurement: 'Days'
+        entity_id: input_datetime.school_first_day,sensor.time
+      school_end_days2go:
+        value_template: '{{ (((states.input_datetime.school_last_day.attributes.timestamp)-as_timestamp(now())) | int /60/1440) | round(0) }}'
+        unit_of_measurement: 'Days'
+        entity_id: input_datetime.school_last_day,sensor.time
+
 automation:
   - id: refresh_special_event_sensors
     alias: Refresh special event sensors