|
blueprint: |
|
name: Wasp-in-a-box light control |
|
description: Turn on light based on the wasp-in-a-box paradigm. Opening the box and detecting the wasp should turn on the light. Deciding that the wasp is no longer in the box and reverting to a closed box with no motion and no presumed wasp should turn off the light. |
|
domain: automation |
|
author: tetele |
|
input: |
|
wasp_sensor: |
|
name: Activity sensor |
|
description: A binary sensor indicating whether there is activity in the room. |
|
selector: |
|
entity: |
|
domain: binary_sensor |
|
wasp_sensor_cooldown: |
|
name: Activity sensor cooldown |
|
description: The time it takes after activity is no longer detected until the activity sensor returns to "clear". |
|
selector: |
|
duration: |
|
default: |
|
seconds: 2 |
|
minutes: 0 |
|
hours: 0 |
|
box_sensor: |
|
name: Open box sensor |
|
description: A binary sensor indicating whether the box is open. |
|
selector: |
|
entity: |
|
domain: |
|
- binary_sensor |
|
- input_boolean |
|
wasp_in_a_box_sensor: |
|
name: Wasp in box sensor |
|
description: A computed sensor indicating whether the wasp is in the box. |
|
selector: |
|
entity: |
|
domain: binary_sensor |
|
light_entity: |
|
name: Light entity |
|
description: The light to toggle when the wasp is definitely in the box. |
|
selector: |
|
entity: |
|
domain: light |
|
extra_conditions: |
|
name: Extra conditions |
|
description: Conditions required for the automation to run. |
|
selector: |
|
condition: |
|
default: [] |
|
|
|
mode: restart |
|
|
|
trigger: |
|
- id: wasp_detected |
|
platform: state |
|
entity_id: !input wasp_sensor |
|
from: "off" |
|
to: "on" |
|
- id: wasp_cleared |
|
platform: state |
|
entity_id: !input wasp_sensor |
|
from: "on" |
|
to: "off" |
|
- id: box_opened |
|
platform: state |
|
entity_id: !input box_sensor |
|
from: "off" |
|
to: "on" |
|
- id: box_opened_long_ago |
|
platform: state |
|
entity_id: !input box_sensor |
|
from: "off" |
|
to: "on" |
|
for: !input wasp_sensor_cooldown |
|
- id: box_closed |
|
platform: state |
|
entity_id: !input box_sensor |
|
from: "on" |
|
to: "off" |
|
- id: box_closed_long_ago |
|
platform: state |
|
entity_id: !input box_sensor |
|
from: "on" |
|
to: "off" |
|
for: !input wasp_sensor_cooldown |
|
- id: wasp_left_box_long_ago |
|
platform: state |
|
entity_id: !input wasp_in_a_box_sensor |
|
from: "on" |
|
to: "off" |
|
for: !input wasp_sensor_cooldown |
|
condition: !input extra_conditions |
|
variables: |
|
wasp_sensor: !input wasp_sensor |
|
wasp_sensor_cooldown_dict: !input wasp_sensor_cooldown |
|
wasp_sensor_cooldown: > |
|
{{ wasp_sensor_cooldown_dict.hours|float(0)*3600 + wasp_sensor_cooldown_dict.minutes|float(0)*60 + wasp_sensor_cooldown_dict.seconds|float(0) }} |
|
action: |
|
- alias: "what triggered the action" |
|
choose: |
|
- conditions: |
|
# Opening the box and detecting the wasp should turn on the light. |
|
- condition: trigger |
|
id: |
|
- box_opened |
|
- wasp_detected |
|
sequence: |
|
- alias: "turn on the light" |
|
service: light.turn_on |
|
target: |
|
entity_id: !input light_entity |
|
# Deciding that the wasp is no longer in the box and reverting to a closed box with no motion and no presumed wasp should turn off the light. |
|
- conditions: |
|
- condition: trigger |
|
id: wasp_left_box_long_ago |
|
- condition: state |
|
entity_id: !input wasp_sensor |
|
state: "off" |
|
- condition: template |
|
value_template: "{{ as_timestamp(now())|float - states[wasp_sensor].last_changed|as_timestamp|float > wasp_sensor_cooldown }}" |
|
sequence: |
|
- alias: "turn off the light" |
|
service: light.turn_off |
|
target: |
|
entity_id: !input light_entity |
|
- conditions: |
|
- condition: trigger |
|
id: box_closed_long_ago |
|
- condition: state |
|
entity_id: !input wasp_sensor |
|
state: "off" |
|
- condition: template |
|
value_template: "{{ as_timestamp(now())|float - states[wasp_sensor].last_changed|as_timestamp|float > wasp_sensor_cooldown }}" |
|
sequence: |
|
- alias: "turn off the light" |
|
service: light.turn_off |
|
target: |
|
entity_id: !input light_entity |
|
- conditions: |
|
- condition: trigger |
|
id: box_opened_long_ago |
|
- condition: state |
|
entity_id: !input wasp_sensor |
|
state: "off" |
|
- condition: template |
|
value_template: "{{ as_timestamp(now())|float - states[wasp_sensor].last_changed|as_timestamp|float > wasp_sensor_cooldown }}" |
|
sequence: |
|
- alias: "turn off the light" |
|
service: light.turn_off |
|
target: |
|
entity_id: !input light_entity |
|
- conditions: |
|
- condition: trigger |
|
id: wasp_cleared |
|
- condition: state |
|
entity_id: !input wasp_in_a_box_sensor |
|
state: "off" |
|
sequence: |
|
- alias: "turn off the light" |
|
service: light.turn_off |
|
target: |
|
entity_id: !input light_entity |
|
# This is just an optimization |
|
- conditions: |
|
- condition: trigger |
|
id: box_closed |
|
- condition: state |
|
entity_id: !input wasp_sensor |
|
state: "off" |
|
- condition: state |
|
entity_id: !input wasp_in_a_box_sensor |
|
state: "off" |
|
sequence: |
|
- alias: "turn off the light" |
|
service: light.turn_off |
|
target: |
|
entity_id: !input light_entity |