
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