[Claude] - Make Track Abnormal Plug Activity.yaml more practical.

This commit is contained in:
2026-01-22 02:47:59 +03:00
parent 04c2bc1332
commit b7cc945857

View File

@@ -1,15 +1,20 @@
# ============================================================================= # =============================================================================
# Power Spike Tracker Blueprint # Power Overconsumption Monitor Blueprint
# ============================================================================= # =============================================================================
# This blueprint monitors power sensors for abnormal consumption spikes that # This blueprint monitors power sensors for sustained overconsumption that
# might indicate device malfunction or safety concerns. # might indicate device malfunction, overload, or safety concerns.
# #
# Features: # How It Works:
# - Monitors multiple power sensors simultaneously # - Triggers when power EXCEEDS a maximum threshold
# - Configurable spike detection ratio (e.g., 2x = power doubled) # - Requires power to stay high for a configurable duration (filters startup spikes)
# - Minimum threshold to ignore normal low-power fluctuations # - Optionally ignores readings below an idle threshold (device "off")
# - Optional automatic switch turn-off for safety # - Can automatically turn off the switch for safety
# - Derives switch entity from sensor naming convention #
# Use Cases:
# - Space heater drawing more than rated wattage (fire risk)
# - Motor consuming excessive power (mechanical binding/failure)
# - Appliance exceeding safe operating limits
# - Extension cord/circuit overload protection
# #
# Naming Convention: # Naming Convention:
# The blueprint assumes sensors follow the pattern: sensor.<name>_power # The blueprint assumes sensors follow the pattern: sensor.<name>_power
@@ -18,11 +23,11 @@
# ============================================================================= # =============================================================================
blueprint: blueprint:
name: "Custom: Power Spike Tracker" name: "Custom: Power Overconsumption Monitor"
description: > description: >
Monitors power sensors and triggers when consumption spikes beyond a defined Monitors power sensors for sustained overconsumption above a maximum threshold.
ratio compared to the previous reading. Optionally turns off the associated Filters out normal startup spikes by requiring high power for a sustained duration.
switch for safety. Assumes naming convention: sensor.<name>_power -> switch.<name> Optionally turns off the associated switch for safety.
domain: automation domain: automation
input: input:
@@ -44,29 +49,46 @@ blueprint:
# ------------------------------------------------------------------------- # -------------------------------------------------------------------------
# Detection Thresholds # Detection Thresholds
# ------------------------------------------------------------------------- # -------------------------------------------------------------------------
spike_ratio: max_power_threshold:
name: Power Spike Ratio name: Maximum Power Threshold
description: > description: >
Minimum ratio of current/previous power to trigger alert. Alert when power consumption exceeds this value.
Example: 2.0 means power must at least double to trigger. Set this to slightly above the device's normal maximum draw.
default: 2.0 Example: For a 1500W heater, set to 1600W.
default: 1500
selector: selector:
number: number:
min: 1.1 min: 10
max: 10.0 max: 10000
step: 0.1 step: 10
mode: slider unit_of_measurement: W
mode: box
threshold_value: sustained_duration:
name: Minimum Power Threshold name: Sustained Duration
description: > description: >
Ignore spikes if current power is below this value. Power must stay above the threshold for this duration before alerting.
Prevents false alerts from small fluctuations at low power levels. Filters out normal startup spikes and transient fluctuations.
Set to 0 for immediate alerts (not recommended).
default: 30
selector:
number:
min: 0
max: 300
step: 5
unit_of_measurement: seconds
idle_power_threshold:
name: Idle Power Threshold (optional)
description: >
Ignore readings below this value (device considered "off" or idle).
Helps avoid false alerts from sensor noise when device is off.
Set to 0 to monitor all readings.
default: 5 default: 5
selector: selector:
number: number:
min: 0 min: 0
max: 5000 max: 100
step: 1 step: 1
unit_of_measurement: W unit_of_measurement: W
@@ -76,8 +98,8 @@ blueprint:
auto_turn_off: auto_turn_off:
name: Auto Turn Off Switch name: Auto Turn Off Switch
description: > description: >
Automatically turn off the associated switch when a spike is detected. Automatically turn off the associated switch when overconsumption is detected.
Useful for safety when abnormal power draw might indicate a problem. Recommended for safety-critical monitoring.
default: false default: false
selector: selector:
boolean: boolean:
@@ -95,36 +117,37 @@ blueprint:
entity: entity:
domain: notify domain: notify
# Restart mode ensures rapid state changes are handled with latest values # Single mode - we want to track each overconsumption event separately
mode: restart mode: single
max_exceeded: silent
# ============================================================================= # =============================================================================
# Trigger # Trigger - Power exceeds threshold for sustained duration
# ============================================================================= # =============================================================================
trigger: trigger:
# Monitor all configured power sensors for state changes - platform: numeric_state
- platform: state
entity_id: !input power_sensors entity_id: !input power_sensors
id: "power_change" above: !input max_power_threshold
for:
seconds: !input sustained_duration
id: "overconsumption_detected"
# ============================================================================= # =============================================================================
# Variables # Variables
# ============================================================================= # =============================================================================
variables: variables:
# Input references # Input references
spike_ratio: !input spike_ratio max_power_threshold: !input max_power_threshold
auto_turn_off: !input auto_turn_off auto_turn_off: !input auto_turn_off
threshold_value: !input threshold_value
notify_target: !input notify_target notify_target: !input notify_target
idle_power_threshold: !input idle_power_threshold
# Trigger context # Trigger context
entity: "{{ trigger.entity_id }}" entity: "{{ trigger.entity_id }}"
entity_name: "{{ state_attr(trigger.entity_id, 'friendly_name') | default(trigger.entity_id) }}" entity_name: "{{ state_attr(trigger.entity_id, 'friendly_name') | default(trigger.entity_id) }}"
prev: "{{ trigger.from_state.state | float(0) }}" current_power: "{{ states(trigger.entity_id) | float(0) }}"
curr: "{{ trigger.to_state.state | float(0) }}" excess_power: "{{ (current_power - max_power_threshold) | round(1) }}"
excess_percent: "{{ ((current_power / max_power_threshold - 1) * 100) | round(1) if max_power_threshold > 0 else 0 }}"
# Calculate the actual spike ratio for reporting
actual_ratio: "{{ (curr / prev) | round(2) if prev > 0 else 0 }}"
# Derive switch entity from sensor naming convention # Derive switch entity from sensor naming convention
# sensor.<name>_power -> switch.<name> # sensor.<name>_power -> switch.<name>
@@ -136,12 +159,11 @@ variables:
is_debug: false is_debug: false
# ============================================================================= # =============================================================================
# Condition - Only proceed if this is a genuine power spike # Condition - Ensure power is above idle threshold (device is actually "on")
# ============================================================================= # =============================================================================
condition: condition:
- condition: template - condition: template
value_template: > value_template: "{{ current_power > idle_power_threshold }}"
{{ curr > threshold_value and prev > 0 and (curr / prev) >= spike_ratio }}
# ============================================================================= # =============================================================================
# Actions # Actions
@@ -157,19 +179,17 @@ action:
sequence: sequence:
- service: persistent_notification.create - service: persistent_notification.create
data: data:
title: "Power Spike Debug" title: "Power Monitor Debug"
message: > message: >
Entity: {{ entity_name }} ({{ entity }}) Entity: {{ entity_name }} ({{ entity }})
Previous: {{ prev }}W Current: {{ current_power }}W
Current: {{ curr }}W Threshold: {{ max_power_threshold }}W
Ratio: {{ actual_ratio }}x Excess: {{ excess_power }}W (+{{ excess_percent }}%)
Threshold: {{ threshold_value }}W
Required ratio: {{ spike_ratio }}x
Switch: {{ switch_name }} ({{ switch_entity }}) Switch: {{ switch_name }} ({{ switch_entity }})
Auto turn off: {{ auto_turn_off }} Auto turn off: {{ auto_turn_off }}
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
# Send Notification # Send Overconsumption Alert
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
- choose: - choose:
# Use configured notify target if provided # Use configured notify target if provided
@@ -181,16 +201,16 @@ action:
target: target:
entity_id: "{{ notify_target }}" entity_id: "{{ notify_target }}"
data: data:
title: "Power Spike Detected" title: "Power Overconsumption Alert"
message: > message: >
{{ entity_name }}: {{ prev }}W {{ curr }}W ({{ actual_ratio }}x increase) {{ entity_name }} is drawing {{ current_power }}W ({{ excess_power }}W over {{ max_power_threshold }}W limit)
# Fall back to default notify service # Fall back to default notify service
default: default:
- service: notify.notify - service: notify.notify
data: data:
title: "Power Spike Detected" title: "Power Overconsumption Alert"
message: > message: >
{{ entity_name }}: {{ prev }}W {{ curr }}W ({{ actual_ratio }}x increase) {{ entity_name }} is drawing {{ current_power }}W ({{ excess_power }}W over {{ max_power_threshold }}W limit)
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
# Auto Turn Off Switch (if enabled) # Auto Turn Off Switch (if enabled)
@@ -214,8 +234,8 @@ action:
target: target:
entity_id: "{{ notify_target }}" entity_id: "{{ notify_target }}"
data: data:
message: "{{ switch_name }} has been automatically turned off for safety." message: "{{ switch_name }} has been automatically turned off due to overconsumption."
default: default:
- service: notify.notify - service: notify.notify
data: data:
message: "{{ switch_name }} has been automatically turned off for safety." message: "{{ switch_name }} has been automatically turned off due to overconsumption."