I need to find a layer in the TOC and get its position (which can vary) so that I can add a group after that layer. I can get the layer I want to reference easily enough:
root = QgsProject.instance().layerTreeRoot()
last_layer = QgsProject.instance().mapLayersByName('next_ids')[0]
What I want to do is add group after that layer:
lyr_pos = [index in TOC of last_layer] # This is what I need to get
self.err_group = root.insertGroup(lyr_pos + 1, GROUP_NAME)