# Finite state machine logic

**URL:** https://forums.losant.com/t/finite-state-machine-logic/2164
**Category:** Feature Request
**Tags:** workflow
**Created:** [September 3, 2019, 11:40pm UTC](https://forums.losant.com/t/finite-state-machine-logic/2164 "2019-09-03T23:40:17Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![paul\_wareham](https://avatars.discourse-cdn.com/v4/letter/p/ed8c4c/32.png) [@paul\_wareham](https://forums.losant.com/u/paul_wareham)
#### Post date: [September 3, 2019, 11:40pm UTC](https://forums.losant.com/t/finite-state-machine-logic/2164/1 "2019-09-03T23:40:17Z")

</div>

I was curious whether anyone has used workflows to mirror the behaviour of a finite state machine for doing basic control logic at the edge?

I was thinking the Switch and Conditional nodes could be used but I’m wondering if anyone has experimented with mapping an FSM to a Losant workflow?

---

<div class="post-metadata">

### Author: ![Kevin\_Niemiller](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/kevin_niemiller/32/745_2.png) [@Kevin\_Niemiller](https://forums.losant.com/u/Kevin_Niemiller)
#### Post date: [September 4, 2019, 2:00pm UTC](https://forums.losant.com/t/finite-state-machine-logic/2164/2 "2019-09-04T14:00:09Z")

</div>

Paul,

I have not tried implementing a finite state machine into a workflow and not sure if someone has tried this yet. Maybe\Hopefully someone in the forums will respond with an implementation that they have done.

Like you said, I think it is possible and I would anticipate that you would be using the [Switch Node](https://docs.losant.com/workflows/logic/switch/) and [Conditional Node](https://docs.losant.com/workflows/logic/conditional/) like you mentioned.

Let us know how your implementation goes if you choose to implement a finite state machine in a workflow.

Thank you Paul,  
Kevin

---

<div class="post-metadata">

### Author: ![paul\_wareham](https://avatars.discourse-cdn.com/v4/letter/p/ed8c4c/32.png) [@paul\_wareham](https://forums.losant.com/u/paul_wareham)
#### Post date: [September 4, 2019, 2:16pm UTC](https://forums.losant.com/t/finite-state-machine-logic/2164/4 "2019-09-04T14:16:36Z")

</div>

Thanks @Kevin_Niemiller

Folks using node-red have apparently created FSM nodes using a rather popular [JavaScript State Machine](https://www.npmjs.com/package/javascript-state-machine) library.

That would be interesting in Losant 🙂

---

<div class="post-metadata">

### Author: ![Kevin\_Niemiller](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/kevin_niemiller/32/745_2.png) [@Kevin\_Niemiller](https://forums.losant.com/u/Kevin_Niemiller)
#### Post date: [September 4, 2019, 2:47pm UTC](https://forums.losant.com/t/finite-state-machine-logic/2164/5 "2019-09-04T14:47:06Z")

</div>

Paul,

Thank you for the link - I will definitely check it out!

-Kevin

---

<div class="post-metadata">

### Author: ![Gambit\_Support](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/gambit_support/32/826_2.png) [@Gambit\_Support](https://forums.losant.com/u/Gambit_Support)
#### Post date: [September 4, 2019, 4:06pm UTC](https://forums.losant.com/t/finite-state-machine-logic/2164/6 "2019-09-04T16:06:23Z")

</div>

Have not implemented a FSM. Our “control system demo” uses essentially an if-elseif-else  
logic as detailed at

> **[Emergency Shutoff scenario: Losant IoT Platform](http://gambitcomm.blogspot.com/2018/12/emergency-shutoff-scenario-losant-iot.html)**
>
> In previous posts we examined how different platforms, such as Losant ,  Samsung Artik ,  IBM Watson ,  allow implementing a real-time, dy...

---

<div class="post-metadata">

### Author: ![Tim\_Hoffman1](https://avatars.discourse-cdn.com/v4/letter/t/87869e/32.png) [@Tim\_Hoffman1](https://forums.losant.com/u/Tim_Hoffman1)
#### Post date: [September 7, 2019, 4:04am UTC](https://forums.losant.com/t/finite-state-machine-logic/2164/10 "2019-09-07T04:04:57Z")

</div>

I have been effectively creating a FSM using switches, and local storage. Not for control but determining state for alarms.

We have a number of mechanical devices that get start signals but are not considered running until feedback is provided and this can take some time.

We need to be able to record fail to start, starting running.

So the workflow is triggered each event, and the state progresses based on time and inbound events and previous state.

It seems to work fine.

T
