Unifi Switch, dynamic VLAN on a port

I have a homelab with three VLANs.
The firewall (opnsense) is connected to a Unifi USW8-60W. That switch is connected to another USW8-60W upstairs where I connect several different systems (including some untrusted stuff like smart TVs and some IOT things)
Right now I have set port profiles on the switch upstairs so different ports carries different VLANs.

Is it possible to automate this somehow? So if say I connect device A to a port, that port will only deliver VLAN X untagged. If I instead connect device B to that same port, VLAN Y untagged will be delivered through that port.

From what I understand, I need to set up a radius server to accomplish this. Is that correct?
And further, is it possible to accomplish this with my USW8-60W ?

I’ve not been the one configuring it, but we use FreeRadius for this at work. From the datasheet, the USW8 seems to support Radius authentication.

From a quick search I found this German post explaining how to set it up with the internal Radius server of the Unifi controller. Since it’s likely not of much use to the members of this forum, the trick is to set both the username and password to the device’s MAC address when adding Radius users in the controller.

Not something that I have tested but it can be done with FreeRadius and UniFi switches.