Page 1 of 2
RF Device and Alarm Status to openHAB
Posted:
Wed Jan 29, 2014 9:05 am
by n5qm
All,
Here is a script I put together to take RF events and system events and push them to openHAB. I have also included corresponding samples from the openHAB item file and the translations used.
It should be a fairly simple to change this to monitor zones instead of RF devices, but I want to monitor RF contacts that are not configured in my panel.
https://github.com/N5QM/ad2openhabIf you have any questions or run into issues, please let me know.
Robert
Re: RF Device and Alarm Status to openHAB
Posted:
Wed Jan 29, 2014 10:23 am
by Scott
Cool stuff! I went ahead and added openHAB and your repo to our list of supported home automation systems. Thanks!
Re: RF Device and Alarm Status to openHAB
Posted:
Mon May 26, 2014 5:20 am
by jdblank
Hi, thanks for putting this together. Will this script work with the AD2Pi or just the USB version?
Re: RF Device and Alarm Status to openHAB
Posted:
Mon May 26, 2014 12:34 pm
by kevin
Looking at the code it looks to target USB devices, however it could be modified to be used with the AD2Pi
in ad2openhab.py
If you want from the raw serial port of the AD2Pi:
FROM
- Code: Select all
from alarmdecoder.devices import USBDevice
# Global Variables
LOG_FILE = '/opt/ad2openhab/messages'
OPENHAB_HOST = 'localhost'
OPENHAB_PORT = '8080'
def main():
try:
# Setup logging
logging.basicConfig(
filename = LOG_FILE,
level = logging.INFO,
format = '%(asctime)s %(message)s',
datefmt = '%m/%d/%Y %H:%M:%S'
)
# Retrieve the first USB device
device = AlarmDecoder(USBDevice.find())
# Set up an event handler and open the device
device.on_rfx_message += handle_rfx_message
device.on_arm += handle_arm
device.on_disarm += handle_disarm
with device.open():
while True:
time.sleep(1)
TO
- Code: Select all
from alarmdecoder.devices import SerialDevice
# Global Variables
LOG_FILE = '/opt/ad2openhab/messages'
OPENHAB_HOST = 'localhost'
OPENHAB_PORT = '8080'
#default AD2Pi device on Raspberry Pi
SERIAL_DEVICE = '/dev/ttyAMA0'
BAUDRATE = 115200
def main():
try:
# Setup logging
logging.basicConfig(
filename = LOG_FILE,
level = logging.INFO,
format = '%(asctime)s %(message)s',
datefmt = '%m/%d/%Y %H:%M:%S'
)
# Retrieve the Serial Device
device = AlarmDecoder(SerialDevice(interface=SERIAL_DEVICE))
# Set up an event handler and open the device
device.on_rfx_message += handle_rfx_message
device.on_arm += handle_arm
device.on_disarm += handle_disarm
with device.open(baudrate=BAUDRATE):
while True:
time.sleep(1)
Or if you are using Ser2Sock:
TO
- Code: Select all
from alarmdecoder.devices import SocketDevice
# Global Variables
LOG_FILE = '/opt/ad2openhab/messages'
OPENHAB_HOST = 'localhost'
OPENHAB_PORT = '8080'
SER2SOCK_HOST = 'localhost'
SER2SOCK_PORT = 10000
def main():
try:
# Setup logging
logging.basicConfig(
filename = LOG_FILE,
level = logging.INFO,
format = '%(asctime)s %(message)s',
datefmt = '%m/%d/%Y %H:%M:%S'
)
# Retrieve an AD2 device that has been exposed with ser2sock on localhost:10000.
device = AlarmDecoder(SocketDevice(interface=(SER2SOCK_HOST, SER2SOCK_PORT)))
# Set up an event handler and open the device
device.on_rfx_message += handle_rfx_message
device.on_arm += handle_arm
device.on_disarm += handle_disarm
with device.open():
while True:
time.sleep(1)
Re: RF Device and Alarm Status to openHAB
Posted:
Mon May 26, 2014 2:32 pm
by jdblank
Thanks for the quick reply Kevin!
Do you recommend one protocol vs the other? I am new to this.
Josh
Re: RF Device and Alarm Status to openHAB
Posted:
Mon May 26, 2014 5:25 pm
by kevin
If you are using Ser2Sock with our AD2Pi raspbian image, it gives the ability for multiple devices to interface with the AlarmDecoder products over TCP/IP. I think this is the preferred method unless you have something prohibiting it.
Re: RF Device and Alarm Status to openHAB
Posted:
Sun Jun 29, 2014 10:29 am
by jdblank
Can you tell me where this file should be located? I am using your Raspberry image and have successfully connected to my panel but I am not sure if the Python interface is already installed or if I need to install that first. I can get around but definitely a novice.
Thanks!
Re: RF Device and Alarm Status to openHAB
Posted:
Sun Jun 29, 2014 10:38 am
by kevin
According to his source, everything is in /opt/ad2openhab/
But realistically, you could run it from anywhere provided you are using the correct device type - if you are using our image, you would want to make sure that it is a socket device, as that is the only way to have multiple applications speak to the alarmdecoder device at the same time.
You would just execute python ad2openhab.py from a shell, or modify an init script to start that automatically on boot (after ser2sock of course).
Thanks,
Kevin
Re: RF Device and Alarm Status to openHAB
Posted:
Sun Jun 29, 2014 3:37 pm
by jdblank
Thanks Kevin. Really appreciate the quick replies!
How do I determine if this is a socket device?
Re: RF Device and Alarm Status to openHAB
Posted:
Mon Jun 30, 2014 10:20 am
by kevin
You said you were using our Raspberry Pi image? Try and telnet to the IP address Port 10000 - if you can connect and see alarm messages, you are a socket based device.
Thanks,
Kevin