summaryrefslogtreecommitdiffstats
path: root/blueprints/automation/motion/occupancy_tracking_restart.yaml
diff options
context:
space:
mode:
Diffstat (limited to 'blueprints/automation/motion/occupancy_tracking_restart.yaml')
-rw-r--r--blueprints/automation/motion/occupancy_tracking_restart.yaml170
1 files changed, 170 insertions, 0 deletions
diff --git a/blueprints/automation/motion/occupancy_tracking_restart.yaml b/blueprints/automation/motion/occupancy_tracking_restart.yaml
new file mode 100644
index 0000000..27855b9
--- /dev/null
+++ b/blueprints/automation/motion/occupancy_tracking_restart.yaml
@@ -0,0 +1,170 @@
+# This can be used stand-alone or in combination with 'motion_switch' (to allow more complex light-on scenarios, e.g. based on current illumination level)
+# For this reason, 'light on' should be programmed in 'on_action' if necessary
+# We can use blueprint using the same entrance/inside sensors, however, this is least robust variant
+# Re-entry events (take a towel go back in) will break automation
+# We can try to prevent by ensuring there is no repeated motions for prolonged time (but, then, blueprint will fail if we do something at entrance)
+
+blueprint:
+ name: Occupancy tracking with restart mode
+ description: Only mode differs, intended for cases where new inside trigger unlikely after exit triggered (this might happen in small places like e.g. toilet where motion might be detected after we have already openned the door)
+ domain: automation
+ input:
+ entrance:
+ name: Entrance
+ description: This can be door sensor or motion sensor monitoring passage via entrance area
+ selector:
+ entity:
+ domain: binary_sensor
+ inside:
+ name: Inside
+ description: Triggers when there is motion inside (this could be the same like entrance or additional sensor, e.g. we monitor motions as 'inside' and door sensor as 'entrance'). Independent sensors are much more robust
+ selector:
+ entity:
+ domain: binary_sensor
+ light:
+ name: Light
+ selector:
+ entity:
+ domain: [switch, light]
+ occupancy:
+ name: Occupancy
+ description: State variable (normally created via Helpers) tracking current state
+ selector:
+ entity:
+ domain: input_boolean
+
+ reentry_wait:
+ name: Re-entry Wait
+ description: Time without motions to handle re-entry events (seconds)
+ default: 1
+ selector:
+ number:
+ min: 0
+ max: 30
+ unit_of_measurement: seconds
+
+ reentry_timeout:
+ name: Re-entry Timeout
+ description: Timeout to assume re-entry if no 'no-motions' trigger were fired within timeout (seconds)
+ default: 10
+ selector:
+ number:
+ min: 1
+ max: 300
+ unit_of_measurement: seconds
+
+ on_action:
+ name: on_action
+ description: Actions to perform while occupancy is detected (lights will not be turned on automatically to allow more complex scenarios via motion-switch automation)
+ default: []
+ selector:
+ action:
+ off_action:
+ name: off_action
+ description: Additional actions to perform when place gets free
+ default: []
+ selector:
+ action:
+
+variables:
+ reentry_wait: !input reentry_wait
+
+# Lights are still on while we are waiting for re-entry. So, we don't need to allow re-trigger in this case and 'single' should do
+mode: restart
+
+trigger:
+ # Either door is open or motion in the entrance area is detected
+ - platform: state
+ id: "entrance"
+ entity_id: !input entrance
+ from: "off"
+ to: "on"
+
+ - platform: state
+ id: "inside"
+ entity_id: !input inside
+ from: "off"
+ to: "on"
+
+ # Light is turned off
+ - platform: state
+ id: "light_off"
+ entity_id: !input light
+ from: "on"
+ to: "off"
+
+action:
+ - choose:
+ # Occupancy goes 'off' if lights are manually (or on timeout) switched off
+ # We can't do the same to turn occupancy 'on' as 'entrance' event might be fired after manually turning lights on (it will be interpreted as leaving)
+ # Will be retriggered back 'on' on any movement inside (so, it is not so critical if something is wrong)
+ - conditions:
+ - condition: trigger
+ id: "light_off"
+ sequence:
+ - parallel:
+ - service: input_boolean.turn_off
+ target:
+ entity_id: !input occupancy
+ - choose: []
+ default: !input "off_action"
+
+ # Occupancy goes 'on' once movement inside is detected (we can't rely on trigger as inside & entrance might coincide)
+ - conditions:
+# - condition: trigger
+# id: "inside"
+ - condition: state
+ entity_id: !input inside
+ state: 'on'
+ - condition: or
+ conditions:
+ - condition: state
+ entity_id: !input occupancy
+ state: 'off'
+ - condition: state
+ entity_id: !input light
+ state: 'off'
+ sequence:
+ - parallel:
+ - service: input_boolean.turn_on
+ target:
+ entity_id: !input occupancy
+ - choose: []
+ default: !input "on_action"
+
+ # Occupancy goes 'off' once entrance triggered while occapncy is 'on' and there are no movements inside for a while
+ - conditions:
+# - condition: trigger
+# id: "entrance"
+ - condition: state
+ entity_id: !input entrance
+ state: 'on'
+ - condition: state
+ entity_id: !input occupancy
+ state: 'on'
+ sequence:
+ - if:
+ - condition: template
+ value_template: '{{ (reentry_wait | float) > 0 }}'
+ then:
+ - wait_for_trigger:
+ - platform: state
+ entity_id: !input inside
+ to: 'off'
+ for:
+ seconds: !input reentry_wait
+ timeout:
+ seconds: !input reentry_timeout
+ continue_on_timeout: false
+
+ - parallel:
+ - service: input_boolean.turn_off
+ target:
+ entity_id: !input occupancy
+ - service: switch.turn_off
+ target:
+ entity_id: !input light
+ - choose: []
+ default: !input "off_action"
+
+ default: []