So I have an odd custody schedule with my ex. My kids are not home every day, and it varies every other week.
But I wanted to automate lights and stuff to either come on when they get home from school or on days they are not home then they come on right before I get home from work.
So after searching the forum for something similar I ended up using some similar examples to make my own.
/home/homeassistant/.homeassistant/sensors.yaml
- platform: command_line
name: Have Kids In Evening
command: "python3 /home/homeassistant/.homeassistant/scripts/has_kids_evening.py"
scan_interval: 10800
- platform: template
sensors:
kids_home_in_the_evening:
friendly_name: "Kids home in the evening"
value_template: >-
{% if is_state('sensor.have_kids_in_evening', '0') %}
No
{% elif is_state('sensor.have_kids_in_evening', '1') %}
Yes
{% endif %}
/home/homeassistant/.homeassistant/scripts/has_kids_evening.py
import datetime
import json
today = datetime.date.today()
has_kids_evening = None;
if (today.isocalendar()[1] & 1) == 0:
if today.weekday() == 0:
has_kids_evening = 1;
elif today.weekday() == 1:
has_kids_evening = 1;
elif today.weekday() == 2:
has_kids_evening = 0;
elif today.weekday() == 3:
has_kids_evening = 0;
elif today.weekday() == 4:
has_kids_evening = 1;
elif today.weekday() == 5:
has_kids_evening = 1;
elif today.weekday() == 6:
has_kids_evening = 1;
else:
if today.weekday() == 0:
has_kids_evening = 0;
elif today.weekday() == 1:
has_kids_evening = 0;
elif today.weekday() == 2:
has_kids_evening = 1;
elif today.weekday() == 3:
has_kids_evening = 1;
elif today.weekday() == 4:
has_kids_evening = 0;
elif today.weekday() == 5:
has_kids_evening = 0;
elif today.weekday() == 6:
has_kids_evening = 0;
print(has_kids_evening)
/home/homeassistant/.homeassistant/automations.yaml
- alias: 'Kids - Home from School'
trigger:
- platform: time
at: "15:05:00"
condition:
condition: and
conditions:
- condition: state
entity_id: sensor.have_kids_in_evening
state: "1"
- condition: time
weekday:
- mon
- tue
- wed
- thu
- fri
action:
- service: light.turn_on
data:
entity_id:
- light.hall_main_floor
- light.upstairs_hall
- light.playroom_back
- light.playroom_front
- light.floor_lamp
brightness: 255
- service: light.turn_on
data:
entity_id:
- light.livingroom_coffee_table_rgb_strip
brightness: 255
rgb_color: [255,255,255]