Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
SUPLA RF Button
#!/usr/bin/env python3
import argparse
import signal
import sys
import time
import logging
import requests
import json
from rpi_rf import RFDevice
actions = json.load(open("supla-rf-commands.json"))
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=27,
help="GPIO pin (Default: 27)")
args = parser.parse_args()
signal.signal(signal.SIGINT, exithandler)
rfdevice = RFDevice(args.gpio)
rfdevice.enable_rx()
timestamp = None
logging.info("SUPLA RF BUTTON is waiting for commands on GPIO " + str(args.gpio))
while True:
if rfdevice.rx_code_timestamp != timestamp:
if str(rfdevice.rx_code) in actions:
sceneUrl = actions[str(rfdevice.rx_code)]
logging.info(sceneUrl)
requests.get(sceneUrl)
time.sleep(2)
timestamp = rfdevice.rx_code_timestamp
time.sleep(0.01)
rfdevice.cleanup()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.