Help for subscript format

I’m new to yaml programming.
Since some of my devices are not working as a simple switch, I have to add different rule while turing on or off.
Is there any method to pass command/parameter into script to create switch-case in yaml script?
For example like what is written in the arduino :
void MyDevice1(String cmd){
if (cmd==“on”)
do somthing…
else if (cmd ==“off”)
do somthing…

Or is it possible to combine several scripts into one, For example :
Creating a script call test, which contains several different behavior.
Calling service for script.test.on / / / script.test.setscene1

Yes, you can do that with a template switch. The on and off actions can even each be a list of actions to perform, not just one.

Also it has a value template to determine the state of the switch in case its state is changed from outside home assistant, e.g. physically, some other remote control etc…

If you do not have a sensor to determine the switch state you can still use optimistic mode but the switch state in HA may become out of sync with the actual device state if it is changed in some way that does not involve using home assistant.