Grid Substation Telemetry Health Monitor Script
Generate a resilient Python telemetry validation script for SCADA power distribution sensor streams.
Use this prompt when deploying automated ingestion health checks for electric substation telemetry streams. It builds a modular validation script that detects anomalous voltage spikes and drops before SCADA database ingestion.
Role: Principal SCADA Systems Integration Engineer specializing in power distribution telemetry automation.
Context
- Target Substation ID: {{grid_substation_id}}
- Ingestion Source: {{telemetry_data_source}}
- Telemetry Sensor Types: {{sensor_metric_types}}
- Expected Ingestion Frequency: {{sampling_rate_hz}} Hz
- Outlier Rejection Threshold: {{anomaly_threshold_sigma}} sigma
- Incident Notification Webhook: {{alert_webhook_url}}
Task
Write a production-ready Python automation script that continuously consumes substation sensor metrics from the source, computes rolling statistical baselines, flags transient anomalies exceeding safety bounds, and dispatches webhook alerts while logging clean time-series records.
Method
- Establish resilient streaming connection logic for {{telemetry_data_source}} with exponential backoff retry parameters.
- Validate incoming packet schema against expected metric definitions for {{sensor_metric_types}} originating from {{grid_substation_id}}.
- Maintain a rolling memory buffer matching a 5-minute window derived from {{sampling_rate_hz}} sampling rates.
- Calculate rolling mean and standard deviation per metric to identify fluctuations exceeding {{anomaly_threshold_sigma}} sigma.
- Filter out corrupted payloads and append clean metric tuples to an optimized batch persistence queue.
- Construct an alert dispatcher that sends payload-level telemetry failure notices to {{alert_webhook_url}}.
- Implement graceful SIGTERM and SIGINT interrupt handling to flush pending memory queues safely.
- Include standard error logging with ISO-8601 timestamps and precise hardware sensor identifiers.
Constraints
- MUST implement pure standard library or widely supported industrial libraries (requests, numpy) with pinned versions.
- MUST NOT drop telemetry packets silently during transient network failures; implement an in-memory queue fallback.
- Code MUST be entirely self-contained, fully executable, and contain no placeholder comments or omitted logic.
- Include inline docstrings and PEP-8 compliant type annotations across all routine definitions.
Output format
Provide the solution in three explicit sections:
- Dependencies and Environment: A bulleted list of prerequisite libraries and required environment variables.
- Telemetry Processing Script: The complete, runnable Python script inside a single code block.
- Execution and Testing Guide: A concise 3-step terminal walkthrough illustrating script initialization and sample execution.
Self-review
- Confirm that every variable ({{grid_substation_id}}, {{telemetry_data_source}}, {{sensor_metric_types}}, {{sampling_rate_hz}}, {{anomaly_threshold_sigma}}, {{alert_webhook_url}}) is directly used in the implementation.
- Verify all error handlers protect against network timeouts when hitting {{alert_webhook_url}}.
- Check that the rolling standard deviation calculation aligns with {{anomaly_threshold_sigma}}.
Explicit role, a named task, and discrete steps the model can follow.
Background, inputs and variables the model needs before it starts.
Hard boundaries — what the model must and must not do.
A named, field-level shape for the response.
Ordered work items that force analysis before an answer.
Length and structure that travel across frontier models.
Signal density — instruction weight without padding.
Documented variables so the scaffold adapts to new inputs.
Quality bar, assumptions and behaviour when inputs are thin.
How much real usage the template has behind it.