AD2Pi | VISTA control panel |
- | 4 - KEYPAD GROUND (-) |
+ | 5 - KEYPAD PWD (+) |
DI | 6 - DATA IN TO KEYPAD |
Do | 7 - DATA OUT TO KEYPAD |
pip install alarmdecoder
git clone https://github.com/nutechsoftware/alarmdecoder.git cd alarmdecoder python setup.py install
git clone https://github.com/nutechsoftware/ser2sock.git
sudo minicom -d /dev/ttyAMA0
sudo /etc/init.d/ser2sock start nc localhost 10000
#!/usr/bin/python # -*- coding: utf-8 -*- import json import base64 import time from time import gmtime, strftime import requests from requests.auth import HTTPBasicAuth from alarmdecoder import AlarmDecoder from alarmdecoder.devices import SocketDevice # Configuration values HOSTNAME = 'localhost' PORT = 10000 # Fibaro access username = "admin" password = "admin" def main(): """ Example application that prints messages from the panel to the terminal. """ try: # Retrieve an AD2 device that has been exposed with ser2sock on localhost:10000. device = AlarmDecoder(SocketDevice(interface=(HOSTNAME, PORT))) # Set up an event handler and open the device device.on_message += handle_message device.on_lrr_message += handle_lrr_message with device.open(): while True: time.sleep(1) except Exception, ex: print 'Exception:', ex def handle_message(sender, message): """ Handles message events from the AlarmDecoder. """ print message.text jsonData = {"value":message.text} requests.put('http://10.0.1.43/api/globalVariables/AlarmStatus', json = jsonData, auth=HTTPBasicAuth(username, password)) def handle_lrr_message(sender, message): """ Handles message events from the AlarmDecoder. """ lrr_message = message.event_data + " " + message.event_type print lrr_message jsonData = {"value":lrr_message} requests.put('http://10.0.1.43/api/globalVariables/AlarmUsers', json = jsonData, auth=HTTPBasicAuth(username, password)) if __name__ == '__main__': main()
-- Check alarm status securityStatus = fibaro:getGlobalValue('AlarmStatus') lastSecurityStatus = fibaro:getGlobalValue('lastSecurityStatus') -- Show messages from alarm system if (lastSecurityStatus ~= securityStatus) then fibaro:call(108, "setProperty", "ui.Label1.value", os.date("%x %X ") .. securityStatus) fibaro:setGlobal('lastSecurityStatus',securityStatus) fibaro:debug(fibaro:getValue(108, 'ui.Label1.value')) end -- Check alarm user and event alarmUsers = fibaro:getGlobalValue('AlarmUsers') lastAlarmUsers = fibaro:getGlobalValue('lastAlarmUsers') -- If security status changed then show new status and send push if (lastAlarmUsers ~= alarmUsers) then fibaro:setGlobal('lastAlarmUsers',alarmUsers) userID = string.sub(alarmUsers, 3, 3) event = string.sub(alarmUsers, 5) -- set user name if userID == "4" then userID = "Raspberry" elseif userID == "3" then userID = "" elseif userID == "2" then userID = "" end -- set translated event if event == "ARM_AWAY" then event = " " elseif event == "ARM_STAY" then event = " " elseif event == "OPEN" then event = " " end fibaro:call(108, "setProperty", "ui.Label2.value", event .. " " .. userID) fibaro:debug(fibaro:getValue(108, 'ui.Label2.value')) fibaro:call(100, "sendPush", fibaro:getValue(108, 'ui.Label2.value')) fibaro:call(25, "sendPush", fibaro:getValue(108, 'ui.Label2.value')) end
Source: https://habr.com/ru/post/399833/
All Articles