Skip to content

Instantly share code, notes, and snippets.

@fracz
Last active June 12, 2018 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save fracz/c95d24800768cf72d2fa9b13d06e60a1 to your computer and use it in GitHub Desktop.
Save fracz/c95d24800768cf72d2fa9b13d06e60a1 to your computer and use it in GitHub Desktop.
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