Close
0%
0%

Raspberry Pi 433MHz RF Transmitter/Receiver

Setup a 433 MHZ transmitter/receiver with the Raspberry Pi for Home Assistant use

Similar projects worth following
I setup a RF Transmitter/Receiver on a Raspberry PI so I can control some Etekcity Remote Controled Outlets from Home Assistant.

I wanted control some Etekcity RF switches from Home Assistant.

I had an old Raspberry Pi 2 Model B V1.1 laying around doing nothing, so I got started.  I believe this process should work with any model, the pins just may be different and easily updated in the send/receive scripts.

I started by installing Raspberry Pi OS Lite, as I didn't need a screen other than initial setup.  I had a USB Wifi dongle that I use for communication and I enabled SSH.  The OS was fully updated and configured and autologin was setup.

I wired up the RF Transmitter and RF Receiver per https://github.com/milaq/rpi-rf.

I then configured the RF per https://www.instructables.com/RF-433-MHZ-Raspberry-Pi/.  Installing RPi-RF per https://pypi.org/project/rpi-rf/.  Created my working directory and copied my scripts from https://github.com/KayserSosa/RPiRF.  I then obtained the On/Off codes from the outlets. and tested to make sure the send code was working.

MQTT configuration was next.  I used https://www.emqx.io/blog/how-to-use-mqtt-in-python and https://pimylifeup.com/raspberry-pi-mosquitto-mqtt-server/ to get it installed on the RPi.  I copied my script from https://github.com/KayserSosa/RPiRF and tested.  I was able to send words back and forth from Home Assistant and the RPi.  This was before I had the final version of the code, so most of the testing was with the original version that I tweaked as needed.

I then experimented with several ways to create a button or switch in Home Assistant to control the Etekcity RF switches.  I finally settled on a working method via scripts.  I only setup a single button at this time, the rest were setup when the project was completed.

Next I started on trying to figure out how to auto execute my python script and ran into several walls.  One of the methods I had used on another older project kept giving me errors and I couldn't figure it out.  That is where it sat for awhile, until I finally came back to it.  I had to almost re-figure out what I had done.  Luckily I had most of it already done and partly documented.

I then figured out how to the execute my python script at login, modify the rc.local file instead, which I verified it worked.

I knew I needed a safe shutdown switch for the RPi or it would become corrupted.  I next wired in and configured the button.  Testing was successful.

Then I needed to figure out how to execute both python scripts at boot.  Wasn't sure if I had to combine them into a single script or if I could run them both the same way as the main script, I was finding conflicting information on that topic.  I put them both in the rc.local and success.

The next task was to create the buttons in Home Assistant and everything was working.

The last thing I did was block the IP of the RPi from the internet, as I have no need for the access unless I'm updating.

I have this RPi sitting in my office which is on the first floor and opposite side of the house from a pair of the switches that are upstairs as well.  It can access all the switches without issue.  Also my Home Assistant server is on a virtual machine not a RPi.

An issue I ran into, was the retention of the last button press.  So if I turned on a light and had to reboot the RPi but had manually turn the light off, the light would come back on after reboot.  Being new to MQTT, after a bunch of reading and trying different things in the code I discovered I had selected retain message to yes on the Home Assistant side.  Once I cleared the retained messages and set retained message to no, the issue was gone.

I think I figured out the final issue of keeping the system alive.  I initially had it setup on Wifi (2.4ghz) and have since hardwired it.  My 2.4ghz network has lots of stuff on it.  I haven't had an issue since connecting to hardwire. ...

Read more »

  • 1
    RPi OS Install & Config

    OS: Raspberry Pi OS Lite

    Install the OS

    Configure Wireless Access

    country=US
    ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
    update_config=1
    network={
       scan_ssid=1
       ssid=”ssid name”
       psk=”password”
    }

    Enable SSH

    • Create an empty file in the boot directory called ssh.

    Configure Raspberry Pi OS

    • SSH into the Pi
    • sudo apt update
    • sudo apt upgrade
    • sudo apt full-upgrade
    • sudo apt autoremove
    • sudo raspi-config
      • 1 System Options
        • S3 Password
          • Enter in a password
        • S4 Hostname
          • RPi-RF
        • S5 Boot / Auto Login
          • B2 Console Autologin Text console, automatically logged in as 'pi' user
        • 5 Localisation Options
          • L2 Timezone
            • Setup yours
          • 8 Update
  • 2
    Wiring

    Wire the TX, RX, & Button

    TX: (little)

    • GND > PIN 09 (GND) (Red)
    • VCC > PIN 02 (5V) (Black)
    • DATA > PIN 11 (GPIO17) (Yellow)
    • Antenna

    RX: (big)

    • VCC > PIN 04 (5V) (Red)
    • DATA > PIN 13 (GPIO27) (Orange)
    • GND > PIN 06 (GND) (Black)
    • Antenna

    Button:

    • B > PIN 37 (GPIO26) (Yellow)
    • C > PIN 39 (GND) (Black)
  • 3
    Config RF

    https://www.instructables.com/RF-433-MHZ-Raspberry-Pi/

    Program the remote and outlets to each other.

    Map python and python3 to the same PATH (may not be needed)

    • alias python="python3"

    Install RPi-RF Program

    Create MQTT-RF Directory

    • sudo mkdir mqtt-rf

    RPi-RF Python Scripts

    Obtain the RF Codes

    • cd /home/pi/mqtt-rf
    • python3 rf-receive.py
    • Once the script is running, push the button on the remote for on and note the codes, pulselength and protocol, same for the off.

    Test RPi-RF Send Script

    • usage: rf-send.py [-h] [-g GPIO] [-p PULSELENGTH] [-t PROTOCOL] [-l LENGTH] [-r REPEAT] CODE
    • Example: python3 rf-send.py -p 168 -t 1 87811

View all 7 instructions

Enjoy this project?

Share

Discussions

Ken Yap wrote 02/09/2022 at 23:39 point

If you want an even lighter RPi distro, try https://dietpi.com/ That's what I used for #An NTP server using GNSS for time 

  Are you sure? yes | no

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates