Files
home-assistant-blueprints/Occupancy_Socket_Control_with_Notifications.yaml
T

110 lines
3.6 KiB
YAML

blueprint:
name: Occupancy Socket Control with Power Alert
description: Turns off sockets when everyone leaves home and turns them back on when someone returns. Sends an alert if an appliance was actively drawing power when the home became empty.
domain: automation
input:
home_zone:
name: Home Zone
description: The zone representing your home.
selector:
entity:
domain: zone
default: zone.home
target_switches:
name: Sockets / Switches
description: The smart plugs to turn off when empty and turn on when occupied.
selector:
target:
entity:
domain: switch
power_sensor:
name: Power Metering Sensor
description: The power sensor (Watts) to monitor for active consumption.
selector:
entity:
domain: sensor
device_class: power
power_threshold:
name: Power Threshold (Watts)
description: Minimum wattage to trigger the alert (ignores standby power).
selector:
number:
min: 0.1
max: 100.0
step: 0.1
unit_of_measurement: W
default: 1.0
notify_device:
name: Notification Device
description: Choose the mobile app device that should receive the notification.
selector:
device:
integration: mobile_app
mode: restart
# Bridge blueprint inputs into variables so Jinja can read them
variables:
switch_target: !input target_switches
sensor_entity: !input power_sensor
zone_entity: !input home_zone
trigger:
- platform: zone
entity_id: !input home_zone
event: leave
zone: !input home_zone
id: home_emptied
- platform: zone
entity_id: !input home_zone
event: enter
zone: !input home_zone
id: someone_returned
condition: []
action:
- choose:
# ACTION 1: EVERYONE LEAVES HOME
- conditions:
- condition: trigger
id: home_emptied
- condition: numeric_state
entity_id: !input home_zone
below: 1
sequence:
# Check power consumption before killing the switch
- if:
- condition: numeric_state
entity_id: !input power_sensor
above: !input power_threshold
then:
- domain: mobile_app
type: notify
device_id: !input notify_device
title: "⚠️ Appliance Safely Turned Off"
message: >-
{% set switch_entity = switch_target.entity_id if switch_target.entity_id is string else (switch_target.entity_id | first | default('')) %}
{% set name = state_attr(switch_entity, 'friendly_name') | default('An appliance') | lower %}
{% set area = area_name(switch_entity) | default('') %}
{% set zone_name = state_attr(zone_entity, 'friendly_name') | default('home') | lower %}
The {{ name }}{% if area %} in the {{ area | lower }}{% endif %} was actively drawing power when you left {{ zone_name }}. It has been shut down automatically. Please verify if this requires further attention.
# Turn off the target sockets
- action: switch.turn_off
target: !input target_switches
# ACTION 2: SOMEONE RETURNS HOME
- conditions:
- condition: trigger
id: someone_returned
- condition: numeric_state
entity_id: !input home_zone
above: 0
sequence:
# Turn back on the target sockets
- action: switch.turn_on
target: !input target_switches