Page 1 of 1

Controlling a Bluetooth powered relay - armed light

PostPosted: Fri Mar 11, 2016 3:14 pm
by RickW
I am using the alarm decoder board with a raspberry pi. I built a large blinking red light that is mounted to the wall in my garage to indicate when my alarm system is armed. It is controlled by the pi.

I use remotes to arm/disarm the house and I tend to arm with the remote when I am in my car rather than arming when I am leaving. Also, it is nice to know if the system is armed when I'm in the garage or coming in from outside. The option I was using until now was a Honeywell 5800 Z-Wave Bridge which has a tiny little LED with a plastic magnifier that is very difficult to see unless you are right up next to it. I bought it for $40 just so I could have an indicator light, I don't have any zwave devices.

I've now replaced that with a large blinking red led strobe that I can see from anywhere. After looking at various options, I decided to use a bluetooth powered relay to control the light. I also wanted to keep power consumption low. This system pulls 1w to 3w, tested with a KillAWatt. The 3w is with the light fully on and blinking. The light is a bright but low power 12v LED light.

To make the bluetooth receiver relay + light, I got these items from ebay:

Red Security Alarm Strobe Signal Warning 12V LED Flashing Light: $3.50 or so
DC 12V 2A AC Adapter Power Supply Transformer for 5050 5630 3528 LED Strip 24W $6
12V 2.4G Bluetooth Relay Android Mobile Remote control for Light Switch Lock $13

and for the transmitter:

IOGEAR Bluetooth 4.0 USB Micro Adapter (GBU521) $11

Total was $34, I bought a plastic case for another $6 to bring it to about $40

I then stuck the bluetooth USB adapter on the pi, installed bluetooth on the pi:

Code: Select all
> sudo apt-get install --no-install-recommends bluetooth


and rebooted. Then I built the bluetooth receiver with power supply and light and stuck it on the wall in the garage.

I found the device's bluetooth address on the pi:

Code: Select all
> hcitool scan


and added it to the rfcomm.conf on the pi:

Code: Select all
> vi /etc/bluetooth/rfcomm.conf

rfcomm0 {
        # Automatically bind the device at startup
        bind yes;

        # Bluetooth address of the device
        device AA:BB:CC:11:22:33;

        # RFCOMM channel for the connection
        channel 1;

        # Description of the connection
        comment "Alarm Light Indicator";
}


and then rebooted again.

Then I wrote the following python code to turn the light on and off:

Code: Select all
def bluetooth_relay(powerOn):
        # NOTE: we thread this off because we are in the alarm decoder receive
        # thread and if we block it, we will lose alarm events
        thread.start_new_thread(bluetooth_relay_thread, (powerOn, ))

def bluetooth_relay_thread(powerOn):
        ser = serial.Serial('/dev/rfcomm0', 9600, timeout=2)
        cmd = ''
        if powerOn:
                cmd = 'A2\r\n'
        else:
                cmd = 'A3\r\n'
        ser.write(cmd)
        ser.close()


When I get a handle_arm or disarm:

Code: Select all
        device.on_arm += handle_arm
        device.on_disarm += handle_disarm

def handle_arm(sender):
        bluetooth_relay(True)
        ... do other things

def handle_disarm(sender):
        bluetooth_relay(False)
        ... do other things


The light is nice and bright and when you open the garage, it is clear if the alarm is armed or not. Also, when you are leaving and using a remote to arm the system, it is easy to see if the system actually armed or if it didn't because a window was left open or something.

If you wanted another alarm to sound upon some even or wanted lights to flash or anything else, using bluetooth with a relay seems like a good option with the following caveats:

1. I bought a cheap 1 channel bluetooth relay for the receiver. The board I bought has a fixed address (AA:BB:CC:11:22:33) that is the same for all the relays. So, you can't buy 2 of these cheap relays and to control 2 things independently.

2. This setup isn't secure at all. The relay uses a standard, fixed pin (1234). That wasn't an issue for me because if someone did take over control via bluetooth, I don't care since it is just a light in the garage. If you use it to control something more serious, you'd want to use a different bluetooth relay, one with full security (128+ bit key) on the pairing and communications, etc.

Re: Controlling a Bluetooth powered relay - armed light

PostPosted: Mon Mar 14, 2016 10:28 am
by Scott
Very cool, thanks for sharing!