-
Notifications
You must be signed in to change notification settings - Fork 18
/
appliance-status-monitor.yaml
652 lines (585 loc) · 28.3 KB
/
appliance-status-monitor.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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
blueprint:
name: Monitor the state of an appliance - by leofabri
description: >-
`- Version: 2.1.1 -`
This automation can detect and monitor the state of your appliances by observing their power consumption.
This automation blueprint is universal and very versatile. You can use it with anything that consumes energy: a washing machine, a dishwasher, your fridge, the TV, etc.
I refer to the appliance's operations with the generic word job. A job could be anything (washing, rinsing...).
You can pair this project with other automations and services. I designed it with flexibility in mind. For instance, if you want to
send alerts when the washing machine is not resuming a job, you want to send TTS notifications, or if
your fridge is somehow not working and de-icing you can see that happening. All you needed is just a little bit of creativity.
You can use the state machine and the custom actions to extend it.
The state machine:
* **<ins>unplugged</ins>** - The appliance is no longer powered. It happens when the user manually turns off the smart socket (from HA or the socket itself).
* **<ins>idle</ins>** - There is no pending job, the machine is powered but idling.
* **paused** - Indicates that a job is pending (incomplete cycle), but the appliance is not performing it. The inhibitors of these state are the ***detached_overload*** and ***unplugged*** states. In this condition the power consumption is lower than the finishing power threshold. The appliance must be off (maybe the user turned it off manually, or maybe the job needs some time to recover). The blueprint is waiting for the appliance to resume. **Pro Tip!** You could also use this to diagnose and warn if a job is not resumed after x minutes.
* **<ins>detached_overload</ins>** - This happens when, during a cycle, the appliance used too much power and was suspended. It is also technically unplugged but we don't say that.
* **<ins>job_ongoing</ins>** - Triggered in two cases:
* when a new job cycle begins: the previous one is completed, and the Starting Power threshold is surpassed.
* when a job is resumed.
* **<ins>job_completed</ins>** - Triggered when the current incomplete job cycle is finished. The appliance consumes less than the Finishing Power threshold (with the possibility of selecting for how long)
<strong>First setup?</strong> <i>[Follow the instructions](https://github.com/leofabri/hassio_appliance-status-monitor)</i>
domain: automation
input:
appliance_socket:
name: Appliance Smart Socket
description: >-
(*REQUIRED)
The socket that is used to control this appliance.
default: []
selector:
entity:
domain: switch
appliance_power_sensor:
name: Appliance Power Consumption
description: >-
(*REQUIRED)
The power entity with the current power absorption in Watts.
default: []
selector:
entity:
domain: sensor
appliance_starting_power_threshold:
name: Starting power threshold
description: >-
(*REQUIRED)
Power threshold above which we assume the appliance has started
a new job or is resuming the current one (job_ongoing state).
default: 5
selector:
number:
min: 1.0
max: 100.0
unit_of_measurement: W
mode: slider
step: 1.0
appliance_finishing_power_threshold:
name: Finishing power threshold
description: >-
(*REQUIRED)
Power threshold below which we assume the appliance has finished
a job (job_completed state).
default: 3
selector:
number:
min: 1.0
max: 100.0
unit_of_measurement: W
mode: slider
step: 1.0
appliance_suspended_sensor:
name: Appliance Suspended entity
description: >-
(OPTIONAL)
An input_number variable that turns into a value > 0 when an overload occurs. That would
indicate that the machine was disconnected.
default: []
selector:
entity:
domain: input_number
appliance_state_machine:
name: Appliance State Machine
description: >-
(*REQUIRED | Helper | Name: <i><strong><your_appliance_name>_state_machine</strong></i> | [?](https://github.com/leofabri/hassio_appliance-status-monitor/blob/main/home%20assistant/packages/your_appliance_name.yaml#L18))
The State Machine entity of this appliance.
default: []
selector:
entity:
domain: input_select
appliance_job_cycle:
name: Appliance Job Cycle
description: >-
(*REQUIRED | Helper | Name: <i><strong><your_appliance_name>_job_cycle</strong></i> | [?](https://github.com/leofabri/hassio_appliance-status-monitor/blob/main/home%20assistant/packages/your_appliance_name.yaml#L9))
A sensor that stores whether the appliance is still in a job cycle
or not.<br>
This has to be a boolean (so: 0 or 1).<br> <strong>off</strong> -> the appliance is
not performing any job<br> <strong>on</strong> -> the job is incomplete.
<br>
<strong>Note that this entity does not provide any information about the detailed status
of the machine (like an overload stuation). For that, you need the state machine.</strong>
<br>
default: []
selector:
entity:
domain: input_boolean
delayed_job_completion_timer:
name: Delayed Job Completion timer
description: >-
(*REQUIRED | Helper | Name: <i><strong><your_appliance_name>_delayed_job_completion_timer</i></strong> | [?](https://github.com/leofabri/hassio_appliance-status-monitor/blob/main/home%20assistant/packages/your_appliance_name.yaml#L2))
The timer that will allow to 'wait' & 'see' before assuming that a job has been completed
default: []
selector:
entity:
domain: timer
automation_self_trigger:
name: Automation Self-triggering entity
description: >-
(*REQUIRED | Helper | Name: <i><strong><your_appliance_name>_automation_self_trigger</i></strong> | [?](https://github.com/leofabri/hassio_appliance-status-monitor/blob/main/home%20assistant/packages/your_appliance_name.yaml#L13))
This entity is in charge of triggering the execution of the automation when it changes from off -> on.
Sometimes, if the power consumption of the appliance is perfectly steady, no other trigger will work, but this will.
This variable allows the automation to call itself when some conditions are met.
default: []
selector:
entity:
domain: input_boolean
delayed_job_completion_duration:
name: Delayed Job Completion duration
description: >-
(OPTIONAL | Helper | <i><strong>Suggested: 0, Default: 0 | DISABLED</strong></i>)
During a job cycle, some appliances may intermittently use less power than the finishing power threshold,
thus entering the job_completed state (even when the job is not finished).
With this value set, the automation will wait for the indicated time in seconds, and see if in that timespan the power consumption rises.
...
<strong>WARNING:</strong> Setting a duration introduces a delay on the transition to the 'job_completed' state.
Please make sure that you really need this, or leave it 0 if unsure.
default: 0.0
selector:
number:
min: 0.0
max: 900.0
step: 1.0
unit_of_measurement: seconds
mode: slider
actions_new_job_cycle_begins:
name: Action(s) when a new job cycle begins
description: >-
Executed when the appliance starts a new job cycle (<strong>idle -> job_ongoing</strong>
state).
Note that here the job cycle indicator is off, which means that no previous job has to be completed.
...
**WARNING:** Just use non-blocking actions in this space! No delays, actionable notifications, TTS, waits, or anything that takes time to execute.
Please consider that the permanence in this state could last for a limited amount of time (seconds, potentially!).
This section is meant to be used to trigger other things.
If you really need to trigger long operations, a clean solution is to dispatch the work by calling other services or using the State Machine entity to wake up other external automations.
default: []
selector:
action:
actions_job_cycle_resumes:
name: Action(s) when a job cycle resumes
description: >-
Executed when a pending job cycle is resumed (<strong>paused | unplugged | detached_overload -> job_ongoing</strong>
state).
Note that in this situation, the job cycle indicator is still on. That's how I know that the appliance is resuming and not startig a job.
...
**WARNING:** Just use non-blocking actions in this space! No delays, actionable notifications, TTS, waits, or anything that takes time to execute.
Please consider that the permanence in this state could last for a limited amount of time (seconds, potentially!).
This section is meant to be used to trigger other things.
If you really need to trigger long operations, a clean solution is to dispatch the work by calling other services or using the State Machine entity to wake up other external automations.
default: []
selector:
action:
actions_job_cycle_ends:
name: Action(s) when a job cycle is finished
description: >-
Executed when the appliance finishes a job cycle (<strong>job_ongoing -> job_completed</strong>
state).
...
**WARNING:** Just use non-blocking actions in this space! No delays, actionable notifications, TTS, waits, or anything that takes time to execute.
Please consider that the permanence in this state could last for a limited amount of time (seconds, potentially!).
This section is meant to be used to trigger other things.
If you really need to trigger long operations, a clean solution is to dispatch the work by calling other services or using the State Machine entity to wake up other external automations.
default: []
selector:
action:
actions_unplugged_overload:
name: Action(s) when an overload occurs
description: >-
Executed when the appliance is detected as unplugged (because of an overload
situation).
...
**WARNING:** Just use non-blocking actions in this space! No delays, actionable notifications, TTS, waits, or anything that takes time to execute.
Please consider that the permanence in this state could last for a limited amount of time (seconds, potentially!).
This section is meant to be used to trigger other things.
If you really need to trigger long operations, a clean solution is to dispatch the work by calling other services or using the State Machine entity to wake up other external automations.
default: []
selector:
action:
actions_paused_after_overload:
name: Action(s) when the overload situation is solved, now paused
description: >-
Executed when the state changes from <strong>detached_overload -> paused</strong> (NOT resuming the job).
...
**WARNING:** Just use non-blocking actions in this space! No delays, actionable notifications, TTS, waits, or anything that takes time to execute.
Please consider that the permanence in this state could last for a limited amount of time (seconds, potentially!).
This section is meant to be used to trigger other things.
If you really need to trigger long operations, a clean solution is to dispatch the work by calling other services or using the State Machine entity to wake up other external automations.
default: []
selector:
action:
actions_resuming_after_overload:
name: Action(s) when the overload situation is solved, now resuming
description: >-
Executed when the state changes from <strong>detached_overload
-> job_ongoing</strong> (resuming the previous job).
...
**WARNING:** Just use non-blocking actions in this space! No delays, actionable notifications, TTS, waits, or anything that takes time to execute.
Please consider that the permanence in this state could last for a limited amount of time (seconds, potentially!).
This section is meant to be used to trigger other things.
If you really need to trigger long operations, a clean solution is to dispatch the work by calling other services or using the State Machine entity to wake up other external automations.
default: []
selector:
action:
actions_paused_after_unplugged:
name: Action(s) when the appliance is plugged back in, now paused
description: >-
Executed when the state changes from <strong>unplugged -> paused</strong> (NOT resuming the job).
...
**WARNING:** Just use non-blocking actions in this space! No delays, actionable notifications, TTS, waits, or anything that takes time to execute.
Please consider that the permanence in this state could last for a limited amount of time (seconds, potentially!).
This section is meant to be used to trigger other things.
If you really need to trigger long operations, a clean solution is to dispatch the work by calling other services or using the State Machine entity to wake up other external automations.
default: []
selector:
action:
source_url: https://github.com/leofabri/hassio_appliance-status-monitor/blob/main/appliance-status-monitor.yaml
variables:
appliance_socket: !input "appliance_socket"
appliance_suspended_sensor: !input "appliance_suspended_sensor"
delayed_job_completion_duration: !input "delayed_job_completion_duration"
delayed_job_completion_timer: !input "delayed_job_completion_timer"
trigger:
- platform: state
entity_id: !input "appliance_power_sensor"
id: power_event
- platform: state
entity_id: !input "appliance_socket"
id: socket_state_change_event
- platform: state
entity_id: !input "appliance_state_machine"
from: detached_overload
to: paused
id: paused_after_overload_event
- platform: state
entity_id: !input "appliance_state_machine"
from: unplugged
to: paused
id: paused_after_unplugged_event
- platform: state
entity_id: !input "appliance_state_machine"
from: detached_overload
to: job_ongoing
id: resuming_after_paused_overload_event
- platform: state
entity_id: !input "automation_self_trigger"
from: "off"
to: "on"
id: automation_self_triggered
- platform: event
event_type: timer.finished
event_data:
entity_id: !input "delayed_job_completion_timer"
id: job_completed_timer_finished
- platform: homeassistant
event: start
id: home_assistant_started_event
- platform: event
event_type:
- automation_reloaded
id: automation_reloaded_event
condition:
- condition: or
conditions:
- condition: trigger
id: power_event
- condition: trigger
id: socket_state_change_event
- condition: trigger
id: paused_after_overload_event
- condition: trigger
id: paused_after_unplugged_event
- condition: trigger
id: resuming_after_paused_overload_event
- condition: trigger
id: automation_self_triggered
- condition: trigger
id: job_completed_timer_finished
- condition: trigger
id: home_assistant_started_event
- condition: trigger
id: automation_reloaded_event
action:
- service: input_boolean.turn_off
data: {}
target:
entity_id: !input "automation_self_trigger"
- choose:
- conditions:
- condition: template
value_template: "{{ appliance_suspended_sensor|length > 0 }}"
- condition: and
conditions:
- condition: template
value_template: "{{ states(appliance_suspended_sensor) | float > 0.0 }}"
- condition: state
entity_id: !input "appliance_job_cycle"
state: "on"
sequence:
- condition: not
conditions:
- condition: state
entity_id: !input "appliance_state_machine"
state: detached_overload
- service: input_select.select_option
data:
option: detached_overload
target:
entity_id: !input "appliance_state_machine"
- choose: []
default: !input "actions_unplugged_overload"
- choose:
- conditions:
- condition: state
entity_id: !input "appliance_job_cycle"
state: "on"
- condition: template
value_template: "{% if appliance_suspended_sensor|length > 0 %}{{ states(appliance_suspended_sensor) | float <= 0.0 }}{% else %}true{% endif %}"
- condition: template
value_template: "{{ states(appliance_socket) == 'on' }}"
- condition: numeric_state
entity_id: !input "appliance_power_sensor"
below: !input "appliance_finishing_power_threshold"
- condition: or
conditions:
- condition: state
entity_id: !input "appliance_state_machine"
state: detached_overload
- condition: state
entity_id: !input "appliance_state_machine"
state: unplugged
- condition: not
conditions:
- condition: state
entity_id: !input "appliance_state_machine"
state: paused
sequence:
- service: input_select.select_option
data:
option: paused
target:
entity_id: !input "appliance_state_machine"
- conditions:
- condition: template
value_template: "{{ states(appliance_socket) == 'off' }}"
- condition: not
conditions:
- condition: template
value_template: "{{ appliance_suspended_sensor|length > 0 }}"
- condition: and
conditions:
- condition: template
value_template: "{% if appliance_suspended_sensor|length > 0 %}{{ states(appliance_suspended_sensor) | float > 0.0 }}{% else %}false{% endif %}"
- condition: state
entity_id: !input "appliance_state_machine"
state: detached_overload
sequence:
- condition: not
conditions:
- condition: state
entity_id: !input "appliance_state_machine"
state: unplugged
- service: input_select.select_option
data:
option: unplugged
target:
entity_id: !input "appliance_state_machine"
- choose:
- conditions:
- condition: template
value_template: "{{ states(delayed_job_completion_timer) == 'active' }}"
sequence:
- service: timer.cancel
data: {}
target:
entity_id: !input "delayed_job_completion_timer"
- conditions:
- condition: trigger
id: paused_after_overload_event
sequence:
- choose: []
default: !input "actions_paused_after_overload"
- conditions:
- condition: trigger
id: paused_after_unplugged_event
sequence:
- choose: []
default: !input "actions_paused_after_unplugged"
- conditions:
- condition: trigger
id: resuming_after_paused_overload_event
sequence:
- choose: []
default: !input "actions_resuming_after_overload"
default:
- choose:
- conditions:
- condition: template
value_template: "{{ states(appliance_socket) == 'on' }}"
- condition: numeric_state
entity_id: !input "appliance_power_sensor"
above: !input "appliance_starting_power_threshold"
sequence:
- choose:
- conditions:
- condition: template
value_template:
"{{ states(delayed_job_completion_timer) == 'active'
}}"
sequence:
- service: timer.cancel
data: {}
target:
entity_id: !input "delayed_job_completion_timer"
- condition: not
conditions:
- condition: state
entity_id: !input "appliance_state_machine"
state: job_ongoing
- service: input_select.select_option
data:
option: job_ongoing
target:
entity_id: !input "appliance_state_machine"
- choose:
- conditions:
- condition: state
entity_id: !input "appliance_job_cycle"
state: "off"
sequence:
- service: input_boolean.turn_on
data: {}
target:
entity_id: !input "appliance_job_cycle"
- choose: []
default: !input "actions_new_job_cycle_begins"
default:
- choose: []
default: !input "actions_job_cycle_resumes"
- conditions:
- condition: state
entity_id: !input "appliance_state_machine"
state: job_ongoing
- condition: state
entity_id: !input "appliance_job_cycle"
state: "on"
- condition: template
value_template: "{{ states(appliance_socket) == 'on' }}"
- condition: numeric_state
entity_id: !input "appliance_power_sensor"
below: !input "appliance_finishing_power_threshold"
sequence:
- choose:
- conditions:
- condition: template
value_template:
"{{ states(delayed_job_completion_timer) != 'active'
}}"
- condition: not
conditions:
- condition: trigger
id: job_completed_timer_finished
sequence:
- service: timer.start
data: {}
target:
entity_id: !input "delayed_job_completion_timer"
- choose:
- conditions:
- condition: template
value_template: "{{ delayed_job_completion_duration > 0 }}"
sequence:
- choose:
- conditions:
- condition: template
value_template:
"{% if states(delayed_job_completion_timer) == 'active'\
\ %}\n {% set t_expiring_date = state_attr(delayed_job_completion_timer,\
\ 'finishes_at') %}\n {% set t_remaining_sec = 0 if t_expiring_date\
\ == None else (as_datetime(t_expiring_date) - now()).total_seconds()\
\ | int %}\n {% set t_total_duration = state_attr(delayed_job_completion_timer,\
\ 'duration') %}\n {% set duration_split = t_total_duration.split(':')\
\ %}\n {% set t_total_duration_sec = (duration_split[0] | int\
\ * 3600) + (duration_split[1] | int * 60) + (duration_split[0]\
\ | int) %}\n {% set t_elapsed_sec = (t_total_duration_sec - t_remaining_sec)\
\ | int %}\n {{ t_elapsed_sec < (delayed_job_completion_duration)\
\ | int }}\n{% else %}\n {{0}}\n{% endif %}"
sequence:
- delay:
seconds:
"{% if states(delayed_job_completion_timer) == 'active'\
\ %}\n {% set t_expiring_date = state_attr(delayed_job_completion_timer,\
\ 'finishes_at') %}\n {% set t_remaining_sec = 0 if t_expiring_date\
\ == None else (as_datetime(t_expiring_date) - now()).total_seconds()\
\ | int %}\n {% set t_total_duration = state_attr(delayed_job_completion_timer,\
\ 'duration') %}\n {% set duration_split = t_total_duration.split(':')\
\ %}\n {% set t_total_duration_sec = (duration_split[0] | int\
\ * 3600) + (duration_split[1] | int * 60) + (duration_split[0]\
\ | int) %}\n {% set t_elapsed_sec = (t_total_duration_sec -\
\ t_remaining_sec) | int %}\n {% set t_remaining = ((delayed_job_completion_duration)\
\ | int) - t_elapsed_sec %}\n \n {{ 1 + t_remaining }}\n{% else\
\ %}\n {{ 1 + (delayed_job_completion_duration) | int }}\n{%\
\ endif %}"
- service: input_boolean.turn_on
data: {}
target:
entity_id: !input "automation_self_trigger"
- condition: template
value_template: "{{0}}"
default: []
- service: input_boolean.turn_off
data: {}
target:
entity_id: !input "appliance_job_cycle"
- service: input_select.select_option
data:
option: job_completed
target:
entity_id: !input "appliance_state_machine"
- choose:
- conditions:
- condition: template
value_template:
"{{ states(delayed_job_completion_timer) == 'active'
}}"
sequence:
- service: timer.cancel
data: {}
target:
entity_id: !input "delayed_job_completion_timer"
- choose: []
default: !input "actions_job_cycle_ends"
- choose:
- conditions:
- condition: or
conditions:
- condition: trigger
id: automation_self_triggered
- condition: template
value_template: "{{ delayed_job_completion_duration <= 0 }}"
sequence:
- delay:
minutes: 1
- service: input_boolean.turn_on
data: {}
target:
entity_id: !input "automation_self_trigger"
default:
- choose:
- conditions:
- condition: state
entity_id: !input "appliance_job_cycle"
state: "off"
- condition: not
conditions:
- condition: state
entity_id: !input "appliance_state_machine"
state: idle
sequence:
- service: input_select.select_option
data:
option: idle
target:
entity_id: !input "appliance_state_machine"
mode: restart
max_exceeded: silent
trace:
stored_traces: 10