Bluetooth Shutter remote
Posted: Wednesday 07 December 2016 22:50
I got myself a bluetooth IOS/Android shutter remote, and i decided that i won't be using it where it's made for.

I use it now switch my alarm, here are the details.
First pair the remote:
For monitoring the bluetooth buttons (the big and small one) i created a pyhton script thats running in a endless loop. Adjust your button IDX:
The events are mapped to /dev/input/event0 in my case, it could be something else in yours...
Finally i am using supervisor (sudo apt-get install supervisor) to make shure the pyhton script is always started:
Adjust the config file to your pyhton script path:
After that reread, and update supervisor
After this the button should work, since it is a push button, i configured this also in domoticz. I'm using the lua script below to actually trigger the security panel. I tried it several ways, but the only thing that seems to work is to use a json call in the lua script.
The seccode value is your security code md5 http://www.miraclesalad.com/webtools/md5.php

I use it now switch my alarm, here are the details.
First pair the remote:
Code: Select all
bluetoothctl
pairable on
scan on
pair 0C:FC:83:72:C9:87
trust 0C:FC:83:72:C9:87
connect 0C:FC:83:72:C9:87
Code: Select all
from evdev import InputDevice
from select import select
import time
import json, requests
var = 1
while var == 1:
try:
dev = InputDevice('/dev/input/event0')
while True:
r,w,x = select([dev], [], [])
for event in dev.read():
if event.code == 115:
if event.value == 1:
print("Grote knop")
requests.get(url="http://127.0.0.1:8888/json.htm?type=command¶m=switchlight&idx=457&switchcmd=On")
elif event.code == 28:
if event.value == 1:
print("Kleine knop")
requests.get(url="http://127.0.0.1:8888/json.htm?type=command¶m=switchlight&idx=458&switchcmd=On")
except:
time.sleep(5)
Finally i am using supervisor (sudo apt-get install supervisor) to make shure the pyhton script is always started:
Code: Select all
cd /etc/supervisor/conf.d/
sudo nano bluetoothbutton.conf
Code: Select all
[program:bluetoothbutton]
command = /usr/bin/python3 /home/pi/scripts/getButton.py
autostart=true
autorestart=true
stdout_logfile = /var/log/bluetoothbutton-stdout.log
stderr_logfile = /var/log/bluetoothbutton-stderr.log
Code: Select all
sudo supervisorctl reread
sudo supervisorctl update
The seccode value is your security code md5 http://www.miraclesalad.com/webtools/md5.php
Code: Select all
commandArray = {}
if (devicechanged['BluetoothButtonSmall'] == 'On') then
if(globalvariables['Security'] == 'Disarmed') then
print('Arm away alarm')
commandArray['SendNotification']='Alarm#Alarm is armed#0'
commandArray['OpenURL']='http://127.0.0.1:8888/json.htm?type=command¶m=setsecstatus&secstatus=2&seccode=3083202a936b7d0ef8b680d7ae73fa1a'
else
print('Disarm alarm')
commandArray['SendNotification']='Alarm#Alarm is disabled#0'
commandArray['OpenURL']='http://127.0.0.1:8888/json.htm?type=command¶m=setsecstatus&secstatus=0&seccode=3083202a936b7d0ef8b680d7ae73fa1a'
end
commandArray['BluetoothButtonSmall'] = 'Off'
end
return commandArray