You can definitely put relays for controlling lights in a light fixture, that’s quite common.
As you discovered however fans are something else. You need a specific device intended for control of a fan motor. So it’s not just the wiring, it’s the device itself.
Fortunately, there is one which works well with SmartThings and is quite popular. See the following thread (this is a clickable link) . You can ask any follow-up questions there.