Skip to content

Wireless Remote

mguinness edited this page Oct 13, 2020 · 2 revisions

Introduction

There are several cheap radio frequency (RF) controlled outlets using the 433MHz frequency with a range of up to 50 feet. If you search for Etekcity, Dewenwils & BN-LINK you'll find many wireless controlled outlets with remote controls for either 1, 3 or 5 devices. The remotes themselves can be found for around $10 and are ideal for this purpose as long as they use 433MHz.

Hardware/Software

To interface with the Raspberry Pi it's recommended to get a Superheterodyne 433Mhz receiver module which can be found for less than $5. They will connect to the general purpose input/output (GPIO) pins on the Raspberry Pi using dupont leads and the data pin should be GPIO 27. Use 3.3V instead of 5V to power the receiver module. Once you have it connected up you will need the Python module rpi-rf to allow receiving 433MHz signals. Use pip3 install rpi-rf to install the module on your Raspberry Pi.

Python Script

Below is a script that you can save to a file named rfrx.py that will listen for signals from the wireless remote.

#!/usr/bin/env python3

import argparse
import signal
import sys
import time
import logging
import requests

from rpi_rf import RFDevice

rfdevice = None

dict = {
  1135923: { 'object': 'C0003', 'param': 'STATUS', 'value': 'ON' },
  1136332: { 'object': 'C0003', 'param': 'STATUS', 'value': 'OFF' },
  1136067: { 'object': 'C0004', 'param': 'STATUS', 'value': 'ON' },
  1136387: { 'object': 'C0004', 'param': 'STATUS', 'value': 'OFF' },
  1137923: { 'object': 'C0005', 'param': 'STATUS', 'value': 'ON' },
  1131980: { 'object': 'C0005', 'param': 'STATUS', 'value': 'OFF' }
}

# 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=27,
                    help="GPIO pin (Default: 27)")
args = parser.parse_args()

signal.signal(signal.SIGINT, exithandler)
rfdevice = RFDevice(args.gpio)
rfdevice.enable_rx()
timestamp = None
lastcode = 0
logging.info("Listening for codes on GPIO " + str(args.gpio))
while True:
    if rfdevice.rx_code_timestamp != timestamp:
        timestamp = rfdevice.rx_code_timestamp
        logging.info(str(rfdevice.rx_code) +
                     " [pulselength " + str(rfdevice.rx_pulselength) +
                     ", protocol " + str(rfdevice.rx_proto) + "]")
        if rfdevice.rx_code in dict and rfdevice.rx_code != lastcode:
            lastcode = rfdevice.rx_code
            response = requests.post('http://localhost:5000/shortcuts', data=dict[lastcode], auth=('user', 'pa55word'))
            print(dict[lastcode], response.json())
    time.sleep(0.01)
rfdevice.cleanup()

You will need to make several changes to this file, but for now you can just run using python3 rfrx.py to start listening for codes. When you press a button on the wireless remote you will see several lines like [INFO] rfrx: 1135923 [pulselength 187, protocol 1] displayed. If you don't see any codes shown refer to the rpi-rf repo for more help. From the lines displayed the first 7 digit number is the one you will need. Press every button on the remote that you intend to use and make a note of that number with the corresponding function, i.e. 1 ON. Close the script by hitting CRTL+C once complete.

You will then need to know which circuits on the IntelliCenter that you want to associate these buttons with. Instructions in a post on the thread IntelliCenter Gateway and Control Apps will explain. Once you have the circuit object names you wish to control, you will need to edit the file to modify the dictionary near the beginning. Simply replace entries with the 7 digit codes from before, along with the IntelliCenter object names and value (either ON of OFF). The param field should remain as STATUS.

The final change needed for the file will be the endpoint request near the end of the file. The url will likely remain as http://localhost:5000/shortcuts, but it can be changed where necessary. The auth login will be the username and password that you provided in the environment variable defined earlier for the Gateway application. You can test the endpoint using curl as detailed in the earlier Trouble Free Pool forum post. Once you're ready, you can run the modified script again using python3 rfrx.py and now when you press buttons, you should trigger the endpoint and change the relay circuit to either ON or OFF on the IntelliCenter.

Clone this wiki locally