Your original automation is triggered every minute. So it turns on the switch at the desired time and turns it off for every other time. That means the switch is turned on for just one minute and then turned off. Is that how you want it to work?
An input_datetime only stores the time. How do you plan to tell the automation that the switch should be turned on or off at the specified time?
Why check every second if the time you’re specifying is in hours and minutes?
sensor.time changes every minute. That’s adequate for most scheduling applications.