Advertisement
boomx

RFID-Komplex Update 1.4b

Jan 22nd, 2016
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 23.25 KB | None | 0 0
  1. --[[
  2. %% properties
  3. 96 userCodes
  4. %% globals
  5. --]]
  6.  
  7. -- HIER DIE ARRAYS ANPASSEN (neue IDs können einfach hinzugefügt werden)
  8. local tagReader = 96 -- ID des RFID-Leser (bitte auch in dem Header ändern)
  9. local doorID = {16, 18, 20, 55} -- IDs der Sensoren
  10. local phoneID = {68, 113} -- IDs der Handys, an die eine Push geschickt werden soll
  11. local countID = 1000 -- Anzahl eurer devices (Muss nicht zwangsläufig geändert werden)
  12.  
  13. -- OPTIONEN
  14. -- Prüfung einer globalen Variable für Chip 3/4, ob diese gültig ist.
  15. -- Bei nicht Nutzung dieser Funktion müsst Ihr nichts weiter einrichten.
  16. -- Solltet Ihr diese nutzen wollen, dann müsst Ihr für jeden Chip eine Variable anlegen (z.B rfid_active1)
  17. local rfid_active3 = fibaro:getGlobalValue('rfid_active3') -- Variable zum Prüfen ob RFID-Chip1 gültig ist oder nicht (active = gültig/inactive = ungültig)
  18. local rfid_active4 = fibaro:getGlobalValue('rfid_active4') -- Variable zum Prüfen ob RFID-Chip2 gültig ist oder nicht (active = gültig/inactive = ungültig)
  19.  
  20. -- Hier könnt Ihr mit der 1 setzen, dass die RFID-Tags nur zum entschärfen genutzt werden sollen
  21. local rfid_use1 = 1 -- Wenn Ihr mit dem RFID-Tag1 nur entschärfen wollt, bitte auf 1 setzen
  22. local rfid_use2 = 1 -- Wenn Ihr mit dem RFID-Tag2 nur entschärfen wollt, bitte auf 1 setzen
  23. local rfid_use3 = 0 -- Wenn Ihr mit dem RFID-Tag3 nur entschärfen wollt, bitte auf 1 setzen
  24. local rfid_use4 = 0 -- Wenn Ihr mit dem RFID-Tag4 nur entschärfen wollt, bitte auf 1 setzen
  25.  
  26. -- Prüfung, ob Ihr eigene Aktionen ausführen möchtet (Siehe FUNKTIONEN FÜR AKTIONEN)
  27. local own_action = 1 -- Bitte auf 1 setzen, wenn Ihr eigene Aktionen ausführen wollt.
  28.  
  29. -- 10-stellige Byte-Array's (Bytes, weil RFID-Tags auch Zeichen ausserhalb des lesbaren Bereichs liefern)
  30. local rfid1 = {143, 80, 84, 84, 42, 0, 1, 4, 0, 0} -- <--ANPASSEN: Byte-Array eines RFID-Tags
  31. local rfid2 = {143, 174, 97, 84, 42, 0, 1, 4, 0, 0} -- <--ANPASSEN: Byte-Array eines RFID-Tags
  32. local rfid3 = {143, 80, 84, 84, 42, 0, 1, 4, 0, 0} -- <--ANPASSEN: Byte-Array eines RFID-Tags
  33. local rfid4 = {143, 174, 97, 84, 42, 0, 1, 4, 0, 0} -- <--ANPASSEN: Byte-Array eines RFID-Tags
  34. local code = {49, 50, 51, 52, 0, 0, 0, 0, 0, 0} -- <--ANPASSEN: Byte-Array für Zahlencode (1234 als Unicode)
  35.  
  36. -- WIDGET-Support
  37. -- Solltet Ihr die Widget-Funktion der App nutzen wollen, dann könnt Ihr die Option hier aktivieren
  38. -- ACHTUNG: Solltet Ihr die Szene manuell ausführen, dann wird der Alarm gesetzt
  39. local widget = true -- false = Widget wird nicht genutzt; true = Widget wird genutzt
  40.  
  41. -- DOORLOCK-Integration
  42. -- Hier kann ein Doorlock hinzugefügt werden, was die Tür nach schärfen/entschärfen automatisch auf/zu schließt.
  43. -- Die Option kann über die Variable doorlock auf true/false (Standart ist false) gesetzt werden
  44. -- ACHTUNG: Die Funktion zum Öffnen mit RFID/Code funktioniert nur, wenn PresentState auf 'home' steht; NUTZUNG AUF EIGENE GEFAHR
  45. local doorlock = false -- false = Kein Doorlock im Einsatz; true = Doorlock soll über das Skript geschaltet werden
  46. local doorlockID = 211 -- ID des Doorlocks
  47. -- Wie soll der doorlock geöffnet werden (Falls jemand zu Hause ist und Ihr kommt zusätzlich nach Hause und wollt keinen Schlüssel nutzen)
  48. -- rfid = Über den RFID-Chip (dann kann dieser aber nicht mehr zum schärfen der Alarmanlage verwendet werden
  49. -- pin = Dann könnt Ihr mit einem zusätzlichen Code (open_code) die Tür öffnen
  50. local doorlock_open = 'pin'
  51. local open_code = {50, 50, 50, 50, 0, 0, 0, 0, 0, 0} -- <--ANPASSEN: Byte-Array für Zahlencode (1234 als Unicode)
  52. local rfid_doorlock1 = 1 -- Wenn Ihr mit dem RFID-Tag1 nur entschärfen wollt, bitte auf 1 setzen
  53. local rfid_doorlock2 = 1 -- Wenn Ihr mit dem RFID-Tag2 nur entschärfen wollt, bitte auf 1 setzen
  54. local rfid_doorlock3 = 0 -- Wenn Ihr mit dem RFID-Tag3 nur entschärfen wollt, bitte auf 1 setzen
  55. local rfid_doorlock4 = 0 -- Wenn Ihr mit dem RFID-Tag4 nur entschärfen wollt, bitte auf 1 setzen
  56.  
  57. local readerCode = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0} -- leeres Byte-Array, in dem nachher der gelesene Code steht (RFID-Tag oder Zahlencode)
  58.  
  59. -- FUNKTIONEN FÜR AKTIONEN (z.B. TTS, LICHT AUS)
  60. ------------------------------------------------
  61. -- Aktionen nach dem Schärfen mit Delay, bvor die Sensoren geschäft sind
  62. function actionsbeforeArmed()
  63. fibaro:debug('Führe eigene Funktionen vor Schärfen aus')
  64.  
  65. end
  66. -- Aktionen nach dem endgültigen Schärfen
  67. function actionsafterArmed()
  68. fibaro:debug('Führe eigene Funktionen nach dem Schärfen aus')
  69.  
  70. end
  71. -- Aktionen nach dem Entschärfen
  72. function actionsafterDisarmed()
  73. fibaro:debug('Führe eigene Funktionen nach dem Entschärfen aus')
  74.  
  75. end
  76. -------------------------------------------------
  77. -- OPTIONEN ENDE -- AB HIER NICHTS MEHR ÄNDERN --
  78.  
  79. fibaro:debug('RFID-Scene -Version 1.3- gestartet');
  80.  
  81. Debug = function ( color, message )
  82. fibaro:debug(string.format('<%s style="color:%s;">%s</%s>', "span", color, message, "span"))
  83. end
  84.  
  85. if (rfid_active3 == nil) then
  86. fibaro:debug('Keine Variable für RFID3 gesetzt; Funktion wird nicht genutzt')
  87. local rfid_active3 = 'active'
  88. end
  89.  
  90. if (rfid_active4 == nil) then
  91. fibaro:debug('Keine Variable für RFID4 gesetzt; Funktion wird nicht genutzt')
  92. local rfid_active4 = 'active'
  93. end
  94.  
  95. -- FUNKTIONEN (bitte nicht ändern)
  96. function compareCodes(array1, array2)
  97. if (#array1 ~= 10 or #array2 ~= 10) then
  98. fibaro:debug('Grösse der Arrays ungültig...')
  99. return false
  100. end
  101. for i = 1, #array1 do
  102. if (array1[i] ~= array2[i]) then
  103. return false
  104. end
  105. end
  106. return true
  107. end
  108.  
  109. function armedcheckSensorID(array)
  110. for j=1, countID do
  111. if doorID[j] ~= nil then
  112. if (tonumber(fibaro:getValue(doorID[j], 'armed')) == 0) then
  113. return false
  114. end
  115. end
  116. end
  117. return true
  118. end
  119.  
  120. local startSource = fibaro:getSourceTrigger()
  121.  
  122. if (startSource['deviceID'] == tagReader) then
  123.  
  124. local delay = 0
  125.  
  126. -- RFID auslesen
  127. local userCodes = fibaro:get(tagReader, 'userCodes')
  128. jsontbl = json.decode(userCodes)
  129.  
  130. -- nach dem Code mit der ID 0 suchen
  131. for i = 1, #jsontbl do
  132. if (jsontbl[i].id == 0) then
  133.  
  134. -- die 10 Zeichen lesen und in das leere Byte-Array abfüllen
  135. for b = 1, string.len(jsontbl[i].code) do
  136. readerCode[b] = string.byte(jsontbl[i].code,b)
  137. end
  138.  
  139. if (compareCodes(rfid1, readerCode) or compareCodes(rfid2, readerCode) or (compareCodes(rfid3, readerCode) and rfid_active3 == 'active') or (compareCodes(rfid4, readerCode) and rfid_active4 == 'active')) then
  140. if (fibaro:getGlobal('PresentState') == 'Home') then
  141.  
  142. -- Prüfung, ob RFID zum Schärfen genutzt werden darf/Zum Öffnen der Tür
  143. if (compareCodes(rfid1, readerCode) and rfid_use1 == 1) then
  144. fibaro:debug('Scene abgebrochen. Mit diesem RFID-Tag 1 dürfen die Sensoren nicht geschärft werden.')
  145. if (doorlock and rfid_doorlock1 == 1) then
  146. fibaro:debug('Doorlock vorhanden, Tür wird geöffnet.')
  147. fibaro:call(doorlockID, 'unsecure')
  148. end
  149. fibaro:abort()
  150. end
  151. ---------------ENDE PRÜFUNG--------------------------
  152. -- Prüfung, ob RFID zum Schärfen genutzt werden darf/Zum Öffnen der Tür
  153. if (compareCodes(rfid2, readerCode) and rfid_use2 == 1) then
  154. fibaro:debug('Scene abgebrochen. Mit diesem RFID-Tag 2 dürfen die Sensoren nicht geschärft werden.')
  155. if (doorlock and rfid_doorlock2 == 1) then
  156. fibaro:debug('Doorlock vorhanden, Tür wird geöffnet.')
  157. fibaro:call(doorlockID, 'unsecure')
  158. end
  159. fibaro:abort()
  160. end
  161. ---------------ENDE PRÜFUNG--------------------------
  162. -- Prüfung, ob RFID zum Schärfen genutzt werden darf/Zum Öffnen der Tür
  163. if (compareCodes(rfid3, readerCode) and rfid_use3 == 1) then
  164. fibaro:debug('Scene abgebrochen. Mit diesem RFID-Tag 3 dürfen die Sensoren nicht geschärft werden.')
  165. if (doorlock and rfid_doorlock3 == 1) then
  166. fibaro:debug('Doorlock vorhanden, Tür wird geöffnet.')
  167. fibaro:call(doorlockID, 'unsecure')
  168. end
  169. fibaro:abort()
  170. end
  171. ---------------ENDE PRÜFUNG--------------------------
  172. -- Prüfung, ob RFID zum Schärfen genutzt werden darf/Zum Öffnen der Tür
  173. if (compareCodes(rfid4, readerCode) and rfid_use4 == 1) then
  174. fibaro:debug('Scene abgebrochen. Mit diesem RFID-Tag 4 dürfen die Sensoren nicht geschärft werden.')
  175. if (doorlock and rfid_doorlock4 == 1) then
  176. fibaro:debug('Doorlock vorhanden, Tür wird geöffnet.')
  177. fibaro:call(doorlockID, 'unsecure')
  178. end
  179. fibaro:abort()
  180. end
  181.  
  182. fibaro:debug('RFID-Tag akzeptiert - Haus wurde verlassen')
  183. fibaro:setGlobal('PresentState', 'Away')
  184. if (own_action == 1) then
  185. actionsbeforeArmed()
  186. end
  187. local delay = tonumber(fibaro:getValue(doorID[1], "armDelay"))
  188. if (delay ~= 0) then
  189. fibaro:debug('Arm-Delay erkannt. Arm-Delay: ' ..delay)
  190. end
  191. for j=1, countID do
  192. if doorID[j] ~= nil then
  193. if (tonumber(fibaro:getValue(doorID[j], 'value')) == 0) then
  194. fibaro:call(doorID[j], 'setArmed', '1')
  195. else
  196. local sensorname = fibaro:getName(doorID[j])
  197. local sensorroom = fibaro:getRoomNameByDeviceID(doorID[j])
  198. fibaro:debug('ACHTUNG: ' .. sensorname .. ' im Raum: ' .. sensorroom .. ' nicht sicher. Sende Push.')
  199. for k=1, countID do
  200. if phoneID[k] ~= nil then
  201. fibaro:call(phoneID[k], 'sendPush', 'ACHTUNG: ' .. sensorname .. ' im Raum: ' .. sensorroom .. ' nicht sicher.')
  202. end
  203. end
  204. end
  205. end
  206. end
  207. fibaro:debug('Warte ' .. delay .. ' Sekunden')
  208. delay = delay + 1
  209. fibaro:sleep(delay*1000)
  210. if (fibaro:getGlobal('PresentState') == 'Away') then
  211. if (armedcheckSensorID(doorID)) then
  212. if (own_action == 1) then
  213. actionsafterArmed()
  214. end
  215. for l=1, countID do
  216. if phoneID[l] ~= nil then
  217. fibaro:call(phoneID[l], 'sendPush', 'RFID: Alarmanlage SCHARF')
  218. end
  219. end
  220. fibaro:debug('Alle Sensoren geschärft. Sende Push')
  221. if (doorlock) then
  222. fibaro:call(doorlockID, 'secure')
  223. fibaro:debug('doorlock vorhanden, Tür wurde geschlossen!')
  224. end
  225. else
  226. fibaro:debug('Es konnten nicht alle Sensoren scharf geschaltet werden')
  227. end
  228. else
  229. fibaro:debug('Alarm wurde während der Delay-Time deaktiviert')
  230. end
  231.  
  232. elseif (fibaro:getGlobal('PresentState') == 'Away') then
  233. fibaro:debug('RFID-Tag akzeptiert - Welcome@Home')
  234. fibaro:setGlobal('PresentState', 'Home')
  235. for m=1, countID do
  236. if doorID[m] ~= nil then
  237. fibaro:call(doorID[m], 'setArmed', '0')
  238. end
  239. end
  240.  
  241. if (armedcheckSensorID(doorID)) then
  242. fibaro:debug('Es konnten nicht alle Sensoren entschäft werden');
  243. for t=1, countID do
  244. if doorID[t] ~= nil then
  245. if (tonumber(fibaro:getValue(doorID[t], 'armed')) == 1) then
  246. local sensorname = fibaro:getName(doorID[t])
  247. local sensorroom = fibaro:getRoomNameByDeviceID(doorID[t])
  248. fibaro:debug('ACHTUNG: ' .. sensorname .. ' im Raum: ' .. sensorroom .. ' konnte nicht entschärft werden. Sende Push.')
  249. for o=1, countID do
  250. if phoneID[o] ~= nil then
  251. fibaro:call(phoneID[o], 'sendPush', 'ACHTUNG: ' .. sensorname .. ' im Raum: ' .. sensorroom .. ' nicht entschärft.')
  252. end
  253. end
  254. end
  255. end
  256. end
  257. else
  258. fibaro:debug('Alle Sensoren entschärft. Sende Push')
  259. if (doorlock) then
  260. fibaro:call(doorlockID, 'unsecure')
  261. fibaro:debug('doorlock vorhanden, Tür wurde geöffnet')
  262. end
  263. for l=1, countID do
  264. if phoneID[l] ~= nil then
  265. fibaro:call(phoneID[l], 'sendPush', 'RFID: Alarmanlage entschärft')
  266. end
  267. end
  268. if (own_action == 1) then
  269. actionsafterDisarmed()
  270. end
  271. end
  272.  
  273. else
  274. fibaro:debug('RFID-Tag akzeptiert - Variablen nicht korrekt gesetzt.')
  275. end
  276.  
  277. elseif (compareCodes(code, readerCode)) then
  278. fibaro:debug('PIN-Code akzeptiert.')
  279. fibaro:setGlobal('PresentState', 'Away')
  280. for z=1, countID do
  281. if doorID[z] ~= nil then
  282. if (tonumber(fibaro:getValue(doorID[z], 'value')) == 0) then
  283. fibaro:call(doorID[z], 'setArmed', '1')
  284. else
  285. local sensorname = fibaro:getName(doorID[z])
  286. local sensorroom = fibaro:getRoomNameByDeviceID(doorID[z])
  287. fibaro:debug('ACHTUNG: ' .. sensorname .. ' im Raum: ' .. sensorroom .. ' nicht sicher. Sende Push.')
  288. for y=1, countID do
  289. if phoneID[y] ~= nil then
  290. fibaro:call(phoneID[y], 'sendPush', 'ACHTUNG: ' .. sensorname .. ' im Raum: ' .. sensorroom .. ' nicht sicher.')
  291. end
  292. end
  293. end
  294. end
  295. end
  296. if (own_action == 1) then
  297. actionsbeforeArmed()
  298. end
  299. local delay = tonumber(fibaro:getValue(doorID[1], "armDelay"))
  300. if (delay ~= 0) then
  301. fibaro:debug('Arm-Delay erkannt. Arm-Delay: ' ..delay)
  302. end
  303. fibaro:debug('Warte ' .. delay .. ' Sekunden')
  304. delay = delay + 1
  305. fibaro:sleep(delay*1000)
  306. if (fibaro:getGlobal('PresentState') == 'Away') then
  307. if (armedcheckSensorID(doorID)) then
  308. if (own_action == 1) then
  309. actionsafterArmed()
  310. end
  311. for l=1, countID do
  312. if phoneID[l] ~= nil then
  313. fibaro:call(phoneID[l], 'sendPush', 'PIN-CODE: Alarmanlage SCHARF')
  314. end
  315. end
  316. fibaro:debug('Alle Sensoren geschärft. Sende Push')
  317. if (doorlock) then
  318. fibaro:call(doorlockID, 'secure')
  319. fibaro:debug('doorlock vorhanden, Tür wurde geschlossen')
  320. end
  321. else
  322. fibaro:debug('Es konnten nicht alle Sensoren scharf geschaltet werden');
  323. end
  324. else
  325. fibaro:debug('Alarm wurde während der Delay-Time deaktiviert');
  326. end
  327.  
  328. elseif (compareCodes(open_code, readerCode) and fibaro:getGlobal('PresentState') == 'Home' and doorlock_open == 'pin') then
  329. fibaro:debug('PIN-Code zum Öffnen der Tür akzeptiert.')
  330. if (doorlock) then
  331. fibaro:call(doorlockID, 'unsecure')
  332. fibaro:debug('doorlock vorhanden, es war schon jemand zu Hause, Tür wird geöffnet')
  333. for r=1, countID do
  334. if phoneID[r] ~= nil then
  335. fibaro:call(phoneID[r], 'sendPush', 'Tür würde mit PIN geöffnet')
  336. end
  337. end
  338. end
  339. else
  340. fibaro:debug('RFID-Tag/PIN-Code wurde abgelehnt. Manipulation oder Karte inaktiv? Push versendet')
  341. for r=1, countID do
  342. if phoneID[r] ~= nil then
  343. fibaro:call(phoneID[r], 'sendPush', 'ACHTUNG: Code falsch eingegeben/RFID inaktiv')
  344. end
  345. end
  346. end
  347. end
  348. end
  349. else
  350. if (widget) then
  351. if (fibaro:getGlobal('PresentState') == 'Home') then
  352. fibaro:debug('Szene durch Widget gestartet - Haus wurde verlassen')
  353. fibaro:setGlobal('PresentState', 'Away')
  354. if (own_action == 1) then
  355. actionsbeforeArmed()
  356. end
  357. local delay = tonumber(fibaro:getValue(doorID[1], "armDelay"))
  358. if (delay ~= 0) then
  359. fibaro:debug('Arm-Delay erkannt. Arm-Delay: ' ..delay)
  360. end
  361. for j=1, countID do
  362. if doorID[j] ~= nil then
  363. if (tonumber(fibaro:getValue(doorID[j], 'value')) == 0) then
  364. fibaro:call(doorID[j], 'setArmed', '1')
  365. else
  366. local sensorname = fibaro:getName(doorID[j])
  367. local sensorroom = fibaro:getRoomNameByDeviceID(doorID[j])
  368. fibaro:debug('ACHTUNG: ' .. sensorname .. ' im Raum: ' .. sensorroom .. ' nicht sicher. Sende Push.')
  369. for k=1, countID do
  370. if phoneID[k] ~= nil then
  371. fibaro:call(phoneID[k], 'sendPush', 'ACHTUNG: ' .. sensorname .. ' im Raum: ' .. sensorroom .. ' nicht sicher.')
  372. end
  373. end
  374. end
  375. end
  376. end
  377. fibaro:debug('Warte ' .. delay .. ' Sekunden')
  378. delay = delay + 1
  379. fibaro:sleep(delay*1000)
  380. if (fibaro:getGlobal('PresentState') == 'Away') then
  381. if (armedcheckSensorID(doorID)) then
  382. if (own_action == 1) then
  383. actionsafterArmed()
  384. end
  385. for l=1, countID do
  386. if phoneID[l] ~= nil then
  387. fibaro:call(phoneID[l], 'sendPush', 'Widget: Alarmanlage SCHARF')
  388. end
  389. end
  390. fibaro:debug('Alle Sensoren geschärft. Sende Push')
  391. if (doorlock) then
  392. fibaro:call(doorlockID, 'secure')
  393. fibaro:debug('doorlock vorhanden, Tür wurde geschlossen!')
  394. end
  395. else
  396. fibaro:debug('Es konnten nicht alle Sensoren scharf geschaltet werden')
  397. end
  398. else
  399. fibaro:debug('Alarm wurde während der Delay-Time deaktiviert')
  400. end
  401. elseif (fibaro:getGlobal('PresentState') == 'Away') then
  402. fibaro:debug('Szene durch Widget gestartet - Welcome@Home')
  403. fibaro:setGlobal('PresentState', 'Home')
  404. for m=1, countID do
  405. if doorID[m] ~= nil then
  406. fibaro:call(doorID[m], 'setArmed', '0')
  407. end
  408. end
  409. if (armedcheckSensorID(doorID)) then
  410. fibaro:debug('Es konnten nicht alle Sensoren entschäft werden');
  411. for t=1, countID do
  412. if doorID[t] ~= nil then
  413. if (tonumber(fibaro:getValue(doorID[t], 'armed')) == 1) then
  414. local sensorname = fibaro:getName(doorID[t])
  415. local sensorroom = fibaro:getRoomNameByDeviceID(doorID[t])
  416. fibaro:debug('ACHTUNG: ' .. sensorname .. ' im Raum: ' .. sensorroom .. ' konnte nicht entschärft werden. Sende Push.')
  417. for o=1, countID do
  418. if phoneID[o] ~= nil then
  419. fibaro:call(phoneID[o], 'sendPush', 'ACHTUNG: ' .. sensorname .. ' im Raum: ' .. sensorroom .. ' nicht entschärft.')
  420. end
  421. end
  422. end
  423. end
  424. end
  425. else
  426. fibaro:debug('Alle Sensoren entschärft. Sende Push')
  427. if (doorlock) then
  428. fibaro:call(doorlockID, 'unsecure')
  429. fibaro:debug('doorlock vorhanden, Tür wurde geöffnet')
  430. end
  431. for l=1, countID do
  432. if phoneID[l] ~= nil then
  433. fibaro:call(phoneID[l], 'sendPush', 'Widget: Alarmanlage entschärft')
  434. end
  435. end
  436. if (own_action == 1) then
  437. actionsafterDisarmed()
  438. end
  439. end
  440. end
  441.  
  442. else
  443. fibaro:debug('Szene manuell gestartet. Auslesen der Informationen')
  444. local userCodes = fibaro:get(tagReader, 'userCodes')
  445. jsontbl = json.decode(userCodes)
  446.  
  447. -- nach dem Code mit der ID 0 suchen
  448. for i = 1, #jsontbl do
  449. if (jsontbl[i].id == 0) then
  450.  
  451. -- die 10 Zeichen lesen und in das leere Byte-Array abfüllen
  452. for b = 1, string.len(jsontbl[i].code) do
  453. readerCode[b] = string.byte(jsontbl[i].code,b)
  454. end
  455. fibaro:debug('RFID-INFO: {' .. readerCode[1] .. ', ' .. readerCode[2] .. ', ' .. readerCode[3] .. ', ' .. readerCode[4] .. ', ' .. readerCode[5] .. ', ' .. readerCode[6] .. ', ' .. readerCode[7] .. ', ' .. readerCode[8] .. ', ' .. readerCode[9] .. ', ' .. readerCode[10] .. '}')
  456. end
  457. end
  458. fibaro:debug('Diese Info in die lokalen Arrays rfid1,rfid2,code eintragen')
  459. if (fibaro:getGlobal('PresentState') ~= nil) then
  460. local PresentState = fibaro:getGlobal('PresentState')
  461. Debug( 'green', 'Die Variable PresentState wurde gefunden. Status: ' ..PresentState)
  462. else
  463. Debug( 'red', 'Die Variable PresentState wurde nicht gefunden. Bitte einrichten! rfid_alarm wird nicht mehr unterstützt.')
  464. end
  465. local delay = tonumber(fibaro:getValue(doorID[1], 'armDelay'))
  466. if (delay ~= 0) then
  467. fibaro:debug('Arm-Delay erkannt. Arm-Delay: ' ..delay)
  468. else
  469. fibaro:debug('Kein Arm-Delay erkannt.')
  470. end
  471. if (doorlock) then
  472. Debug( 'green', 'doorlock mit der ID ' ..doorlockID.. ' erkannt');
  473. else
  474. fibaro:debug('Kein doorlock erkannt')
  475. end
  476. if (doorlock) then
  477. if (doorlock_open == 'rfid') then
  478. Debug( 'white', 'doorlock soll mit den RFID-Tags geöffnet werden können. Prüfe Abhängigkeiten.')
  479. local error_rfid = 0
  480. if (rfid_use1 == 0 and rfid_doorlock1 == 1) then
  481. Debug( 'red', 'RFID-Tag 1 soll zum Schärfen und zum Öffnen genutzt werden. Dies ist nicht möglich. Bitte ändern!')
  482. error_rfid = 1
  483. end
  484. if (rfid_use2 == 0 and rfid_doorlock2 == 1) then
  485. Debug( 'red', 'RFID-Tag 2 soll zum Schärfen und zum Öffnen genutzt werden. Dies ist nicht möglich. Bitte ändern!')
  486. error_rfid = 1
  487. end
  488. if (rfid_use3 == 0 and rfid_doorlock3 == 1) then
  489. Debug( 'red', 'RFID-Tag 3 soll zum Schärfen und zum Öffnen genutzt werden. Dies ist nicht möglich. Bitte ändern!')
  490. error_rfid = 1
  491. end
  492. if (rfid_use4 == 0 and rfid_doorlock4 == 1) then
  493. Debug( 'red', 'RFID-Tag 4 soll zum Schärfen und zum Öffnen genutzt werden. Dies ist nicht möglich. Bitte ändern!')
  494. error_rfid = 1
  495. end
  496. if (error_rfid == 0) then
  497. Debug( 'green', 'Abhängigkeiten bei den RFID-Tags in Ordnung')
  498. end
  499. elseif (doorlock_open == 'pin') then
  500. Debug( 'white', 'doorlock soll mit einem PIN geöffnet werden. Prüfe PINs.')
  501. if (compareCodes(code, open_code)) then
  502. Debug( 'red', 'Die PINs zum öffnen und schärfen sind gleich, bitte einen ändern.')
  503. else
  504. Debug( 'green', 'Die PINs sind in Ordnung')
  505. end
  506. end
  507. end
  508. end
  509. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement