I need help in how to create a function where it allows me to turn on and off a switch by means of an infrared sensor using remote control, the control will allow to control LEDs

Welcome to the forum @joan895

Please have a look at this thread from earlier today asking pretty much exactly the same question - I want to control someone else's leds using mqtt and an infrared sensor