-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoctopus_saving_session_detection.yaml
193 lines (192 loc) · 7.03 KB
/
octopus_saving_session_detection.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
blueprint:
name: Octopus Saving Session Detection
description: Detects an upcoming OPTED-IN saving session, sets start and end time entities, and enables your session export automation. Will also disable your automation at the end of the session too. You must have the Octopus Energy integration installed and working already. This version 2023-11-29 v04.01
domain: automation
input:
octopus_saving_sessions_entity:
name: Octopus Energy Saving Sessions Binary Sensor Entity
description: From the Octopus Energy integration - binary_sensor.octopus_energy_a_xxxxxxxx_octoplus_saving_sessions
selector:
entity:
domain:
- binary_sensor
multiple: false
octopus_saving_session_event_entity:
name: Octoplus Saving Session Events Events Entity
description: From the Octopus Energy integration - event.octopus_energy_a_xxxxxxxx_octoplus_saving_session_events
selector:
entity:
domain:
- event
multiple: false
dfs_start_time:
name: Session Start Time Entity
description: Create a time-only helper to contain the start time of the Saving Session
Session
selector:
entity:
domain:
- input_datetime
multiple: false
dfs_end_time:
name: Session End Time Entity
description: Create a time-only helper to contain the end time of the Saving Session
selector:
entity:
domain:
- input_datetime
multiple: false
saving_session_automations:
name: Saving Session Automations
description: Choose all of your saving session automations for this automation to enable and disable for you
selector:
entity:
domain:
- automation
multiple: true
variables:
dfs_start_time: !input dfs_start_time
dfs_end_time: !input dfs_end_time
octopus_saving_sessions_entity: !input octopus_saving_sessions_entity
octopus_saving_session_event_entity: !input octopus_saving_session_event_entity
trigger_variables:
trigger_dfs_end_time: !input dfs_end_time
trigger:
- alias: New Session - triggers on new saving session event
platform: event
event_type: octopus_energy_new_octoplus_saving_session
id: New_Session
- alias: >-
Joined Session - triggers when any of the three entity attributes change
and also every thirty minutes
platform: state
entity_id:
- !input octopus_saving_sessions_entity
attribute: next_joined_event_start
id: Joined_Session
- platform: state
entity_id:
- !input octopus_saving_sessions_entity
attribute: next_joined_event_end
id: Joined_Session
- platform: state
entity_id:
- !input octopus_saving_sessions_entity
attribute: next_joined_event_duration_in_minutes
id: Joined_Session
- platform: time_pattern
minutes: /30
id: Joined_Session
- alias: End of session - activites required after session has finished
platform: time
at: !input dfs_end_time
id: Finished_Session
condition:
- or:
- alias: New Session - no further conditions
condition: trigger
id: New_Session
- alias: Finished Session - no further conditions
condition: trigger
id: Finished_Session
- and:
- alias: >-
Joined Session - checks that all 3 entity attributes are not null
and validates the data by calculating that the duration is equal
to the difference between the start time and the end time and also
that the start time is within the next 24 hours
condition: trigger
id: Joined_Session
- not:
- condition: state
entity_id: !input octopus_saving_sessions_entity
attribute: next_joined_event_start
state: null
- not:
- condition: state
entity_id: !input octopus_saving_sessions_entity
attribute: next_joined_event_end
state: null
- not:
- condition: state
entity_id: !input octopus_saving_sessions_entity
attribute: next_joined_event_duration_in_minutes
state: null
- condition: template
value_template: >-
{{
((state_attr(octopus_saving_sessions_entity,'next_joined_event_end')|as_local
-
state_attr(octopus_saving_sessions_entity,'next_joined_event_start')|as_local).total_seconds()
/ 60) ==
state_attr(octopus_saving_sessions_entity,'next_joined_event_duration_in_minutes')
}}
- condition: template
value_template: >-
{{
(((state_attr(octopus_saving_sessions_entity,'next_joined_event_start')|as_local
- now()).total_seconds()) / 60) < (24 * 60) }}
- condition: template
value_template: >-
{{
(((state_attr(octopus_saving_sessions_entity,'next_joined_event_start')|as_local
- now()).total_seconds()) / 60) > 0 }}
action:
- choose:
- conditions:
- condition: trigger
id: New_Session
sequence:
- service: octopus_energy.join_octoplus_saving_session_event
data:
event_code: '{{ trigger.event.data["event_code"] }}'
target:
entity_id: !input octopus_saving_session_event_entity
- service: persistent_notification.create
data:
title: Saving Sessions Updated
message: >-
Joined new Octopus Energy saving session. It starts at {{
trigger.event.data["event_start"].strftime('%H:%M') }} on {{
trigger.event.data["event_start"].day }}/{{
trigger.event.data["event_start"].month }}
- conditions:
- condition: trigger
id:
- Joined_Session
sequence:
- service: input_datetime.set_datetime
data:
datetime: >-
{{
state_attr(octopus_saving_sessions_entity,'next_joined_event_start')
}}
target:
entity_id: !input dfs_start_time
- service: input_datetime.set_datetime
data:
datetime: >-
{{
state_attr(octopus_saving_sessions_entity,'next_joined_event_end')
}}
target:
entity_id: !input dfs_end_time
- service: automation.turn_on
data: {}
target:
entity_id: !input saving_session_automations
- conditions:
- condition: trigger
id:
- Finished_Session
sequence:
- delay:
hours: 0
minutes: 5
seconds: 0
milliseconds: 0
- service: automation.turn_off
data: {}
target:
entity_id: !input saving_session_automations
mode: single