Your topic has been moved to a more suitable location on the forum. Installation and Troubleshooting is not for problems with (nor for advice on) your project
See About the Installation & Troubleshooting category.
Your description mentions one sensor, your code uses two sensors; maybe a better description is in place explaining the second sensor.