Testing Python library


The following code interacts with a second file which controls the pinout of a Raspberry board.

For some reason, the relay I’m activating gets turned on twice when selected from the app.

I’ve a similar code running on a Arduino Yun for over a year without a problem.

I’m probably doing some wrong since this’ the first time I’m playing with the Blynk-Python lib .

Any help is appreciated.


#import libraries
import BlynkLib
from gpio import relayOn #from gpio.py script

BLYNK_AUTH = '***'

# Initialize Blynk
blynk = BlynkLib.Blynk(BLYNK_AUTH)

def my_write_handler(value):
  if value: # is the button pressed?

#start Blynk

Printout from the console…

pi@pi:~/sketches $ python3 test.py

___  __          __

/ _ )/ /_ _____ / /__
/ _ / / // / _ / '/
//_, /////_

Give Blynk a Github star! => https://github.com/vshymanskyy/blynk-library-python

TCP: Connecting to blynk-cloud.com:80
Blynk connection successful, authenticating…
Access granted, happy Blynking!

Every button press consists of two state changes… Press (ON) and Release (OFF)… thus two actions unless your code specifically looks for one or the other state.

def my_write_handler(value):
  if int(value) == 1: # The button is pressed
  else: # The button is released

@Gunner Thanks, that was the issue. I thought that if value: is equivalent to if value == True: or if value == 1.

if int(value) == 1:

worked as well if value == ‘1’: but I understand it should be an integer.