Test conditions continually and switch a sensor based on the outcome

please see this info on how to format the code so that it’s readable for us to be able to help.