# MQTT - Single button press - multiple different actions (in order/sequence)

**URL:** https://discourse.nodered.org/t/mqtt-single-button-press-multiple-different-actions-in-order-sequence/50125
**Category:** General
**Created:** [24 August 2021 17:21 UTC](https://discourse.nodered.org/t/mqtt-single-button-press-multiple-different-actions-in-order-sequence/50125 "2021-08-24T17:21:46Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [24 August 2021 17:36 UTC](https://discourse.nodered.org/t/mqtt-single-button-press-multiple-different-actions-in-order-sequence/50125/2 "2021-08-24T17:36:21Z")

</div>

You need to remember last state. for this there are several solutions. The easiest (for me) is a function node...

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/a/ca0179fac3783b8c55c946bc0fc4a1abd461c87b.png)

```auto
[{"id":"75f941daf629c2ba","type":"inject","z":"219b0be6.926804","name":"fake button","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":1570,"y":320,"wires":[["bcc8bbbf106ec10f"]]},{"id":"bcc8bbbf106ec10f","type":"function","z":"219b0be6.926804","name":"colour cycle","func":"/ ****colour list - update as required***** /\nconst colours = [\n \"red\", \n \"blue\", \n \"green\",\n];\n\n/ ****dont change***** /\nlet colour = context.get(\"colour\"); //restore last colour\ncolour = colour == null ? 0 : colour + 1;//inc colour\nif(colour >= colours.length) {\n colour = 0;\n}\nmsg.payload = colours[colour];\ncontext.set(\"colour\", colour); //store last colour\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1730,"y":320,"wires":[["fc3d23dad0eccca5"]]},{"id":"fc3d23dad0eccca5","type":"debug","z":"219b0be6.926804","name":"","active":false,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":1750,"y":360,"wires":[]}]

```

↑ Flow to import (CTRL+I)

PS, as a new user, I recommend watching this playlist: [Node-RED Essentials](https://www.youtube.com/playlist?list=PLyNBB9VCLmo1hyO-4fIZ08gqFcXBkHy-6). The videos are done by the developers of node-red. They're nice & short and to the point. You will understand a whole lot more in about 1 hour. A small investment for a lot of gain.

---

_[View the full topic](https://discourse.nodered.org/t/mqtt-single-button-press-multiple-different-actions-in-order-sequence/50125)._
