Explainer
Why Modbus alarm First Trigger misses nonzero alarm word changes
Short answer
First Trigger fires on the false-to-true transition of the Boolean condition, not on every register change. With Not Equal to 0, a 16-bit alarm word that moves from 1 to 3 is still nonzero, the condition stays true and nothing publishes. Publish on the whole-word change instead: sample the alarm word, store the previous value, and send an MQTT message whenever a new sample differs.

On this page
First Trigger acts on the false-to-true transition of its condition, and the condition Not Equal to 0 is true for every nonzero value of an alarm word. That is why a 16-bit alarm word that moves from 1 to 3 produces no message: the word is still not zero, the condition never falls, and no second trigger exists to fire. The fix is not another alarm condition. Store the last sampled word and publish to MQTT whenever a new sample differs, with the comparison running either beside the Modbus device or downstream of the broker. The examples below follow a Modbus TCP alarm word read by an industrial router and forwarded through its Data to Server feature, but the trigger semantics are identical on any platform that reduces a register to one Boolean condition.
What the First Trigger condition watches #
The Modbus Alarms feature evaluates one condition against one register and reduces it to a Boolean. With Not Equal to 0, every value from 1 through 65,535 produces the same result: true. First Trigger acts on that result rising — one action when the condition turns true, then nothing until it falls back to false and rises again. Every Trigger, the other mode selected under Action Frequency, acts while the result stays true, on its own repetition schedule.
The trigger therefore watches one bit of derived state: the word is zero or it is not. Which alarms are active lives in the 16 bits of the word, and that information never reaches the condition. A router that reads Modbus TCP and forwards telemetry with Data to Server is doing two separate jobs, acquiring values and detecting events. The acquisition side sees the word move between nonzero values; the Boolean condition on top of it does not.
Why a word that moves from 1 to 3 never publishes #
Worked example: bit 0 of a 16-bit alarm word in a holding register is alarm 1, bit 1 is alarm 2, the router samples the word through its Modbus TCP Client, and the alarm uses Not Equal to 0 with First Trigger. Trace the transitions the machine can produce:
| Word change | What happened at the machine | Condition result | First Trigger output |
|---|---|---|---|
| 0 to 1 | Alarm 1 activates | false to true | Publishes |
| 1 to 3 | Alarm 2 activates, alarm 1 still active | true to true | Nothing |
| 3 to 1 | Alarm 2 clears, alarm 1 still active | true to true | Nothing |
| 1 to 0 | The last alarm clears | true to false | Nothing; the condition rearms |
| 0 to 3 | Both alarms activate | false to true | Publishes again |
The word changed three times after the first activation and published none of them. Only the return to zero re-enables the trigger, which is why the fault hides on the bench: a test that cycles zero, nonzero, zero publishes every time, while a running line sits at a nonzero word for a whole shift while alarms toggle inside it.
The arithmetic behind the only in-router alternative: a 16-bit word has 2^16 = 65,536 possible values including zero, so covering each value with its own equality alarm means configuring and maintaining 65,536 conditions.
Why more alarm conditions do not fix it #
Every Trigger looks like the cure and is not. It acts while the condition holds, so it repeats on its schedule whether or not the register moved; in one reported setup its output cadence followed the Data to Server publication period rather than the alarm. A repeated message says the word is still nonzero and cannot say which alarms changed — the same separation of repetition from change that why an On Change tag stores the same value every second traces in tag history.
Equality alarms avoid the Boolean grouping but scale as the arithmetic above shows, and the structural reason no arrangement of whole-word conditions works is simple: one condition emits one bit of result, while the change information is spread across the 16 bits of the word. A single condition cannot express a transition between states; it needs stored state to compare against. That is the same argument the companion page on why a pick-and-place rung needs sequence state, not one condition makes for sequence logic.
Per-bit conditions are the workable middle ground when the platform can extract each alarm bit and act on its edge: 16 conditions, one per bit, each publishing on its own false-to-true or true-to-false transition. That design fits when every alarm must arrive as a separate event. It still does not produce one message describing the whole alarm set, and the consumer has to handle 16 event streams instead of one.
The stateful comparison that catches every change #
The comparator is three steps: sample the alarm word, compare it with the stored previous value, and if the two differ, publish one MQTT message carrying the new word and the previous word, then store the new value as the previous one. That is the entire event logic, and it yields exactly one message per word change, including changes between two nonzero values and changes where one alarm sets as another clears.
| Placement | What the comparator sees | What it can add | Constraint |
|---|---|---|---|
| Beside the Modbus device | Every poll cycle, read straight from the register | A snapshot of the device's other holding registers in the same message | Needs a device at the machine that speaks Modbus TCP and MQTT |
| Downstream of the broker | Only the samples the forwarding path delivers | Nothing extra; it judges the word alone | Blind to gaps in the forwarded stream; no register snapshot |
Upstream, the comparison runs on an edge PC or gateway that polls the alarm register over Modbus TCP and publishes to the broker directly. Node-RED is the usual build, and the walkthrough of MQTT to Modbus TCP with Node-RED on an edge gateway covers the client side. The message pattern is the one described in publish one MQTT event when a PLC bit rises, with a comparison of the full word standing in for a single rising edge. A fanless mini PC in the cabinet runs this poll-compare-publish loop for a whole row of devices.
Downstream, the comparison subscribes to the topic that already carries the sampled word and compares successive values. It adds no hardware at the machine, but it sees only the samples that arrive: a forwarding stage that publishes on its own period, or that drops samples across a reconnect, leaves gaps in the comparator's view of the word. It also cannot pull the device's other registers at the moment of change, because it never talks to the device.
The sampling rate sets the resolution of the comparison at either placement. A change that begins and ends between two samples is invisible to a stored-value comparison: with 2-second sampling, a word that goes 1 to 3 and back to 1 inside one window reads the same at both samples and produces no event. Sample faster than the fastest alarm sequence you must catch, and when the comparator sits downstream, remember that the forwarding period becomes the sampling period.
Test the delivery path before touching the detection logic #
Reaching the broker and detecting a change are separate faults, and the second cannot be debugged until the first is proven. Working Data to Server telemetry proves that acquisition and forwarding function; it proves nothing about the alarm action, which holds its own broker, port and topic settings.
- Install the MQTT package through System → Packages if it is absent, then open Services → MQTT.
- Enable the router's own broker on port 1883 and, for a bench test only, set Allow anonymous to On under Miscellaneous.
- Point the alarm action's MQTT output at the router's LAN address, for example 192.168.1.50, on port 1883, with keepalive 60 seconds, which is a connection-maintenance value and not a sampling or publication interval, and set a topic your test client can subscribe to.
- Subscribe with any MQTT test client before forcing the alarm input, then trigger the alarm and watch for the local message.
- Turn anonymous access back off and restore the intended authentication before the broker serves anything beyond the bench.
If the local message arrives and the external one does not, the trigger logic is innocent and the fault sits in the alarm action's external connection settings; compare them against the working Data to Server output line by line. A connection that opens but stays silent is its own failure class, and why a gateway shows a TCP connection but sends no payload walks that diagnosis for an edge gateway.
One interaction reported on this class of router is worth ruling out while you are there: with a single Modbus Alarm carrying an MQTT message action, publication failed whenever the Data to Server collection included a Modbus alarms data type, and adding a second alarm let messages through in that setup. Separate topics for the alarm stream and the telemetry stream were required as well. Treat all of it as configuration-specific to the installed firmware and verify it there; none of it changes the First Trigger semantics above.
The decision for each case #
- One message per alarm-word change, describing the current alarm set: run the previous-word comparison upstream, on a device that polls the register over Modbus TCP and publishes to the same broker as the rest of the telemetry. This is the default for packed alarm words and the only design that also snapshots the other registers at the moment of change.
- Each alarm as its own event, on a platform that extracts bits and detects edges: configure 16 conditions, one per alarm bit, each acting on its own transition, and accept 16 event streams instead of one word message.
- No extra device allowed and the word takes only a few values in practice: equality conditions per value are the only in-router option, and they stay maintainable only while the real value count stays small; a full enumeration of a 16-bit word is not a design.
- Nothing arrives at all, not even on the zero-to-nonzero transition: stop adjusting the condition and test delivery first with the router's local broker, because the alarm action's own connection settings are the usual fault.
Whichever case applies, the comparison needs the one thing the alarm engine lacks: a stored previous value. Give the loop that memory and every change in the word, including 1 to 3, publishes exactly once.
Questions asked
Why did the alarms publish during bench testing but not on the running machine?
Bench tests usually cycle the word from zero to nonzero and back to zero. Every return to zero makes the condition false again, which rearms First Trigger, so each new nonzero value publishes and the test passes. On the running machine the word often stays nonzero for a whole shift while individual alarms come and go inside it, and those are exactly the changes the condition cannot see.
What should the change message carry?
Publish the new word, the previous word and a timestamp. The consumer can then build a change mask: previous word XOR current word gives a 16-bit result in which each 1 marks a bit that toggled, and the alarm map turns that mask into exactly which alarm activated and which cleared. Adding a snapshot of the device's other holding registers in the same message gives the historian the context around the event.
What happens to the comparison after a comparator restart?
The stored previous value lives in the comparator's memory, so a restart leaves it with no baseline. Decide the startup behavior deliberately: either publish the first sample after startup as a change, which costs one spurious message after each reboot, or hold the first sample as the baseline and compare from the second. Without a deliberate choice, the default can silently skip or duplicate the first transition after every restart.
Is there a trigger type that detects the change without a separate comparator?
Some platforms offer an on-value-change or deadband trigger directly on numeric registers; where it exists, it performs the previous-value comparison internally and is the cleaner choice. The First Trigger style that acts on a Boolean condition cannot be tuned into a change detector, because its input is a single bit of derived state. Check the trigger types your alarm or tag engine documents for numeric values before building the comparison yourself.


