In the Dungeon Master's Guide (pp. 267-268), there are rules for firearms, including future items (e.g., laser pistol, antimatter rifle and a laser rifle, along with modern weapons). Also explosives, including grenades. There are also rules on 'alien technology' in the DMG (pg 268) which is rules for a character figuring out how to use technology works.
For most technology (magi-tech or otherwise), I would use these rules and simply treat it as a magic item with similar properties. Jet pack is a broom of flying, a computer is a scroll of some divination spell (with recharging charges) and a hovercraft is an airship or flying carpet, etc., perhaps with limited charges.
Since the DMG also features guidelines on making spells, you can make up an ability with those guidelines and treat items as either scrolls or wands to simulate technology.
You're trying to set a tone. This is an abstract quality that will inform and emerge from your game. To shape how it goes, you'll need to keep your desired tone in mind during preparation and play, and identify specifics that will help guide you.
Gritty Drama vs. Lighthearted Adventure
You're used to grit. Let's define some of the qualities that comprise it, so you can see more objectively what creates this atmosphere:
- Dramatic setbacks & character flaws are part of what makes a compelling story
- The protagonists are "regular" people. They are made exceptional because the narrative is about them. Even if they are exceptional within the setting, their flaws and humanity are important.
- Getting by in the world is challenging. Simply holding one's ground can sometimes be considered a victory.
- Risks are serious. Whether you are wounded in a fight or mocked before your peers, there will be consequences that matter.
- Happy endings aren't a guarantee. Tragedies and downwards spirals are compelling gritty stories.
- Life isn't fair and good doesn't always prevail.
- "Good" and "evil" can get murky, and most people and situations are shades of grey.
- Narration includes realistic details and nuances.
Gritty stories are at least as dark, miserable, and challenging - often more so - than the reality we are used to. We can relate to the adversity, and even take comfort that our own world isn't any worse. Empathizing with the characters' struggles is a central appeal; one which is enhanced by maintaining a sense of realism.
By contrast:
Lighthearted adventure stories are about empowerment and escapism. The best of them also highlight the value of virtue, giving the audience inspiration we can carry into our own lives. Notable qualities:
- Dramatic victories achieved with flourish are part of what makes a compelling story
- The protagonists are exceptional. Through some combination of skill, luck and virtue they stand out and get things done.
- Risks are exciting. The heroes win more than they lose. When setbacks happen, it's possible to recover, and often to turn the setback into an advantage.*
- Endings are happy. In the rare event that a main character dies, they hailed for their sacrifice by the survivors, and their accomplishments are always large.
- Life might be full of danger, but virtue will ultimately prevail. Honesty, bravery, kindness and cleverness will defeat selfishness, cruelty, and ignorance.
- Characters, while still ideally having some depth, are more likely to play directly towards or against tropes.
- Narration includes larger-than-life action and details that are stylized and exciting.
*Example: A hero is kidnapped by bad guys and locked in a dungeon. After escaping their cell, the hero is now in the bad guys' lair and ready to some serious damage.
How the magic happens
As you can see, this is a style that deliberately uses less realism. This is where the room for comedy comes in. Comedy is how we respond to the absurdity of a situation. In a gritty story, one is often too immersed in the drama to laugh much. In a less realistic story you are just enough removed that it's easier to laugh. Also, the lack of realism fosters more absurd situations, so funny things happen more. Don't worry about forcing comedy. It's a spontaneous quality of the genre.
Best Answer
I learned most of my lessons on this topic from action and drama films.
I've found that one of the best ways to introduce comic relief in an otherwise tense campaign is to introduce sometimes hilarious events into combat descriptions. For example, let's say one of your party member's gets a critical success on his attack roll and obliterates an enemy. All it takes to add some comic relief then is to throw something like "The guard gives a confused look as the railgun shell comes barreling towards him" or "A growing wet spot appears on his pants as he watches the fireball come closer" to introduce a moment of lessened tension. I particularly like this kind of technique because it doesn't ever distract or detract from the overall mood of the campaign or setting, since combat tends to be a gruesome and serious subject by its nature (and players sense this).
Another great way that I really like is dropping quick one-liners in a tense situation. For example, in a campaign I ran once, my party acquired a spaceship piloted by an NPC. At one point there was some on-board combat, and the party's heavy weapons expert critically failed, making a massive hole in the hull (luckily, they hadn't yet exited the upper atmosphere). The pilot NPC gave the PC an incredulous look and started a slow clap for him, saying, "Way to go, Jim. Way to go." It was a moment of hilarity amidst an otherwise very grim situation, and again, it only added value to the session and atmosphere.
I think there are two keys to successful comedic relief:
If you force it, the players will sense it, and it will just be awkward and break the mood (which is exactly what you don't want). Also, if you extend the comedy for too long, it takes over the scenario and your campaign suddenly becomes a silly comedy of errors rather than a drama or action-adventure or whatever else.
Basically, small quips inserted artfully are the key to success.