Hello. Everything is working. But what is missing is the ability to block the light from turning off if some condition does not match the value 'on', for example, input_boolean.autoswitch_off_light. That is, so that the light turns on in normal mode, but does not turn off if {input_boolean.autoswitch_off_light} is on, as when working with stay_mode. Perhaps it is worth refining this function so that it is possible not only to specify 'stay_mode: on', but to check the state of some entity, similar to:
stay_mode: input_boolean.autoswitch_off_light
Then the light will be turned on, but you will need to turn it off either manually or by changing the stay_mode state.