blueprint: name: Occupancy Socket Control with Global Power Alert description: Turns off sockets when everyone leaves home and turns them back on when someone returns. Automatically sends an alert to all mobile devices 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 mode: restart 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 sending notifications - if: - condition: numeric_state entity_id: !input power_sensor above: !input power_threshold then: - action: notify.notify data: 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