I am trying to control a LED with Blynk but it doesn't seem to work. I have checked the connections and LED with a simple blinking program, everything works. I run the blynk program, the app successfully connected and I am able to print the status of the button, however, when it comes to the if statement it doesn't work.
from gpiozero import LED
import blynklib
led = LED(17)
BLYNK_AUTH = '' #insert your Auth Token here
blynk = blynklib.Blynk(BLYNK_AUTH)
while True:
@blynk.handle_event('write V4')
def write_virtual_pin_handler(pin, value):
status = value[0]
print(status)
if status == 1:
led.on()
print("on")
elif status == 0:
led.off()
print("off")
blynk.run()
You have to convert the status
variable into an integer, since the list includes strings, not integers. In order to do this, change status
to int(status)
in the if / elif statements.