Last active
February 7, 2024 01:58
-
-
Save koosvanw/64d0cb13cf5b257f7e95c17f8f66875f to your computer and use it in GitHub Desktop.
Sleep trainer blueprint for Home-Assistant
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
blueprint: | |
name: Sleep trainer light using time and RGB light | |
description: 'Creates a sleep trainer using an RGB(w) light to | |
indicate if it is time to get out of bed or not. | |
Usefull for smaller children who cant tell time yet. | |
At the start time the light is turned on red. | |
15 minutes before the wake up time the light is changed to purple-ish | |
At the configured wake up time the light is changed to green. | |
At the stop time the light is turned off again. | |
As target several options are available to choose from. | |
' | |
domain: automation | |
input: | |
enable_trainer_light: | |
name: Enable light | |
description: Enable the actions of the automation to set the ligtht's state | |
default: 'on' | |
selector: | |
entity: | |
domain: input_boolean | |
time_start: | |
name: Time to start | |
description: Time to turn on the light red before it's OK to get up | |
default: "05:30:00" | |
selector: | |
time: | |
time_stop: | |
name: Time to stop | |
description: Time to turn off the light | |
default: "09:00:00" | |
selector: | |
time: | |
time_monday: | |
name: Monday time | |
description: Time to get up on Mondays | |
default: "07:00:00" | |
selector: | |
entity: | |
domain: input_datetime | |
time_tuesday: | |
name: Tuesday time | |
description: Time to get up on Tuesdays | |
default: "07:00:00" | |
selector: | |
entity: | |
domain: input_datetime | |
time_wednesday: | |
name: Wednesday time | |
description: Time to get up on Wednesdays | |
default: "07:00:00" | |
selector: | |
entity: | |
domain: input_datetime | |
time_thursday: | |
name: Thursday time | |
description: Time to get up on Thursdays | |
default: "07:00:00" | |
selector: | |
entity: | |
domain: input_datetime | |
time_friday: | |
name: Friday time | |
description: Time to get up on Fridays | |
default: "07:00:00" | |
selector: | |
entity: | |
domain: input_datetime | |
time_saturday: | |
name: Saturday time | |
description: Time to get up on Saturdays | |
default: "07:00:00" | |
selector: | |
entity: | |
domain: input_datetime | |
time_sunday: | |
name: Sunday time | |
description: Time to get up on Sundays | |
default: "07:00:00" | |
selector: | |
entity: | |
domain: input_datetime | |
target_light: | |
name: Light | |
description: Light entity to use | |
selector: | |
target: | |
entity: | |
domain: light | |
brightness: | |
name: Brightness | |
description: Brightness of the light(s) when turning on | |
default: 10 | |
selector: | |
number: | |
min: 0.0 | |
max: 100.0 | |
mode: slider | |
step: 1.0 | |
unit_of_measurement: '%' | |
mode: queued | |
max_exceeded: silent | |
trigger: | |
- platform: time | |
at: | |
- !input time_start | |
- !input time_stop | |
- !input time_monday | |
- !input time_tuesday | |
- !input time_wednesday | |
- !input time_thursday | |
- !input time_friday | |
- !input time_saturday | |
- !input time_sunday | |
- platform: homeassistant | |
event: start | |
variables: | |
timestart: !input 'time_start' | |
timestop: !input 'time_stop' | |
timemonday: !input 'time_monday' | |
timetuesday: !input 'time_tuesday' | |
timewednesday: !input 'time_wednesday' | |
timethursday: !input 'time_thursday' | |
timefriday: !input 'time_friday' | |
timesaturday: !input 'time_saturday' | |
timesunday: !input 'time_saturday' | |
condition: | |
- condition: state | |
entity_id: !input enable_trainer_light | |
state: 'on' | |
action: | |
- choose: | |
- conditions: | |
- condition: time | |
after: !input time_stop | |
sequence: | |
- service: light.turn_off | |
target: !input target_light | |
data: | |
transition: 2 | |
- conditions: | |
- condition: template | |
value_template: > | |
{% set cdate = now().strftime("%Y-%m-%d ") %} | |
{% set ctime = (now().timestamp() + 1) | int %} | |
{% if now().weekday() in (0,) %} | |
{% set wakeuptime = as_timestamp(strptime(cdate + states(timemonday), '%Y-%m-%d %H:%M:%S')) | int %} | |
{% elif now().weekday() in (1,) %} | |
{% set wakeuptime = as_timestamp(strptime(cdate + states(timetuesday), '%Y-%m-%d %H:%M:%S')) | int %} | |
{% elif now().weekday() in (2,) %} | |
{% set wakeuptime = as_timestamp(strptime(cdate + states(timewednesday), '%Y-%m-%d %H:%M:%S')) | int %} | |
{% elif now().weekday() in (3,) %} | |
{% set wakeuptime = as_timestamp(strptime(cdate + states(timethursday), '%Y-%m-%d %H:%M:%S')) | int %} | |
{% elif now().weekday() in (4,) %} | |
{% set wakeuptime = as_timestamp(strptime(cdate + states(timefriday), '%Y-%m-%d %H:%M:%S')) | int %} | |
{% elif now().weekday() in (5,) %} | |
{% set wakeuptime = as_timestamp(strptime(cdate + states(timesaturday), '%Y-%m-%d %H:%M:%S')) | int %} | |
{% elif now().weekday() in (6,) %} | |
{% set wakeuptime = as_timestamp(strptime(cdate + states(timesunday), '%Y-%m-%d %H:%M:%S')) | int %} | |
{% endif %} | |
{% set starttime = as_timestamp(strptime(cdate + timestart, '%Y-%m-%d %H:%M:%S')) | int %} | |
{{ starttime < ctime < wakeuptime }} | |
sequence: | |
- service: light.turn_on | |
target: !input target_light | |
data: | |
transition: 2 | |
color_name: 'red' | |
brightness_pct: !input brightness | |
- wait_template: > | |
{% set cdate = now().strftime("%Y-%m-%d ") %} | |
{% if now().weekday() in (0,) %} | |
{% set wakeuptime = as_timestamp(strptime(cdate + states(timemonday), '%Y-%m-%d %H:%M:%S')) | int %} | |
{% elif now().weekday() in (1,) %} | |
{% set wakeuptime = as_timestamp(strptime(cdate + states(timetuesday), '%Y-%m-%d %H:%M:%S')) | int %} | |
{% elif now().weekday() in (2,) %} | |
{% set wakeuptime = as_timestamp(strptime(cdate + states(timewednesday), '%Y-%m-%d %H:%M:%S')) | int %} | |
{% elif now().weekday() in (3,) %} | |
{% set wakeuptime = as_timestamp(strptime(cdate + states(timethursday), '%Y-%m-%d %H:%M:%S')) | int %} | |
{% elif now().weekday() in (4,) %} | |
{% set wakeuptime = as_timestamp(strptime(cdate + states(timefriday), '%Y-%m-%d %H:%M:%S')) | int %} | |
{% elif now().weekday() in (5,) %} | |
{% set wakeuptime = as_timestamp(strptime(cdate + states(timesaturday), '%Y-%m-%d %H:%M:%S')) | int %} | |
{% elif now().weekday() in (6,) %} | |
{% set wakeuptime = as_timestamp(strptime(cdate + states(timesunday), '%Y-%m-%d %H:%M:%S')) | int %} | |
{% endif %} | |
{% set curTime = as_timestamp(strptime(cdate + states('sensor.time'), '%Y-%m-%d %H:%M')) | int %} | |
{{ curTime > (wakeuptime - (60 * 15)) }} | |
- service: light.turn_on | |
target: !input target_light | |
data: | |
transition: 2 | |
rgb_color: [255,0,170] | |
brightness_pct: !input brightness | |
- conditions: | |
- condition: template | |
value_template: > | |
{% set cdate = now().strftime("%Y-%m-%d ") %} | |
{% set ctime = (now().timestamp() + 1) | int %} | |
{% if now().weekday() in (0,) %} | |
{% set wakeuptime = as_timestamp(strptime(cdate + states(timemonday), '%Y-%m-%d %H:%M:%S')) | int %} | |
{% elif now().weekday() in (1,) %} | |
{% set wakeuptime = as_timestamp(strptime(cdate + states(timetuesday), '%Y-%m-%d %H:%M:%S')) | int %} | |
{% elif now().weekday() in (2,) %} | |
{% set wakeuptime = as_timestamp(strptime(cdate + states(timewednesday), '%Y-%m-%d %H:%M:%S')) | int %} | |
{% elif now().weekday() in (3,) %} | |
{% set wakeuptime = as_timestamp(strptime(cdate + states(timethursday), '%Y-%m-%d %H:%M:%S')) | int %} | |
{% elif now().weekday() in (4,) %} | |
{% set wakeuptime = as_timestamp(strptime(cdate + states(timefriday), '%Y-%m-%d %H:%M:%S')) | int %} | |
{% elif now().weekday() in (5,) %} | |
{% set wakeuptime = as_timestamp(strptime(cdate + states(timesaturday), '%Y-%m-%d %H:%M:%S')) | int %} | |
{% elif now().weekday() in (6,) %} | |
{% set wakeuptime = as_timestamp(strptime(cdate + states(timesunday), '%Y-%m-%d %H:%M:%S')) | int %} | |
{% endif %} | |
{% set stoptime = as_timestamp(strptime(cdate + timestop, '%Y-%m-%d %H:%M:%S')) | int %} | |
{{ wakeuptime < ctime < stoptime }} | |
sequence: | |
- service: light.turn_on | |
target: !input target_light | |
data: | |
transition: 2 | |
color_name: 'green' | |
brightness_pct: !input brightness |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment