In this paper, we propose a non-orthogonal multiple access (NOMA) based grouping method for IEEE 802.11ah, a promising platform for the internet of things (IoT). The grouping method improves the scalability of IoT networks, by reducing collisions in the access points (APs). The proposed method puts those IoT devices (IoT-Ds) whose channel gains are far enough from each other, i.e., who satisfy NOMA constraints, in the same group. Therefore, using successive interference cancellation (SIC), the AP is able to decode the simultaneous signal transmissions from IoT-Ds in a group. To assign IoT-Ds into groups and determine their transmission power, we formulate a total throughput maximization problem as a joint optimal grouping and power allocation problem, which is a non-convex mixed-integer programming problem. We convert it to a convex problem using quadratic fractional programming (QFP), and then we solve it using augmented Lagrange multiplier (ALM) method. Moreover, to reduce the complexity of the solution, we propose a fast grouping method to allocate power to each group in parallel. Simulation results show that the proposed methods have outstanding performance compared to conventional association identifier (AID)-based grouping method; besides, scalability of the network in terms of throughput, power consumption and channel utilization improves dramatically because of the collision reduction of IoT-Ds, which is achieved by deploying NOMA and SIC. Furthermore, the fast grouping method decreases the computational complexity greatly at the expense of a small reduction in network performance.