For the past year I lived with the polling based concord232 platform, it works, but there is much to be desired. So I started looking around for alternatives and found the RTL_433 project:
This code uses a $30 radio to pick up the signals of the GE/Interlogix wireless security sensors and can output there state in json format, which is perfect for MQTT! Here is the radio I am using:
https://www.amazon.com/gp/product/B01GDN1T4S/ref=oh_aui_search_asin_title?ie=UTF8&psc=1
For starters you need to have RTL_433 installed and have a working MQTT server that is integrated with Home Assistant.
We now need to discover all the sensors, so fire up your radio listener:
/usr/local/bin/rtl_433 -f 319500000 -R 100 -F json
Go ahead and open and close each sensor and you should see messages like this on the console:
{"time" : "2019-03-26 20:24:47", "model" : "Interlogix", "id" : "a8x80b", "device_type" : "contact", "raw_message" : "2d15bc", "battery" : "OK", "switch1" : "OPEN", "switch2" : "OPEN", "switch3" : "CLOSED", "switch4" : "OPEN", "switch5" : "OPEN"}
{"time" : "2019-03-26 20:24:48", "model" : "Interlogix", "id" : "a8x80b", "device_type" : "contact", "raw_message" : "a114ac", "battery" : "OK", "switch1" : "CLOSED", "switch2" : "OPEN", "switch3" : "CLOSED", "switch4" : "OPEN", "switch5" : "OPEN"}
If you look closely, you will see that one of the switches, in this case “switch 1”, went from open to close. Switch 3 is usually the tamper alarm, and depending on the device switches 2,4, or 5 might trigger based on opening or closing the sensor.
Now would be a good time to go around and map the ID of all your sensors to a friendly name. Make a list like this:
a8x80b front_door
a3xb9b kitchen_window_1
a3x76e kitchen_window_2
a4x41d kitchen_window_3
acx728 kitchen_window_4
Next, you will need to use the following parsing/rename script to take the values and turn them into something a bit more meaningful for MQTT/HA. You will need to update the mqtt settings as well as the mapping of IDs to friendly names, be sure the friendly names are longer than 7 characters. Don’t forget to mark it executable.
file: /home/homeassistant/interlogix
#!/bin/bash
MQTT_HOST=<IP or localhost>
MQTT_USER=<MQTT USER>
MQTT_PASSWORD=<PASSWORD>
# Remove hash on next line for debugging
#set -x
#
# Start the listener and enter an endless loop
#
/usr/local/bin/rtl_433 -f 319500000 -R 100 -F json | while read line
do
# Remove hash from following line to record a raw log of events
#echo $line | tee -a /tmp/rtl_433_raw.log | \
# Pull out the ID and give it a friendly name, for example the ID a8x80b is my front_door.
TOPIC=$(echo "$line" | jq -r '.id' | sed \
-e 's/a8x80b/front_door/' \
-e 's/a3xb9b/kitchen_window_1/' \
-e 's/a3x76e/kitchen_window_2/' \
-e 's/a4x41d/kitchen_window_3/' \
-e 's/acx728/kitchen_window_4/')
# Select desired data
JSON=$(echo "$line" | jq --compact-output '. | { time: .time, device_type: .device_type, battery: .battery, switch1: .switch1, switch2: .switch2, switch3: .switch3, switch4: .switch4, switch5: .switch5 }')
#
# MQTT Time!
#
# Only process topics equal to or grater than 7 characters. This will avoid processing your neighbors sensors.
#
# Note: remove the "-r" below for testing, this causes MQTT NOT to retain the value on reboot.
#
if [ ${#TOPIC} -ge 7 ]
then
echo $JSON | /usr/bin/mosquitto_pub -r -h $MQTT_HOST -u $MQTT_USER -P $MQTT_PASSWORD -l -t "rtl_433/$TOPIC"
fi
done
You should be able to launch the script and start to see MQTT populate as such:
$ mosquitto_sub -v -u -P -h localhost -p 1883 -t ‘rtl_433/#’
rtl_433/kitchen_window_4 {"time":"2019-03-26 21:14:30","device_type":"contact","battery":"OK","switch1":"CLOSED","switch2":"CLOSED","switch3":"CLOSED","switch4":"OPEN","switch5":"OPEN"}
rtl_433/kitchen_window_2 {"time":"2019-03-26 21:21:40","device_type":"contact","battery":"OK","switch1":"CLOSED","switch2":"CLOSED","switch3":"CLOSED","switch4":"OPEN","switch5":"OPEN"}
rtl_433/kitchen_window_3 {"time":"2019-03-26 19:20:04","device_type":"contact","battery":"OK","switch1":"OPEN","switch2":"CLOSED","switch3":"CLOSED","switch4":"OPEN","switch5":"OPEN"}
rtl_433/front_door {"time":"2019-03-26 19:28:49","device_type":"contact","battery":"OK","switch1":"CLOSED","switch2":"OPEN","switch3":"CLOSED","switch4":"OPEN","switch5":"OPEN"}
rtl_433/kitchen_window_1 {"time":"2019-03-26 21:13:44","device_type":"contact","battery":"OK","switch1":"CLOSED","switch2":"CLOSED","switch3":"CLOSED","switch4":"OPEN","switch5":"OPEN"}
If you made it this far, you are in great shape! Now we need to finish it off with some MQTT sensors in your configuration.yaml, for each of the entries above you need to create some of these:
binary_sensor:
# - platform: concord232
- platform: mqtt
name: kitchen_window_1
state_topic: 'rtl_433/kitchen_window_1'
value_template: '{{ value_json.switch1 }}'
payload_off: "CLOSED"
payload_on: "OPEN"
device_class: window
- platform: mqtt
name: kitchen_window_1_battery
state_topic: 'rtl_433/kitchen_window_1'
value_template: '{{ value_json.battery }}'
payload_off: "OK"
payload_on: "LOW"
device_class: battery
Restart HA, and you should now see something like this in your states view:
Finally, you need to make the interlogix script into a system service that starts at boot. Under Ubuntu I did something like this:
Create the file: /etc/systemd/system/[email protected] with the following contents:
[Unit]
Description=RTL-SDR to MQTT
[email protected]
[Service]
Type=simple
User=%i
ExecStart=/home/homeassistant/interlogix
[Install]
WantedBy=multi-user.target
Lastly, enable it, update systemd and start it up:
sudo systemctl enable [email protected]
sudo systemctl daemon-reload
sudo service [email protected]
One last note, on Ubuntu, you need to add the following file so that non-root users can run RTL_433:
file: /etc/udev/rules.d/20.rtlsdr.rules
#RTL2832U OEM vid/pid, e.g. ezcap EzTV668 (E4000), Newsky TV28T (E4000/R820T) etc.
SUBSYSTEMS==“usb”, ATTRS{idVendor}==“0bda”, ATTRS{idProduct}==“2838”, MODE:=“0666”
Hope this helps!