The IEEE 802.11ah standard is intended to adapt the specifications of IEEE 802.11 to the Internet of Things (IoT) scenario. One of the main features of IEEE 802.11ah consists of the Restricted Access Window (RAW) mechanism, designed for scheduling transmissions of groups of stations within certain periods of time or windows. With an appropriate configuration, the RAW feature reduces contention and improves energy efficiency. However, the standard specification does not provide mechanisms for the optimal setting of RAW parameters. In this way, this paper presents a grouping strategy based on a genetic algorithm (GA) for IEEE 802.11ah networks operating under the RAW mechanism and considering heterogeneous stations, that is, stations using different modulation and coding schemes (MCS). We define a fitness function from the combination of the predicted system throughput and fairness, and provide the tuning of the GA parameters to obtain the best result in a short time. The paper also includes a comparison of different alternatives with regard to the stages of the GA, i.e., parent selection, crossover, and mutation methods. As a proof of concept, the proposed GA-based RAW grouping is tested on a more constrained device, a Raspberry Pi 3B+, where the grouping method converges in around 5 s. The evaluation concludes with a comparison of the GA-based grouping strategy with other grouping approaches, thus showing that the proposed mechanism provides a good trade-off between throughput and fairness performance.