-
1RPi OS Install & Config
OS: Raspberry Pi OS Lite
Install the OS
- Download the lastest OS from https://www.raspberrypi.org/downloads/raspbian/
- Use Etcher to image a 2GB or larger SD card.
Configure Wireless Access
- https://www.tomshardware.com/reviews/raspberry-pi-headless-setup-how-to,6028.html
- Setup Wireless
- Create a file named wpa_supplicant.conf under boot directory.
- Add the following lines to the file and save.
- Create a file named wpa_supplicant.conf under boot directory.
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
- L2 Timezone
- S3 Password
- 1 System Options
-
2Wiring
Wire the TX, RX, & Button
- milaq/rpi-rf
- https://github.com/milaq/rpi-rf
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)
-
3Config 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
- https://pypi.org/project/rpi-rf/
- sudo apt update
- sudo apt install python3-pip
- sudo -H pip3 install --system rpi-rf (may not need the -H)
- pip3 install rpi-rf
Create MQTT-RF Directory
- sudo mkdir mqtt-rf
RPi-RF Python Scripts
- Copy the rf-receive.py and rf-send.py files to /home/pi/mqtt-rf
- Do not modify the these scripts
- https://github.com/KayserSosa/RPiRF
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
-
4Config MQTT
Install Mosquitto Program
- https://www.emqx.io/blog/how-to-use-mqtt-in-python
- https://pimylifeup.com/raspberry-pi-mosquitto-mqtt-server/
- sudo apt update
- sudo apt install mosquitto mosquitto-clients
- pip3 install paho-mqtt
Mosquitto Python Scripts
- Copy the mqtt-subscribe.py script files to /home/pi/mqtt-rf
- https://github.com/KayserSosa/RPiRF
Test Mosquitto Scripts
- cd /home/pi/mqtt-rf
- python3 mqtt-subscribe.py
Install Mosquitto Program on HA
- Configuration
- Devices & Services
- + Add Integration
- Mosquitto broker
- + Add Integration
- Devices & Services
Create MQTT User on HA
- Configuration
- People & Zones
- Users
- + Add User
- Users
- People & Zones
Test the MQTT communication between the RPi and HA
- Configuation
- Devices & Services
- Mosquitto broker
- Configure
- Publish & Listen
- Configure
- Mosquitto broker
- Devices & Services
Creating Home Assistant Buttons
- ON Button (complete for each switch or grouping)
- Configuration
- Automations & Scenes
- Scripts
- + Add Script
- Name: EtekcityZap Switch 1 - On
- Sequence
- Action type: Call service
- Service: mqtt.publish
- Publish a message to an MQTT topic.
- Topic: etekcityzap/switch1/command
- Payload: ON
- QoS: 1
- Retained: checked but off
- + Add Script
- Scripts
- Automations & Scenes
- Configuration
- OFF Button (complete for each switch or grouping)
- Configuration
- Automations & Scenes
- Scripts
- + Add Script
- Name: EtekcityZap Switch 1 - Off
- Sequence
- Action type: Call service
- Service: mqtt.publish
- Publish a message to an MQTT topic.
- Topic: etekcityzap/switch1/command
- Payload: OFF
- QoS: 1
- Retained: checked but off
- + Add Script
- Scripts
- Automations & Scenes
- Configuration
-
5Config Safe Shutdown Button
https://github.com/TonyLHansen/raspberry-pi-safe-off-switch/
Install GPIO Zero
- https://gpiozero.readthedocs.io/en/stable/installing.html
- sudo apt update
- sudo apt install python3-gpiozero
Safe Shutdown Python Script
- Copy the safe-shutdown-press-simple.py script file to /home/pi/mqtt-rf
- https://github.com/KayserSosa/RPiRF
Make Executable
- sudo chmod a+x /home/pi//home/pi/mqtt-rf/safe-shutdown-press-simple.py
Test Safe Shutdown Script
- cd /home/pi/mqtt-rf
- python3 safe-shutdown-press-simple.py
-
6Config Execution at Boot
https://www.dexterindustries.com/howto/run-a-program-on-your-raspberry-pi-at-startup/
Modify rc.local
- sudo nano /etc/rc.local
- Add the following before exit 0
- python3 /home/pi/mqtt-rf/mqtt-subscribe.py &
- python3 /home/pi/mqtt-rf/safe-shutdown-press-simple.py
Reboot
- sudo reboot
-
7Step 7
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.