RF 433Mhz - Send Code Rpi-rf

Hi guys, please is there a way to insert the following script (which I currently use to send RF 433Mhz signals with a bash script from Command Shell) directly into an HG Python program?

#!/usr/bin/env python3
import argparse
import logging
from rpi_rf import RFDevice
logging.basicConfig(level=logging.INFO, datefmt=’%Y-%m-%d %H:%M:%S’,
format=’%(asctime)-15s - [%(levelname)s] %(module)s: %(message)s’,)
parser = argparse.ArgumentParser(description=‘Sends a decimal code via a 433/315MHz GPIO device’)
parser.add_argument(‘code’, metavar=‘CODE’, type=int,
help=“Decimal code to send”)
parser.add_argument(’-g’, dest=‘gpio’, type=int, default=17,
help=“GPIO pin (Default: 17)”)
parser.add_argument(’-p’, dest=‘pulselength’, type=int, default=None,
help=“Pulselength (Default: 350)”)
parser.add_argument(’-t’, dest=‘protocol’, type=int, default=None,
help=“Protocol (Default: 1)”)
args = parser.parse_args()
rfdevice = RFDevice(args.gpio)
rfdevice.enable_tx()
if args.protocol:
protocol = args.protocol
else:
protocol = “default”
if args.pulselength:
pulselength = args.pulselength
else:
pulselength = “default”
logging.info(str(args.code) +
" [protocol: " + str(protocol) +
", pulselength: " + str(pulselength) + “]”)
rfdevice.tx_code(args.code, args.protocol, args.pulselength)
rfdevice.cleanup()

From Programs select Add New Program and select Python Script. You should be able to copy/paste your code into it and save.

I’m not sure if it will affect you as your Python 3 is installed in a venv but HomeGenie is using Python 2.7.16. Just check your HG install to confirm this.

Hi Prete, thanks.
I had done this and everything seems correct, but the problem is that I don’t know how to insert the variables present in the code.
When I run the script from Command Shell I type " python3 send.py 1234567" , (when 1234567 is the RF code to send)… How could I add the option field to the program where I can insert the code?

You’ll need to define some form of startup script. Maybe if you had a look at the Email Account Program and have a look at the Start Up code section it might give you an idea how to approach this. I know it’s written in C# but the approach should be similar.