RF Device and Alarm Status to openHAB

Contribute source code here. Anything not accompanied by source code will be removed.

RF Device and Alarm Status to openHAB

Postby n5qm » Wed Jan 29, 2014 9:05 am

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/ad2openhab

If you have any questions or run into issues, please let me know.

Robert
n5qm
newt
newt
 
Posts: 6
Joined: Tue Jan 28, 2014 3:36 pm

Re: RF Device and Alarm Status to openHAB

Postby Scott » Wed Jan 29, 2014 10:23 am

Cool stuff! I went ahead and added openHAB and your repo to our list of supported home automation systems. Thanks!
Scott
Expert Nut
Expert Nut
 
Posts: 118
Joined: Thu Dec 12, 2013 11:17 am

Re: RF Device and Alarm Status to openHAB

Postby jdblank » Mon May 26, 2014 5:20 am

Hi, thanks for putting this together. Will this script work with the AD2Pi or just the USB version?
jdblank
newt
newt
 
Posts: 4
Joined: Mon May 26, 2014 5:12 am

Re: RF Device and Alarm Status to openHAB

Postby kevin » Mon May 26, 2014 12:34 pm

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)
Not an employee of the company. Just here to help and keep things clean.
kevin
Platinum Nut
Platinum Nut
 
Posts: 994
Joined: Fri Aug 16, 2013 10:10 am

Re: RF Device and Alarm Status to openHAB

Postby jdblank » Mon May 26, 2014 2:32 pm

Thanks for the quick reply Kevin!

Do you recommend one protocol vs the other? I am new to this.

Josh
jdblank
newt
newt
 
Posts: 4
Joined: Mon May 26, 2014 5:12 am

Re: RF Device and Alarm Status to openHAB

Postby kevin » Mon May 26, 2014 5:25 pm

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.
Not an employee of the company. Just here to help and keep things clean.
kevin
Platinum Nut
Platinum Nut
 
Posts: 994
Joined: Fri Aug 16, 2013 10:10 am

Re: RF Device and Alarm Status to openHAB

Postby jdblank » Sun Jun 29, 2014 10:29 am

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!
jdblank
newt
newt
 
Posts: 4
Joined: Mon May 26, 2014 5:12 am

Re: RF Device and Alarm Status to openHAB

Postby kevin » Sun Jun 29, 2014 10:38 am

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
Not an employee of the company. Just here to help and keep things clean.
kevin
Platinum Nut
Platinum Nut
 
Posts: 994
Joined: Fri Aug 16, 2013 10:10 am

Re: RF Device and Alarm Status to openHAB

Postby jdblank » Sun Jun 29, 2014 3:37 pm

Thanks Kevin. Really appreciate the quick replies!

How do I determine if this is a socket device?
jdblank
newt
newt
 
Posts: 4
Joined: Mon May 26, 2014 5:12 am

Re: RF Device and Alarm Status to openHAB

Postby kevin » Mon Jun 30, 2014 10:20 am

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
Not an employee of the company. Just here to help and keep things clean.
kevin
Platinum Nut
Platinum Nut
 
Posts: 994
Joined: Fri Aug 16, 2013 10:10 am

Next

Return to Code Contributions

Who is online

Users browsing this forum: No registered users and 13 guests

cron