If you use Pilight and RPI_RF together, you can send and receive all day long. I have several remote controls, door/window sensors, and electrical plugs that I control using HASS and the remote controls. But, there are a few things you need to know to do this:
- Use a superheterodyne transmitter and receiver. The cheap ones don’t work well, if at all, because the range sucks on them. A good transmitter/receiver should cost you around $13 or so on Amazon.
Good Type: http://www.amazon.com/dp/B00HEDRHG6/
Bad Type: http://www.amazon.com/dp/B00M2CUALS/
- Use an external antenna on your superheterodyne transmitter and receiver. The jumper kits that you can get have roughly 6-8" wires in them. These are more than sufficient to have a 50’ or more range.
Jumper Kit Example: http://www.amazon.com/dp/B01LZF1ZSZ/
- If you have a remote that already controls an outlet, and the remote/outlet cannot be reprogrammed, you may experience some sync issues with HASS. This is because 433 stuff doesn’t have confirmation messages in its design. If HASS doesn’t “hear” the button press, it won’t know that the light is off/on. That causes the HASS state to not match the live state of the device. If you are intentional in your button presses and make sure you press it for at least a second, this is less likely to happen. But even if it does, you can automate around this to a degree.
So… in my example, you can have the following:
Remote 1
Remote 2
Remote 4
Outlet 1
Outlet 2
Outlet 3
As you can see, we’ve “lost” remote 3, and we’ve also “lost” outlet 4. Now, assume that Remote 1 only controls Outlet 1, Remote 2 controls Outlet 2, etc. So there’s no remote for Outlet 3, and no Outlet for Remote 4. If you know the codes to Outlet 3, you can still use HASS to control it. If it’s reprogrammable (like the ones that BRUH uses), you can reprogram it to match the new remote. If you don’t know the codes, you’ll have to use trial and error to guess the codes, but that’s nearly impossible. We’ll come back to Outlet 3 and Remote 4 later on. Let’s keep going.
In Pilight, you must first setup Pilight to listen to ALL protocols. This is documented in the manual install of Pilight, so I’m not going to go into detail on that.
NOTE: If you are up to date on your firmware on the Raspberry PI, you’ll need to use the Development Branch of Pilight. I’ve written another article on that, so I’m not going into detail on that either.
Once Pilight is installed and setup to listen to all the codes, you’ll use sudo pilight-receive
to “listen” the codes from each Remote. When you press a button on the remote, you should see something like this:
{
"message": {
"id": "A3",
"unit": 61,
"state": "off"
},
"origin": "receiver",
"protocol": "clarus_switch",
"uuid": "0000-b8-27-eb-4ffabe",
"repeats": 1
}
Repeat this for each button press on each remote. Once you have your codes and device types, you can re-run the Pilight setup so that Pilight only listens to those protocols that you need.
Once you’ve finished getting all the Pilight codes, you’ll still need to get the codes using RPI_RF so we can transmit them later. To do this, you’ll need the rpi-rf_receive.py file from the RPI_RF repository. The master link is: https://pypi.python.org/pypi/rpi-rf
Using the link above, download the rpi-rf_receive.py file located in the SCRIPTS section. Place that file in your home folder on your PI (not your AIO Virtual Environment if you’ve install HASS using that method). Then run chmod +x ./rpi-rf_receive.py
in the same directory that you placed the file. This will allow it to be executed. Now, run the file using sudo ./rpi-rf_receive.py
. You should see something like this if you did it correctly:
2017-10-22 22:15:00 - [INFO] rfrx: Listening for codes on GPIO 27
2017-10-22 22:16:00 - [INFO] rfrx: 21280 [pulselength 200, protocol 1]
2017-10-22 22:17:00 - [INFO] rfrx: 21211 [pulselength 200, protocol 1]
This will give you the “codes” that HASS will transmit when the button press is received. Repeat this for each button press.
Now that you have both the Pilight and RPI-RF codes, here’s how to set things up. We will have Pilight receive the codes, and RPI-RF transmit the codes. You “can” do both with Pilight, but I’ve found this method to be nearly bulletproof in accuracy, which is why I use it.
First, create 2 automations. The first one is triggered by the Pilight message that is generated when you press the ON button on the remote and will turn on the RPI-RF switch we will create later. The second one is triggered by the Pilight message that is generated when you press the OFF button on the remote and will turn off the RPI-RF switch we will create later.
automations/pilight_remote1_on.yaml
alias: "pilight_outlet1_on"
trigger:
platform: event
event_type: pilight_received
event_data:
protocol: clarus_switch
uuid: 0000-b8-27-eb-4ffabe
id: 'A3'
state: 'on'
action:
- service: homeassistant.turn_on
entity_id: switch.rpirf_outlet1
automations/pilight_remote1_off.yaml
alias: "pilight_remote1_off"
trigger:
platform: event
event_type: pilight_received
event_data:
protocol: clarus_switch
uuid: 0000-b8-27-eb-4ffabe
id: 'A3'
state: 'off'
action:
- service: homeassistant.turn_off
entity_id: switch.rpirf_outlet1
Next, we will create the RPI-RF switch in HASS:
switches/rpi_rf.yaml
platform: rpi_rf
gpio: 17
switches:
rpirf_outlet1:
#Outlet 1
code_off: 21820
code_on: 21811
protocol: 1
pulselength: 200
signal_repetitions: 15
Now, make sure Pilight is running and restart HASS to activate the switch/automations you just created. Whenever you press the button on the remote, Pilight will receive that message, place that message on the HASS event bus, and the automation will be triggered. The automation tells the switch to be turned on (or off), which sends the RPI-RF code, which turns on the light.
Now, all you’ve really done is setup a switch in HASS that “mimics” the state of the REAL switch and remote. So now that you are armed with this information, you can now use a remote (Remote 4) to control an outlet that it wasn’t originally programmed for (Outlet 1 or 2). And assuming that you could successfully find the codes for Outlet 3, you could use Remote 4 to control Outlet 3.
Hopefully this helps. Also keep in mind, I wrote this late at night, so if I missed something or something doesn’t make sense, let me know.