If you look at the API, the findGroup() method need a String "name value" but findLayer() need a Layer Id not the name.
Then to make it work you need this:
from qgis.core import QgsLayerTreeGroup, QgsLayerTreeLayer
root = QgsProject.instance().layerTreeRoot()
for child in root.children():
if isinstance(child, QgsLayerTreeGroup):
print ("- group: " + child.name())
elif isinstance(child, QgsLayerTreeLayer):
print ("- layer: " + child.layerId())
Move Loaded layer:
layer = QgsProject.instance().mapLayersByName(<layer_name>)[0]
root = QgsProject.instance().layerTreeRoot()
mylayer = root.findLayer(layer.id())
myClone = mylayer.clone()
parent = mylayer.parent()
group = root.findGroup(<group_name>)
group.insertChildNode(0, myClone)
parent.removeChildNode(mylayer)
Load layer in a specific group
layer = QgsVectorLayer(<layer_path>, "airports", "ogr")
QgsProject.instance().addMapLayer(layer, False)
root = QgsProject.instance().layerTreeRoot()
g = root.findGroup(<group_name>)
g.insertChildNode(0, QgsLayerTreeLayer(layer))