You have lots of wonderful colors of wires, which means you have conduit. (Or should - if these are loose wires in the wall then you've got big problems.) That's the good news, because it means you can add wires as needed to solve problems. There are no ground wires, so that would indicate metal boxes and conduits. On the other hand, very little metal is exposed - it looks like the box has been sprayed with concrete...not good.
The bad news is that we have no idea what each wire currently means.
Assuming things were done properly, the white wires are neutral. That would seem to indicate:
one of these is incoming power and the other is light/fan. But that is a bit unusual. Typical is two wires for incoming power/neutral and three wires for outgoing switched power (one light, one fan) and neutral. Clearly that is not the case here. Except for the white wires (both neutral) we need to figure out what each wire does in order to continue. Some possibilities include:
- Incoming hot - logically that would be black and really should be either yellow or black since they are connected to the switch, but could be any color here except white. Easiest way to find out is to turn off the power, disconnect (but tag so we know what goes where) all the non-white wires in the two sets (black, red x2, yellow) and turn on the power and see which wire is hot with a non-contact voltage tester (NCVT) and verify with a multimeter. Could even be multiple colors (but shouldn't be).
- Switched hot - must be either black or yellow. Whichever one is not always hot.
- Passing through additional switched hot - e.g., if yellow goes up to light and then comes back as red and on to a separate fan, or something like that. Not likely, but technically possible.
- Passing through addition always hot - again, not likely (because not needed just split the hot where needed) but possible.
- Something else???
The diagram with the new switch is based on the most common "good" situation (there are some older configurations where it just won't work without new wires). In this particular case, the most that should be needed is running one additional wire through conduit, but even that might not be needed. We just don't know yet.