Home Assistant Community

How to program 433 remote using raspberry

#1

I buy four remote controls and I want to use them in my home automation. Every remote has same code for same button and i need to change that (it is possible).

This is the code that i use to get data from remote

#!/usr/bin/env python3

import argparse
import signal
import sys
import logging
import RPi.GPIO as GPIO
import time

from rpi_rf import RFDevice

rfdevice = None

# pylint: disable=unused-argument
def exithandler(signal, frame):
    rfdevice.cleanup()
    sys.exit(0)

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='Receives a decimal code via a 433/315MHz GPIO device')
parser.add_argument('-g', dest='gpio', type=int, default=4,
                    help="GPIO pin (Default: 4)")
args = parser.parse_args()

signal.signal(signal.SIGINT, exithandler)
rfdevice = RFDevice(args.gpio)
rfdevice.enable_rx()
timestamp = None
logging.info("Listening for codes on GPIO " + str(args.gpio))


GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)

pin = 17
rfdevice2 = RFDevice(pin)
rfdevice2.enable_tx()

def send(code):

    length=315
    rfdevice2.tx_code(code, 1, length)


while True:

    if rfdevice.rx_code_timestamp != timestamp:
        timestamp = rfdevice.rx_code_timestamp
        logging.info(" [code " + str(rfdevice.rx_code) +
        "  pulselength " + str(rfdevice.rx_pulselength) +
        ", protocol " + str(rfdevice.rx_proto) +
        ", length " + str(rfdevice.tx_length) + "]")
        pulse = rfdevice.rx_code
    time.sleep(0.45)
    #send(6055592)
rfdevice.cleanup()

For first button as output i can see this: [code 6792738 pulselength 315, protocol 1, length 24]

So as argument in send function i put similar number “6055592” which is random number.

The question is: Why I can’t program my remote? I can’t use random code numbers or what? I am able to copy two same remotes but not using my code. I tried to program remote by uncomment send function at the bottom.

#2

As explained here this isn’t a general home automation/tech support forum.

closed #3