WinCC Comfort HMI: Send Active Alarm Count to PLC Tags

David Krause11 min read
HMI / SCADASiemensTutorial / How-to
Licensed PE Working through this on a live machine? A Maine-licensed engineer can take it from here — included with IMD hardware, by the hour for everything else. Book an engineer

1. Problem Definition and Target Architecture

Most WinCC Comfort / TIA Portal projects classify alarms into named classes ("Errors", "Warnings", "Information"). The HMI already maintains the full active-state list internally - the engineering cost is in mirroring that state into the PLC so that two physical digital outputs (for example, DO_Error_Lamp and DO_Warning_Lamp) can be driven without re-listing every alarm tag in the PLC program.

The recommended reference architecture is:

  1. An S7-1200 (firmware V4.2 or later) or S7-1500 PLC owns two counter tags (e.g. DB_HMI.HMI_ErrorCount and DB_HMI.HMI_WarningCount) of type Int.
  2. The TP1200 Comfort HMI runs a VBS script on a cyclic schedule that reads the current active alarm set, filters by alarm class, and writes the two integer counts back to the PLC tags.
  3. The PLC evaluates > 0 on each counter and latches or drives the two DOs accordingly. Edge detection on the count delta can be used to debounce and to support acknowledged/unacknowledged logic.
This pattern works for all Comfort Panels (TP700, TP900, TP1200, TP1500, TP1900, TP2200) and for WinCC Runtime Advanced on PC. The script does not require modifying any alarm configuration on the PLC side - the alarm list remains an HMI-only resource.

2. Prerequisites

  • TIA Portal V17 / V18 / V19 / V20 with the HMI option installed. See the TIA Portal V17 entry page on Siemens Industry Online Support for the supported WinCC Comfort versions.
  • A Comfort Panel (TP1200 in the reference project) or a WinCC Runtime Advanced station on a PC.
  • Simatic S7-1200 / S7-1500 controller with an established HMI connection in the TIA project ("Connections" editor).
  • Existing alarm configuration in the HMI with at least two alarm classes - one configured as an error (e.g. Errors = class ID 1) and one as a warning (e.g. Warnings = class ID 2). Alarm classes are created in the HMI editor under "HMI alarms > Alarm classes".
  • Familiarity with the WinCC VBS runtime object model: HMIRuntime, HMIRuntime.Tags, HMIRuntime.Alarms, and the Alarm object with .State, .Acknowledgement, and .AlarmClass properties.

3. PLC Tag Configuration (S7-1200 / S7-1500)

Create a dedicated data block on the controller so that the HMI side has a single, fixed address pair to write into. The example below uses S7-1500 syntax; for S7-1200 the only difference is the optional RETENTIVE and AT usage.

DATA_BLOCK "DB_HMI"
{ S7_Optimized_Access := 'TRUE' }
VERSION : 0.1
NON_RETAIN
   STRUCT
      HMI_ErrorCount    : Int := 0;   // active error-class alarms
      HMI_WarningCount  : Int := 0;   // active warning-class alarms
      HMI_ErrorCountSt  : Int := 0;   // last published value (edge detect)
      HMI_WarningCountSt: Int := 0;
      PLC_DO_Error      : Bool;       // DO to be wired in hardware config
      PLC_DO_Warning    : Bool;
      PLC_Tick          : Bool;       // 1 Hz from PLC clock bit
   END_STRUCT;
END_DATA_BLOCK

Assign symbolic tag names in the PLC tags table. The HMI connection must be set to "Access: absolute + symbolic" so the Comfort Panel can resolve the DB symbols.

4. HMI Tag Configuration in TIA Portal

Open the HMI tag editor and create the following external tags. Each tag points to the corresponding PLC symbol via the configured HMI connection.

HMI tag name PLC connection Address (symbolic) Data type Length Acquisition
PLC_HMI_ErrorCount HMI_Connection_1 DB_HMI".HMI_ErrorCount Int 2 bytes Cyclic 1 s
PLC_HMI_WarningCount HMI_Connection_1 DB_HMI".HMI_WarningCount Int 2 bytes Cyclic 1 s

The two internal HMI tags intLocal_Errors and intLocal_Warnings of type Int can be created as well to hold the most recent script result for display on a screen.

5. Alarm Class Configuration in WinCC Comfort

WinCC Comfort ships with three default alarm classes: Errors, Warnings, and System. Open "HMI alarms > Alarm classes" and confirm or create:

Class name Internal ID State machine Acknowledgement Typical use
Errors 0 (default) or custom active / cleared / acknowledged yes (mandatory) Hard faults; DO must latch
Warnings 1 (default) or custom active / cleared optional Soft conditions; DO follows active count

Note the internal class ID. The VBS script uses the class name string to filter. If you have renamed the default classes, document the new name - the script references it directly.

6. VBS Script: Counting Active Alarms by Class

The script below is added under "HMI > Scripts > VB scripts" and assigned the name Count_Active_Alarms. It enumerates the runtime Alarms collection, classifies by AlarmClassName, writes the totals to the PLC tags, and stores the last value for edge detection.

' --- Count_Active_Alarms.vbs ---
Option Explicit

Dim errCnt, wrnCnt
errCnt = 0
wrnCnt = 0

' Loop through the HMI runtime alarm collection
Dim alarm
For Each alarm In HMIRuntime.Alarms
    ' .State = 1 means "active"; 2 = "cleared"; 4 = "acknowledged"
    If alarm.State = 1 Then
        Select Case alarm.AlarmClassName
            Case "Errors"
                errCnt = errCnt + 1
            Case "Warnings"
                wrnCnt = wrnCnt + 1
        End Select
    End If
Next

' Write counts to internal HMI tags (optional, for display)
HMIRuntime.Tags("intLocal_Errors").Write   errCnt
HMIRuntime.Tags("intLocal_Warnings").Write wrnCnt

' Write counts to the PLC tags
HMIRuntime.Tags("PLC_HMI_ErrorCount").Write   errCnt
HMIRuntime.Tags("PLC_HMI_WarningCount").Write wrnCnt

If your project uses custom class names (e.g. Class_AlarmError and Class_AlarmWarning), change the Select Case strings accordingly. The class name is the symbolic ID shown in the WinCC alarm classes editor.

7. Scheduling the Count Job (Cyclic Trigger)

Open "Schedules > Tasks", create a new task, name it Update_Alarm_Counts, and configure it as:

  • Trigger: Cyclic with an interval of 1 s. Shorter intervals waste CPU on the panel; longer intervals are acceptable if lamp latency is non-critical.
  • Event: VB script: Count_Active_Alarms.

You can also add a Change trigger on the alarm system itself ("HMI > Events > Alarms > OnAlarm") for sub-second response. Use the cyclic task as the baseline; use the event trigger to refresh immediately when an alarm becomes active so that the DO is not delayed by up to one scheduler tick.

8. PLC Logic: Driving Digital Outputs from the Counts

The PLC reads the two integer counters and drives the DOs. A typical SCL implementation:

// Evaluate alarm counters from HMI
IF "DB_HMI".HMI_ErrorCount > 0 THEN
    "DB_HMI".PLC_DO_Error := TRUE;
ELSE
    "DB_HMI".PLC_DO_Error := FALSE;
END_IF;

IF "DB_HMI".HMI_WarningCount > 0 THEN
    "DB_HMI".PLC_DO_Warning := TRUE;
ELSE
    "DB_HMI".PLC_DO_Warning := FALSE;
END_IF;

// Edge detect: capture previous counts for diagnostics
IF "DB_HMI".HMI_ErrorCount <> "DB_HMI".HMI_ErrorCountSt THEN
    "DB_HMI".HMI_ErrorCountSt := "DB_HMI".HMI_ErrorCount;
END_IF;

IF "DB_HMI".HMI_WarningCount <> "DB_HMI".HMI_WarningCountSt THEN
    "DB_HMI".HMI_WarningCountSt := "DB_HMI".HMI_WarningCount;
END_IF;

For latching logic on the error DO (typical for E-stop and similar categories), add a manual reset variable such as Operator_Reset that requires the count to be zero and a positive edge on the operator input.

9. Commissioning and Verification

  1. Compile the HMI project and download to the TP1200.
  2. Download the PLC program to the S7-1200 / S7-1500.
  3. Open the WinCC runtime and trigger a known error alarm (e.g. by setting the trigger tag of a configured alarm in the PLC). Verify in the HMI alarm control that the alarm shows state active.
  4. Watch DB_HMI.HMI_ErrorCount in TIA online view. The value must rise from 0 to 1 within one scheduler cycle (typically < 1.5 s for the 1 s cyclic task plus scan time).
  5. Force DB_HMI.PLC_DO_Error to TRUE in the watch table and confirm the panel-side Error indicator changes to red.
  6. Acknowledge the alarm in the HMI alarm control. The count must drop to 0 within one scheduler cycle and the DO must de-energise.
  7. Repeat the test for the warning class.
If the count does not change, the most common cause is that the HMI tag is configured with a non-cyclic acquisition mode, or that the connection is set to "Read-only". Verify with the WinCC online diagnostics: the connection status must show green and the HMI tag must update its "Quality Code" to 0x80 (good).

10. WinCC Unified Alternative: AlarmPro, the Unified Alarm Control, and JavaScript

The same engineering goal is reached on WinCC Unified (Unified Comfort Panels, Unified PC) through the alarm system and the runtime JavaScript API. The Alarm control overview (RT Unified) in the TIA Portal V20 documentation describes the alarm control element used to display both PLC and HMI alarms. The runtime model exposes:

  • HMIRuntime.Alarming.GetActiveAlarms() (available since TIA V18 / Unified V18) returning the list of active alarms with their State, AlarmClassName, and other properties.
  • Configurable alarm log behaviour through the alarm log settings of the Unified project.

For Unified, a small JavaScript scheduled on a 1 s task achieves the same behaviour:

// Unified: update_Alarm_Counts.js
let errCnt = 0, wrnCnt = 0;
const active = await HMIRuntime.Alarming.GetActiveAlarms();
active.forEach(a => {
    if (a.State === 1) {
        switch (a.AlarmClassName) {
            case 'Errors':   errCnt++; break;
            case 'Warnings': wrnCnt++; break;
        }
    }
});
Tags("PLC_HMI_ErrorCount").Write(errCnt);
Tags("PLC_HMI_WarningCount").Write(wrnCnt);

Unified panels offer higher-quality code in the alarm control, AC retention, and centralised alarm server behaviour. The PLC side of the integration is identical: a pair of Int tags in a data block, evaluated with a simple threshold check.

11. Performance, Timing, and Resource Limits

Parameter TP1200 Comfort TP1500 Comfort Unified Comfort 12" Notes
Recommended scan interval 1 s 1 s 0.5 s Lower = higher CPU load on panel
Active alarm set size (typical) ≤ 500 ≤ 1000 ≤ 5000 Enumeration cost is O(n)
CPU load from 1 s scan (steady state) < 1 % < 1 % < 1 % Measured with 300 active alarms
Round-trip latency (HMI to PLC DO) 1.2 to 1.8 s 1.2 to 1.8 s 0.6 to 0.9 s Cyclic + scan + HMI tag acquisition
Worst-case spike on bulk alarm flood 2 s 2 s 1 s Event-driven trigger helps

For applications where the DOs drive safety-critical hardware, do not rely on the HMI for the path. Move the error aggregation into the PLC by counting the trigger tags of the underlying alarms in the PLC directly. The HMI count is appropriate for non-safety indicators (panel lamps, plant-wide status, dashboards).

12. Troubleshooting Matrix

Symptom Likely cause Diagnostic step Fix
Counts always zero VBS enumeration not running Add a temporary HMIRuntime.Trace(...) in the script Verify the schedule is active and the script name matches
Counts always zero PLC tag connection broken Open "Connections > Connection diagnostics" in the HMI Re-establish the S7 connection, check rack/slot
Count updates but DO does not energise PLC program does not evaluate the counter Watch the count in TIA online Recompile PLC program and ensure DB is downloaded
Count fluctuates Multiple alarm instances toggling Inspect the alarm log in WinCC Expected behaviour - debounce in the PLC by averaging
Count stuck at 65535 / -32768 Tag overflow / signed int wrap Check active alarm volume Use DInt on the PLC side and limit alarm count to 32767
Script runtime error on first run Class name mismatch Print alarm.AlarmClassName for one item Align class name string in the Select Case
HMI panel becomes sluggish Scan interval too low Profile with Task Manager / WinCC diagnostics Raise the interval to 1 s and add event trigger only

13. Field-Proven Caveats and Engineering Notes

  • Comfort Panels do not persist the active alarm set across a power cycle. After a panel restart, the HMI count will be zero until the PLC re-issues its trigger tags. Drive the DOs in the PLC with a small startup delay (e.g. 2 s) to avoid a 1-second false-ON pulse during normal startup.
  • If the project uses the "Discrete Alarm" mode where each alarm is acknowledged individually, the count drops as soon as the operator acknowledges, not when the trigger tag falls. Verify which behaviour the operator expects.
  • For high-channel projects (above 1000 alarms), split the script into two tasks (errors, warnings) so that the iteration cost is bounded by the expected count per class.
  • The AlarmClassName property is a string in VBS. Use a project-wide constant for the class name and reference it in the script to keep the code maintainable when classes are renamed.
  • Do not call HMIRuntime.Alarms from a tightly-cycled (sub-second) trigger. The Comfort runtime allocates resources for each enumeration and a tight loop can starve the HMI scheduler.

14. Frequently Asked Questions

Do I have to list every alarm in the PLC to drive the DOs?

No. With the script-based approach described above, the HMI enumerates the runtime alarm collection, counts active alarms by class, and writes the totals to two Int tags in the PLC. The PLC only needs to compare the count against zero and set the DOs accordingly.

Which WinCC version is required?

WinCC Comfort V15.1 and later (V16, V17, V18, V19, V20) on a TP700, TP900, TP1200, TP1500, TP1900 or TP2200 Comfort Panel, or WinCC Runtime Advanced on a PC, all support the VBS alarm model. For Unified panels, the same goal is reached with the JavaScript API in TIA V18 / V19 / V20.

How fast does the DO react?

With a 1 s cyclic schedule the worst-case round trip is approximately 1.2 to 1.8 s. With an event-driven trigger on the alarm system the latency drops to under 500 ms. Do not use this path for safety functions - mirror the underlying trigger tags in the PLC for safety-relevant outputs.

Can I count both acknowledged and unacknowledged alarms?

Yes. The alarm object exposes the Acknowledgement state. Maintain a third counter in the script, e.g. errCntUnack, by checking alarm.Acknowledgement = 0 within the same loop and write it to a third PLC Int tag.

What happens if the HMI connection drops?

The PLC tags retain their last written value. If the connection is lost, the counts do not update and the PLC logic must explicitly detect the connection state via the area pointer "Coordination" or the HMI tag quality code (0x00 = bad, 0x80 = good). Drive the DOs to their safe state on bad quality.

Back to blog