This functionality is probably the single biggest gap in OpenWrt and LEDE and one of the reasons I think the GLI GUI is so great.

By no means am I trying to discourage you from this pursuit, but there are a hand full of these out there including one I have made some mods to: 404 Page not found - GL.iNet and this one from Dirk Benson which I am currently testing: OpenWrt Forum Archive

Hopefully there is something you can learn from the code in these.

I will suggest you try to avoid expecting the STAtion to be either the [0] or[1] specifically. If someone uses Luci, it’s easy to wipe the entries and the STAtion can be [0]. The little check box at the top of Luci’s “Join Network” page which says “Replace Wireless Config” can mess up the works if not set correctly.

What I consider the big gap in every solution so far is the inability to add a STAtions to a library from the GUI.

Probably worth noting where the list is stored (etc\config?) and the correct format for manually adding some STAtions.