Merge branch 'scheduling'
This commit is contained in:
206
packages/events.yaml
Normal file
206
packages/events.yaml
Normal file
@ -0,0 +1,206 @@
|
|||||||
|
###############################################################################
|
||||||
|
# @author : Jeffrey Stone
|
||||||
|
# @date : 02/19/2019
|
||||||
|
# @package : Events
|
||||||
|
# @description : Special Events.
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
input_boolean:
|
||||||
|
school_in_session:
|
||||||
|
name: School In Session
|
||||||
|
icon: mdi:bus-school
|
||||||
|
school_today:
|
||||||
|
name: School Today
|
||||||
|
icon: mdi:bus-school
|
||||||
|
school_early_release:
|
||||||
|
name: School Early Release
|
||||||
|
icon: mdi:bus-school
|
||||||
|
|
||||||
|
input_datetime:
|
||||||
|
school_first_day:
|
||||||
|
name: First Day of School
|
||||||
|
has_date: true
|
||||||
|
has_time: false
|
||||||
|
school_last_day:
|
||||||
|
name: Last Day of School
|
||||||
|
has_date: true
|
||||||
|
has_time: false
|
||||||
|
school_day_start:
|
||||||
|
name: School Day Start
|
||||||
|
has_date: false
|
||||||
|
has_time: true
|
||||||
|
school_day_end:
|
||||||
|
name: School Day End
|
||||||
|
has_date: false
|
||||||
|
has_time: true
|
||||||
|
thanksgiving_break_start:
|
||||||
|
name: Thanksgiving Break
|
||||||
|
has_date: true
|
||||||
|
has_time: false
|
||||||
|
christmas_break_start:
|
||||||
|
name: Christmas Break
|
||||||
|
has_date: true
|
||||||
|
has_time: false
|
||||||
|
spring_break_start:
|
||||||
|
name: Spring Break
|
||||||
|
has_date: true
|
||||||
|
has_time: false
|
||||||
|
school_day_start_reminder:
|
||||||
|
name: School Day Start Reminder
|
||||||
|
has_date: false
|
||||||
|
has_time: true
|
||||||
|
school_day_end_reminder:
|
||||||
|
name: School Day End Reminder
|
||||||
|
has_date: false
|
||||||
|
has_time: true
|
||||||
|
|
||||||
|
sensor:
|
||||||
|
- platform: template
|
||||||
|
sensors:
|
||||||
|
school_start_days2go:
|
||||||
|
value_template: "{{ ((state_attr('input_datetime.school_first_day', 'timestamp')-as_timestamp(now())) | int /60/1440) | round(0) }}"
|
||||||
|
unit_of_measurement: 'Days'
|
||||||
|
school_end_days2go:
|
||||||
|
value_template: "{{ ((state_attr('input_datetime.school_last_day', 'timestamp')-as_timestamp(now())) | int /60/1440) | round(0) }}"
|
||||||
|
unit_of_measurement: 'Days'
|
||||||
|
vacation_days2go:
|
||||||
|
value_template: >
|
||||||
|
{% if state_attr('calendar.vacation', 'start_time') %}
|
||||||
|
{{ ((as_timestamp(strptime(state_attr('calendar.vacation', 'start_time'), '%Y-%m-%d'))-as_timestamp(now())) | int /60/1440) | round(0) }}
|
||||||
|
{% else %}
|
||||||
|
999
|
||||||
|
{% endif %}
|
||||||
|
unit_of_measurement: 'Days'
|
||||||
|
# - platform: rest
|
||||||
|
# resource: https://raw.githubusercontent.com/tm24fan8/home-assistant-config/master/packages/json_data/school.json
|
||||||
|
# name: School Lunch
|
||||||
|
# scan_interval: 14400
|
||||||
|
# value_template: >
|
||||||
|
# {% set today = now().month ~ '/' ~ now().day %}
|
||||||
|
# {% set lunch = value_json.MENU.static[ today ] %}
|
||||||
|
# {%- if lunch %}
|
||||||
|
# {{ lunch }}
|
||||||
|
# {% else %}
|
||||||
|
# Nothing
|
||||||
|
# {%- endif %}
|
||||||
|
|
||||||
|
- platform: rest
|
||||||
|
resource: https://raw.githubusercontent.com/tm24fan8/home-assistant-config/master/packages/json_data/school.json
|
||||||
|
name: School Event
|
||||||
|
scan_interval: 14400
|
||||||
|
value_template: >
|
||||||
|
{% set today = now().month ~ '/' ~ now().day %}
|
||||||
|
{% set event = value_json.EVENTS.static[ today ] %}
|
||||||
|
{%- if event %}
|
||||||
|
{{ event }}
|
||||||
|
{% else %}
|
||||||
|
Nothing
|
||||||
|
{%- endif %}
|
||||||
|
|
||||||
|
automation:
|
||||||
|
- id: refresh_special_event_sensors
|
||||||
|
alias: Refresh special event sensors
|
||||||
|
initial_state: true
|
||||||
|
trigger:
|
||||||
|
- platform: time
|
||||||
|
at: '00:00:01'
|
||||||
|
- platform: homeassistant
|
||||||
|
event: start
|
||||||
|
action:
|
||||||
|
- service: python_script.special_events
|
||||||
|
data:
|
||||||
|
name: Tony
|
||||||
|
type: birthday
|
||||||
|
date: !secret tony_bday
|
||||||
|
- service: python_script.special_events
|
||||||
|
data:
|
||||||
|
name: Tina
|
||||||
|
type: birthday
|
||||||
|
date: !secret tina_bday
|
||||||
|
- service: python_script.special_events
|
||||||
|
data:
|
||||||
|
name: Kallen
|
||||||
|
type: birthday
|
||||||
|
date: !secret kallen_bday
|
||||||
|
- service: python_script.special_events
|
||||||
|
data:
|
||||||
|
name: Emmalynn
|
||||||
|
type: birthday
|
||||||
|
date: !secret emmalynn_bday
|
||||||
|
- service: python_script.special_events
|
||||||
|
data:
|
||||||
|
name: Our Anniversary
|
||||||
|
type: anniversary
|
||||||
|
date: !secret wedding_anniversary
|
||||||
|
|
||||||
|
- id: e1cb2d02-0423-11eb-adc1-0242ac120002
|
||||||
|
alias: School today
|
||||||
|
initial_state: true
|
||||||
|
trigger:
|
||||||
|
- platform: time
|
||||||
|
at: '06:00:00'
|
||||||
|
condition:
|
||||||
|
- 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 -%}
|
||||||
|
action:
|
||||||
|
- choose:
|
||||||
|
- conditions:
|
||||||
|
- condition: template
|
||||||
|
value_template: >
|
||||||
|
{{ 'Early Release' in states('sensor.school_event') }}
|
||||||
|
sequence:
|
||||||
|
- service: input_boolean.turn_on
|
||||||
|
entity_id: input_boolean.school_early_release
|
||||||
|
- service: input_datetime.set_datetime
|
||||||
|
target:
|
||||||
|
entity_id: input_datetime.school_day_end
|
||||||
|
data:
|
||||||
|
time: "14:45:00"
|
||||||
|
default:
|
||||||
|
- service: input_datetime.set_datetime
|
||||||
|
target:
|
||||||
|
entity_id: input_datetime.school_day_end
|
||||||
|
data:
|
||||||
|
time: "15:19:00"
|
||||||
|
- service: input_boolean.turn_on
|
||||||
|
entity_id: input_boolean.school_today
|
||||||
|
- service: script.turn_on
|
||||||
|
entity_id: script.school_in_session
|
||||||
|
|
||||||
|
script:
|
||||||
|
|
||||||
|
school_in_session:
|
||||||
|
sequence:
|
||||||
|
- condition: state
|
||||||
|
entity_id: input_boolean.school_in_session
|
||||||
|
state: 'off'
|
||||||
|
- service: input_boolean.turn_on
|
||||||
|
entity_id: input_boolean.school_in_session
|
||||||
|
|
||||||
|
school_year_over:
|
||||||
|
sequence:
|
||||||
|
- condition: state
|
||||||
|
entity_id: input_boolean.school_in_session
|
||||||
|
state: 'on'
|
||||||
|
- condition: template
|
||||||
|
value_template: >
|
||||||
|
{{ states('input_datetime.school_last_day') == now().strftime("%Y-%m-%d") }}
|
||||||
|
- service: input_boolean.turn_off
|
||||||
|
entity_id: input_boolean.school_in_session
|
||||||
|
|
||||||
|
class_alarm:
|
||||||
|
sequence:
|
||||||
|
- service: script.status_annc
|
||||||
|
data_template:
|
||||||
|
who: '{{ states.sensor.room_presence.state }}'
|
||||||
|
call_interuption: 1
|
||||||
|
speech_message: >
|
||||||
|
{{ class }} starts in two minutes.
|
||||||
|
- service: script.text_notify
|
||||||
|
data:
|
||||||
|
who: 'parents'
|
||||||
|
message: >
|
||||||
|
{{ class }} starts in two minutes.
|
8
packages/json_data/school.json
Normal file
8
packages/json_data/school.json
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"EVENTS": {
|
||||||
|
"static": {
|
||||||
|
"5/25": "Early Release"
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
39
python_scripts/special_events.py
Normal file
39
python_scripts/special_events.py
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
today = datetime.datetime.now().date()
|
||||||
|
|
||||||
|
name = data.get('name')
|
||||||
|
type = data.get('type')
|
||||||
|
sensorName = "sensor.{}_{}".format(type , name.replace(" " , "_"))
|
||||||
|
|
||||||
|
dateStr = data.get('date')
|
||||||
|
dateSplit = dateStr.split("/")
|
||||||
|
|
||||||
|
dateDay = int(dateSplit[0])
|
||||||
|
dateMonth = int(dateSplit[1])
|
||||||
|
dateYear = int(dateSplit[2])
|
||||||
|
date = datetime.date(dateYear,dateMonth,dateDay)
|
||||||
|
|
||||||
|
thisYear = today.year
|
||||||
|
nextOccur = datetime.date(thisYear , dateMonth , dateDay)
|
||||||
|
|
||||||
|
numberOfDays = 0
|
||||||
|
years = int(thisYear) - dateYear
|
||||||
|
|
||||||
|
|
||||||
|
if today < nextOccur:
|
||||||
|
numberOfDays = (nextOccur - today).days
|
||||||
|
|
||||||
|
elif today > nextOccur:
|
||||||
|
nextOccur = datetime.date(thisYear+1 , dateMonth , dateDay)
|
||||||
|
numberOfDays = int((nextOccur - today).days)
|
||||||
|
years = years+1
|
||||||
|
|
||||||
|
|
||||||
|
hass.states.set(sensorName , numberOfDays ,
|
||||||
|
{
|
||||||
|
"icon" : "mdi:calendar-star" ,
|
||||||
|
"unit_of_measurement" : "days" ,
|
||||||
|
"friendly_name" : "{}'s {}".format(name, type) ,
|
||||||
|
"years" : years
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
Reference in New Issue
Block a user