Home Assistant Automation - Sonoff RF Bridge and PIR Motion Sensor
synopsis
The host builds a Home Assistant automation that switches RF-controlled LED strip lights on when a Sonoff PIR motion sensor sees movement, and off again 90 seconds after it stops, using a $15.99 Sonoff RF Bridge on Home Assistant 2021.6.2 running on a Raspberry Pi 4.
Pairing in eWeLink. The bridge is first adopted in Sonoff's eWeLink phone app. It must join a 2.4 GHz network, ideally a separate IoT one, because his hardware version has no 5 GHz support. It then learns the strip light's remote buttons and the motion sensor, which is added as an alarm, each within a 60-second window. The app's per-motion alarm notifications are worth switching off.
Bringing it into Home Assistant. The SonoffLAN integration, installed through HACS, logs into eWeLink with credentials placed in configuration.yaml and runs in local-and-cloud mode by default. YAML's sensitivity to spacing is why the host points viewers to his GitHub repository for the snippets.
Finding the command codes. A temporary automation posts a notification for every RF event the bridge hears. This shows that learned codes are numbered from 0 in order: on is 0, off is 1, motion is 2. Two scripts sending commands 0 and 1 become on and off buttons in a horizontal-stack card on his office dashboard.
Tying motion to the lights. The sensor is declared a motion device with a 60-second timeout that restarts on each detection. One automation sends "on" when it changes from off to on. A second sends "off" once it has been off for 30 seconds, so the light stays on for 90 seconds after the last motion. The host calls the timings arbitrary, and concedes his blog post had wrong command numbers to correct.
- A cheap Sonoff RF bridge brings RF remote devices into Home Assistant. The host's build is the Sonoff RF Bridge ($15.99 on Amazon), a Sonoff PIR motion sensor ($17.19), any RF LED strip lights and Home Assistant 2021.6.2 on a Raspberry Pi 4, with HACS and a file editor installed. He calls the Pi great for learning but expects heavier users to move to a VM on a Synology NAS or an Intel NUC.
- Pair the bridge in eWeLink on a 2.4 GHz IoT network. His hardware version of the bridge does not support 5 GHz. It signals pairing mode with two short blinks and one long for 300 seconds. Each remote button and the motion sensor (added as an "alarm") is learned within a 60-second window. He turns off the app's alarm notifications, which fire on every motion event.
- The SonoffLAN integration links eWeLink to Home Assistant. Installed through HACS, it defaults to local-and-cloud mode, with cloud-only and local-only as options. The eWeLink email and password go in configuration.yaml. Because YAML is finicky about spacing, he suggests copying from his GitHub repository instead of the web page.
- A notification automation reveals each learned RF command's number. Commands are numbered from 0 in the order learned: his on button was 0, off was 1, the motion sensor 2. Scripts sending commands 0 and 1 then become dashboard buttons. An automation needs a unique 14-digit ID to be editable or switchable in the UI. He admits his blog post had wrong command numbers he meant to fix.
- His motion lights turn off 90 seconds after motion stops. The sensor is declared with device class motion and a 60-second timeout that restarts on each detection. A second automation waits a further 30 seconds after the sensor goes off before sending the off command. He calls both timings arbitrary and suggests tuning them.