Consulting Insight | Liam Bee

State machines are most useful when they make behaviour easier to see, easier to support, and easier to standardise. The real challenge is not understanding the idea. It is knowing where the structure pays off and how to introduce it without making a live project harder to manage.

State machines have an odd reputation in industrial automation. Some engineers see them as something advanced that belongs in large batch systems and nowhere else. Others discover them, like how tidy the pattern feels, and start trying to wrap every control problem in a state model. Neither view is especially helpful on a real project.

The more useful question is simpler. Where does a state machine make the behaviour of the equipment clearer, and where does that clarity change the outcome of the project? That is usually the point where the conversation stops being theoretical and starts becoming valuable.

If you want the fundamentals behind state machines, I have covered that in more detail in a separate article. This piece is more about the real-world side of it.

  • Where state machines pay off.
  • How they fit into brownfield projects.
  • Why the teams that get the best results usually treat them as part of a wider programming standard rather than a neat coding trick.

From a consultancy point of view, the interesting part is rarely the syntax. Most engineers can understand the concept of states, transitions, and fault paths quickly enough. The harder part is deciding where to apply that structure, how to standardise it across a team, and how to migrate toward it without turning a perfectly functional but untidy asset into a risky rewrite.

Structuring A State Machine

A state machine is not really about elegance. It is about ownership. It gives the behaviour of an asset or sequence a place to live. Instead of letting behaviour emerge from scattered flags, timers, and permissive chains, it defines what the equipment is doing, what can move it forward, and what should happen when something goes wrong.

That matters most when the equipment has phases, travel time, confirmation feedback, abnormal recovery, or multiple modes of operation. The moment there is a meaningful difference between being told to do something and actually having done it, you are already dealing with behaviour that benefits from structure. A valve that has been commanded open is not the same thing as a valve that is open. A pump that has received a start command is not the same thing as a pump that has reached running confirmation. A sequence that has paused waiting for operator confirmation is not the same thing as a sequence that is idle.

That does not mean every rung of logic needs to become a state machine. Plenty of control problems are still best served by direct logic. Simple combinational behaviour, basic interlocks, and straightforward output conditions do not suddenly become better because they have been wrapped in a formal state model. The value appears when the structure helps people understand what the software believes is happening.

That last point is the one I think gets missed most often. State machines are useful because they make intent visible. On a live system, visibility is worth a lot. It shortens troubleshooting. It improves handover. It makes HMI status more meaningful. It helps different engineers work on the same project without constantly stepping into each other’s assumptions.

Where State Machines Pay Off

The first place they pay off is on assets with physical movement and feedback. Pumps, valves, dampers, conveyors, drives, lift stations, and duty-standby changeovers all live in the gap between command and confirmation. That gap is exactly where ad hoc logic gets messy. If the software treats command and result as the same thing, the diagnostics become vague and the abnormal paths become hard to reason about. State machines handle that well because they preserve the journey, not just the destination.

The second place is on process sequences that have to deal with pauses, retries, resets, or alternate recovery paths. This is where a lot of otherwise functional code becomes frustrating to commission. The sequence works until it gets interrupted halfway through, or it faults on a timeout, or the operator wants to restart from a sensible point rather than from the very beginning. Those are the places where hidden state starts costing real time.

The third place is on repeated asset types. One pump block can be messy and still survive. Twenty pumps across a site, all behaving slightly differently because they were copied, adjusted, and patched over time, create a completely different problem. Once an asset type is repeated, state machines start paying off as a standard rather than just as an implementation detail. HMI faceplates become easier to template. Fault handling becomes more predictable. Support becomes faster because engineers stop having to learn the same asset again and again in slightly different forms.

The fourth place is at the boundary between disciplines. A good state model gives PLC engineers, SCADA developers, process engineers, and maintenance staff a shared description of what the equipment is doing. Instead of relying on a collection of low-level signals and expecting everyone else to infer the behaviour, the software can present the behaviour directly. That is useful technically, but it is also useful organisationally. It reduces the amount of interpretation the team has to do every time something behaves unexpectedly.

Whenever I have seen state machines create real value, it has usually been in one of those four areas. Not because the code became more advanced, but because the project became easier to understand.

Where They Make Things Clearer

I would be careful about framing state machines as something that only appears once a project has crossed some invisible maturity line. Plenty of systems work for years without formal state structure. The better way to think about it is this: where would clearer behavioural ownership remove confusion, variation, or support overhead?

One common sign is when HMI status is assembled from several booleans and the operator is expected to interpret them. Another is when support conversations keep starting with the same question: what is it trying to do right now? A third is when similar assets all have slightly different behaviour and nobody is fully sure whether those differences were deliberate. A fourth is when the existing code already contains an obvious hidden state model, just encoded as a web of latches, timers, acknowledgements, and conditional branches.

None of those situations mean the original engineer got it wrong. They usually mean the project grew. Behaviour that was once easy to hold in your head stopped being easy to hold in your head. State machines are often the moment where that behaviour gets surfaced and owned properly.

A useful way to assess this on a live project is to ask three simple questions.

  • What state is the equipment in now?
  • What condition is it waiting on next?
  • What path should it follow if that condition never arrives?

If those answers are difficult to extract quickly, clearer state structure is often worth considering.

That is why I like to frame the decision around clarity rather than complexity. The goal is not to make the code look more professional. The goal is to reduce the amount of guesswork involved in reading, modifying, supporting, and explaining it.

Migrating To State Machines To Future Proof Your Asset

The wrong migration strategy is to decide that state machines are a better pattern and then try to rebuild everything around that conclusion. Brownfield projects rarely reward ideological rewrites. The better approach is to choose the asset or sequence that keeps creating friction, understand the behaviour it already contains, and introduce structure there first.

In practice, that usually means starting with an asset type rather than a whole plant. A pump family. A valve template. A recurring sequence module. Something repeated enough to matter, but contained enough to prove safely. The reason I prefer that approach is simple. It lets the team learn what a good state interface should look like before trying to standardise it more widely.

The most valuable work often happens before the code changes. Map the current behaviour. Write down the actual states the asset already moves through. Decide what belongs inside the asset and what belongs outside it. Be clear about the interface. Commands should come in. Status should go out. Fault ownership should be defined. What you are really future-proofing is not the CASE statement itself. You are future-proofing the boundary between the asset and the rest of the project.

That boundary is where many migrations fail. External logic still reaches into the asset and manipulates internal behaviour directly. Site-specific logic gets buried inside a supposedly reusable block. Different engineers expose different status fields because nobody agreed what the standard was. The result is a state machine in appearance but not in practice. It looks structured when you open the block, but the project around it still behaves in an ad hoc way.

Future proofing really comes from consistency. A standard command model. A standard status model. A predictable fault path. Clear ownership between sequence behaviour and equipment behaviour. Once those things are in place, the asset becomes easier to reuse, easier to test, and easier to extend. That is what makes the migration worthwhile.

If you are choosing a first migration candidate, look for three things.

  • Repetition.
  • Clear physical feedback.
  • Recurring support pain.

That combination tends to give the fastest return and the clearest signal that the structure is helping.

Using State Machines Consistently Across A Team

Once more than one engineer is involved, the question changes. It is no longer just whether a state machine is a good idea for one block. It becomes whether the team is using the pattern consistently enough for everybody else to benefit from it.

This is where state machines stop being a local design choice and start becoming a standard. The asset block should own its internal states, transitions, and fault response. The calling sequence should command the asset and consume status, not reach through the interface and drive internals directly. The HMI should display state and diagnostics from known fields rather than having to reconstruct the behaviour from scattered tags. Maintenance staff should know where to look when they want to understand what the software thinks is happening.

Consistency matters in smaller ways too. Whether you separate commanded and actual state. Whether fault states sit in a recognisable range. Whether availability and readiness are exposed consistently. Whether the text shown on the HMI follows the same pattern across all instances. None of those choices are especially difficult on their own, but together they determine whether the state-machine approach actually reduces cognitive load for the wider team.

The other thing that matters is not letting the pattern become too clever. The best industrial state machines are usually readable, boring, and predictable. They prioritise clear behaviour over elegant abstraction. That is especially important when a project will be maintained by people who did not design the architecture in the first place.

This is also the point where supporting material becomes part of the standard. Alarm text, faceplates, commissioning sheets, state diagrams, test cases, and design notes all matter. Those pieces are what carry the clarity out of the PLC editor and into the rest of the project lifecycle.

Where The Payback Shows Up

One reason teams hesitate over state machines is that the first implementation can feel more verbose than the logic it replaces. That is often true. A proper state model asks you to be explicit about behaviour that ad hoc logic was leaving implicit. In the short term, that can look like extra work.

The payback usually shows up later, and it shows up in the places that cost the most. Support gets faster because the software tells you what it thinks it is doing. Commissioning gets more structured because you can test state by state and transition by transition instead of waiting for the right combination of signals to appear. Handover improves because the maintenance team can understand the asset’s behaviour without reading every rung of the surrounding logic. New engineers become productive more quickly because they inherit a pattern instead of a collection of exceptions.

There is also a quieter payoff in project confidence. Teams are more willing to change assets that have visible behaviour and clear ownership. They are more hesitant around logic that technically works but cannot be explained quickly. That difference matters. A lot of automation debt survives not because it is impossible to improve, but because the current structure makes safe modification feel too risky.

That is why I tend to judge state-machine work over the lifetime of the asset, not the size of the first code block. If the structure makes the project easier to support, easier to extend, and easier to standardise, it has probably earned its place.

Why Use External Help?

By the time teams reach this point, the obstacle is usually not whether they understand the idea of a state machine. The obstacle is deciding how far to take it, where to start, what standard to settle on, and how to migrate without destabilising the parts of the plant that are already working.

That is where external input can be useful. Not because the internal team lacks capability, but because architecture decisions are easier to assess when you are not buried in the history of the codebase. An outside view can see where behaviour is leaking across boundaries, where supposedly reusable assets have become too site-specific, and where a team is about to over-engineer a pattern that would be more powerful if it were simpler.

It also helps when the wider project has to keep moving. Brownfield changes are rarely made in isolation. There are commissioning pressures, production windows, site constraints, and team capability considerations all happening at the same time. Good judgement here is less about drawing a perfect diagram and more about choosing the next sensible step.

If you are thinking about tightening up state-machine use across a project, I would start with one asset type, one recurring source of friction, and one interface boundary that can be improved properly. That is usually enough to show whether the approach is going to strengthen the wider system or just add ceremony.

Free 30-Min Call

Book A General Discussion

If your current project has reached the point where the challenge is less about writing logic and more about deciding how it should be structured, you can book a general discussion below and talk it through properly.

This is a 30-minute call to talk through your project, your current situation, and the most sensible next step.

Technical Services

Explore Technical Services

If the bigger issue is architecture, documentation, troubleshooting, or team capability, the technical services page gives a better picture of the kinds of support these projects often turn into once the structure needs tightening up.

View Technical Services

Leave a Reply