forked from Burningstone91/smart-home-setup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sleep.yaml
executable file
·103 lines (100 loc) · 3.31 KB
/
sleep.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
input_boolean:
sleep_mode:
name: Schlafmodus
icon: mdi:sleep
bed_sabrina:
name: Bett Sabrina
bed_dimitri:
name: Bett Dimitri
input_select:
# Sleep state Dimitri
sleep_state_dimitri:
name: Schlaf Dimitri
options:
- gerade hingelegt
- gerade aufgestanden
- wach
- schläft
- zurück im Bett
# Sleep state Sabrina
sleep_state_sabrina:
name: Schlaf Sabrina
options:
- gerade hingelegt
- gerade aufgestanden
- wach
- schläft
- zurück im Bett
automation:
# Sets the sleep state of the persons
- id: set_person_sleep_state
alias: "Bestimme Schlafstatus Personen"
mode: parallel
trigger:
- platform: state
entity_id: binary_sensor.bed_dimitri
for:
seconds: 10
- platform: state
entity_id: input_boolean.bed_dimitri
- platform: state
entity_id: input_select.sleep_state_dimitri
for:
minutes: 5
- platform: state
entity_id: input_boolean.bed_sabrina
- platform: state
entity_id: input_select.sleep_state_sabrina
for:
minutes: 5
action:
- variables:
person: "{{ trigger.to_state.entity_id.split('_')[-1] }}"
input_select: "input_select.sleep_state_{{ person }}"
new: "{{ trigger.to_state.state }}"
- service: input_select.select_option
data:
entity_id: "{{ input_select }}"
option: >
{% if new == 'on' and is_state(input_select, 'gerade aufgestanden') %}
zurück im Bett
{% elif new == 'on' %}
gerade hingelegt
{% elif new == 'off' %}
gerade aufgestanden
{% elif new == 'gerade aufgestanden' %}
wach
{% elif new in ['zurück im Bett', 'gerade hingelegt'] %}
schläft
{% else %}
{{ states(input_select) }}
{% endif %}
# Enable sleep mode when everyone is in bed, disable when everyone is awake
- id: set_sleep_mode_based_on_bed_occupancy
alias: "Schlafmodus einschalten wenn alle im Bett und ausschalten wenn alle wach sind."
mode: parallel
variables:
in_bed_states: ['gerade hingelegt', 'schläft', 'zurück im Bett']
trigger:
- platform: state
entity_id: input_select.sleep_state_dimitri
- platform: state
entity_id: input_select.sleep_state_sabrina
action:
- choose:
# IF everyone just laid down/sleeping/back to bed -> turn on sleep mode
- conditions:
- "{{ is_state('input_boolean.sleep_mode', 'off') }}"
- "{{ states('input_select.sleep_state_dimitri') in in_bed_states }}"
- "{{ states('input_select.sleep_state_sabrina') in in_bed_states }}"
sequence:
service: input_boolean.turn_on
entity_id: input_boolean.sleep_mode
# IF everyone awake -> turn off sleep mode
- conditions:
- "{{ is_state('input_boolean.sleep_mode', 'on') }}"
- "{{ is_state('input_select.sleep_state_dimitri', 'wach') }}"
- "{{ is_state('input_select.sleep_state_sabrina', 'wach') }}"
sequence:
service: input_boolean.turn_off
entity_id: input_boolean.sleep_mode