Motion detection during certain times not working

So you’re using Smart Lighting for this? You would need two different automations, then, one for each time period. But I’m not sure why the first one isn’t working.

The alternative would be to use core, which is a very sophisticated community created rules engine and can do pretty much anything including stacked conditionals with ors and ands and nots, so you shouldn’t have to write your own code. Very popular with power users with a technical background, Here’s the thread for that:

Meanwhile, though, I don’t see anything wrong with what you got. Are both of the devices dimmable? You might try doing it with just one dimmer switch and see if that makes a difference.