Home semi-auto function

That’s because your code that turns the relay on/off (case 1: and case 2:) don’t include any blynk.virtualWrite(vpin,value) commands to update the switch widget to reflect the state of the relay.

For the relay to ignore the off command (the case 2: option in relayOnOff() you need to add an additional “flag” variable which is checked before turning the relay off in case 2:
You could use a boolean variable type for this, and set it to true whe you turn the light on with the button widget and false when turned off with the button widget.

Also, you should remove the

call from your void loop and instead call it with a BlynkTimer.

This topic covers BlynkTimers:

and the section called " Overriding a Timer (auto/manual mode)" explains a little more about how to use a flag variable to override the PIR sensor.

Pete.

1 Like