Heh, "Motivate", sounds mostly impossible. At least with some subjects. But maybe there could be some improvements. Here's some of my dumb and likely useless thoughts:
If it's in your competence, allow phones during breaks. I believe that could make classes without them much easier.
Fresh air: Helps alot. I don't know why some teachers absolutely hate open windows. All you can do on those classes is try to not fall asleep with your heart pounding.
Allow water during classes: Similar to above, dehydration helps no one.
Engage with students: Try to have conversations with them, give them questions, let them give questions to you (on topic). I've had a few teachers that would just do 45 minute monotone monologues.
If possible, give some demonstration or real life use examples. This works well especially with chemistry and physics.
Positive and negative points: For example, 5 pluses may be A, and 5 minuses F. I prefer the system where pluses and minuses null out each other, otherwise a plus may make your grades worse, leading to lack of activity. Someone not paying attention or not knowing answer to questions, minus. Someone being positively active during classes, answering questions, plus. You can decide what makes plus and what minus and how many are needed for the grade.
Quick activities (like optional tests): Math teachers did this since elementary school. Teachers would give a math problem and some time to solve it. First x students to solve it correctly got a good grade, others could get pluses. For example, first 3 students to solve a math problem within 15 minutes get A, the next students get a plus. Those who did nothing get nothing. Like a small optional exam. It makes it worth being prepared. Just don't make the window too small, like "First student to solve this within 5 minutes gets A, next ones get nothing", because most will just give up.
Announce exams in advance: This gives students time to study before each exam. The likelihood that someone will study AFTER a surprise exam is quite low.
Give option to re-do an exam: Got a bad grade? Don't give up yet. Put in some more effort to get a better grade. I've seen different approaches on this. Sometimes it would replace previous grade, sometimes you'd just get another. Sometimes unconditionally, sometimes only if it's better. I'd choose a second grade conditionally. If it replaced the grade, you wouldn't see as many studying for first exam, relying on "fixing it later". Conditionally because if there's a chance of getting worse grade, I may just as well not try, just in case.
Movies or shows: Applies to foreign language classes. If it catches their interest, they may not even realize they're learning. You could occasionally do that as a reward. Reward = motivation. Tip: Subtitles may be helpful. The problem with this is finding something universally interesting.
Try to not treat the whole class as 1 person: Punishing whole class for actions of 1 student will make YOU more disliked than that student.
Respect: I don't know how you could do this. But some teachers may gain respect among students. I believe this is more valuable than using power. But again, no idea what you could do for that.
Outside?: My middle school geography teacher did her classes outside during summer. Nothing changed about those classes, it was just outside. Better environment.
Minimize homework: Homework is one good way to absolutely hate a subject. This could be partially replaced with optional projects. If it's optional, it doesn't feel as bad anymore.
Ask students for feedback: There's a small chance you may get some useful answers.
But you probably can't do much past trying to be nice. Biggest problem is the extra unnecessary information being taught, but if you can't determine what precisely will be useful in the future, you can't know what to omit. Missing knowledge is probably worse.