There's a few key things about playing Zenyatta:
1) Stay out of the fray. You have great range on all your Orb abilities (Harmony, Discord, and Destruction), and are very fragile. Keep near cover as much as possible, and get to it as soon as you're taking damage - you have no self heal save for your Ultimate, but do have shields which can regenerate two thirds of your maximum health. At the same time, try not to get too far from the team, lest you become easy prey for flankers like Tracer or Genji.
2) You should be aiming towards 100 percent uptime on your Orb of Harmony - if everyone is at full health, throw it on whoever is likely to take the most damage first when the fight happens. Your Orb of Discord should be up as much as possible, as it offers a large damage boost, but don't be afraid to be selfish with it - in almost all cases, it is better to throw it on someone that is trying to kill you, in order to drop them first. If noone is trying to kill you, then it should be on either your own target or the team's priority target (many characters in their ultimate, specific characters that need to be dropped for a push to work, or what have you - this is some tactical judgement you need to develop to get the best use of this ability). Be aware that abilities like Reaper's Wraith Form, Tracer's Recall, and Mei's Ice Block can clear off the Orb of Discord.
3) Manage everyone's health, and be as proactive as you can. Pocket Zenyatta is not a good plan; try to keep everyone in decent health, and make sure to Orb allies in Critical state so that they can heal up if they grab cover for a few seconds. This also helps charge your ultimate very fast.
4) Your attack is quite effective when combined with your Orb of Discord. A fully charged alt-fire on a Discorded Bastion is a kill if all five orbs hit. The charge attack is good if you're ducking in and out of cover, or waiting out an opponent's ability duration, but otherwise stick to the primary fire. Precision is rewarded here, so aim for the head.
5) Your ultimate is very powerful, but does not "block" an enemy ultimate. Rather, it heals through anything less than a single hit that removes a character's entire health pool. Thus, this protects your team from abilities like Death Blossom and Rocket Barrage (because you out-heal the damage), but not things like RIP-Tire or Self Destruct. Alternatively, you can turn a fight around by using it when your team is at low health, or to drive a push through, or to help remove an especially sticky Bastion or Turret... It's extremely flexible, but more importantly it charges fast, so you can be relatively liberal in using it.
6) Remember that you are the most fragile character in the game; even Tracer is harder to kill. Wherever possible, keep to cover and poke in and out to refresh your line of sight for your orbs. Engaging weaker characters or close quarters characters from range can be effective as well.