Thanks for all the positive comments. I do understand the perceived higher costs associated with industrial PLCs. Mostly, they are too high for homeowners, even me, but, Automation Direct's PLCs pop up all of the time on EBay for very affordable prices. It seems the 205 series is quite prevalent due to its small size and modular design for great scalability. I started out with a DL06 series, but outgrew it in a matter of weeks and jumped up to the 405 series PLC. All but the older 305 platforms have great communication capabilities including modbus. Co-processors can be added to custom write an serial protocols as long as you can get the publications on the protocols. The software is rather affordable too, unlike others, about $400. Sorry to ramble, I'm not associated with AD at all, I just think they're super alternatives for HA/Security stuff.
They also offer HMIs, but I haven't used them. I use another solution.
Nice set up! I, too have wondered about the use of industrial automation gear in the home and am still in process. I'm particularly interested in how you've set up your exterior lights to be controlled with standard switches and by the PLC. Are you using regular 3-way switches with some logic on the PLC to keep the status correct?
Thanks, the wiring is quite simple for my outside lights. I have PLC output to a relay. A contact on the relay is wired in parallel with the standard light switch. If either switch (relay contact or toggle) the light is on. The PLC doesn't override or vice versa. I have one relay for every outside light. I did this prior to my UPB implementation. I didn't care to have my outside perimeter lights dim, so I could live with on/off control and decided to wire in parallel so I still have manual control at the standard toggle.
View attachment 1241
When I discovered UPB, I was thrilled that the protocol was open so I could integrate it in my PLC system to keep things centrallized. I've had UPB devices for a year now and have no regrets, although they are quite expensive.
The basic program for my UPB interface is below. This is written for a F4-CP128-1. I use shared memory varialbes from the PLC for controlling the protocol from the ladder which is where all my HA/Security is. So if my smoke detectors are tripped or if my alarm system is tripped, all my inside lights come on through UPB commands...and some other stuff happens too...like if my wife burns my dinner and trips the kitchen smoke I get a text message so I know to stop at the drive through!
-------------------------------------------------------------------------------------------------------------------
1 STRING 11326,150 : REM UPBCommsTX14K1.abm
2 DIM I(100)
3 SETPORT 1,115200,N,8,1,N : REM Programming/Debug
4 SETPORT 2,4800,N,8,1,H,P : REM UPB Device
5 PRINT2 CHR$(23),"70038D",CR : REM turn on pulse mode with no idle "--'s"
6 PRINT1 CHR$(23),"70038D"," Pulse No IDLE"
REM ______________________________________________________________
7 P."Line 8": IF S405_C(410) THEN GOTO 21 ELSE GOTO 8
8 P."Line 9": IF S405_C(411) THEN GOTO 308 ELSE GOTO 9
9 SETINPUT 1,0,S405_VH(22000),S405_VH(22001),S405_VH(22002),S405_VH(22003)
10 INLEN2=0
11 DO
12 Q=Q+1: P. "<",Q,">" : IF Q>100 THEN Q=0
13 INPUT2, $(0)
14 IF LEN($(0))>5 THEN GOSUB 5000
15 UNTIL S405_C(411).OR.S405_C(410)
16 GOTO 7
REM ______________________________________________________________
REM Sum connsecutive registers for checksum calculation (8 words)
21 Q=S405_VH(14000)+S405_VH(14001)+S405_VH(14002)+S405_VH(14003)
22 R=S405_VH(14004)+S405_VH(14005)+S405_VH(14006)+S405_VH(14007)
23 S=Q+R
24 P."Requesting Data":REM P. ">>>" : P."Sum = ", S
REM ______________________________________________________________
REM Load VRegisters and print value
25 I(0)=S405_VH(14000) :I(1)=S405_VH(14001)
26 I(2)=S405_VH(14002) :I(3)=S405_VH(14003)
27 I(4)=S405_VH(14004) :I(5)=S405_VH(14005)
28 I(6)=S405_VH(14006) :I(7)=S405_VH(14007)
29 $(10)=CHR$(I(0))+CHR$(I(1))+CHR$(I(2))+CHR$(I(3))+CHR$(I(4))+CHR$(I(5))
30 $(11)=CHR$(I(6))+CHR$(I(7))
REM ______________________________________________________________
REM Calculate Checksum
31 S=0 : FOR X=1TO6 : REM sum header
32 S=S+ASC($(10),X)
34 NEXT X
36 REM P."S = ", S
48 C=0
50 C=NOT(S)+1 : REM invert and add 1
52 C=C.AND.0FFH : REM mask off high byte
54 REM P. "HEX Mask = ", HEX$(C,1)
REM ______________________________________________________________
REM Append leading "0" in Hex value for place holder if necessary
60 IF I(0)<17 THEN $(20)="0" + HEX$(I(0),1) ELSE $(20)=HEX$(I(0),1)
61 IF I(1)<17 THEN $(21)="0" + HEX$(I(1),1) ELSE $(21)=HEX$(I(1),1)
62 IF I(2)<17 THEN $(22)="0" + HEX$(I(2),1) ELSE $(22)=HEX$(I(2),1)
63 IF I(3)<17 THEN $(23)="0" + HEX$(I(3),1) ELSE $(23)=HEX$(I(3),1)
64 IF I(4)<17 THEN $(24)="0" + HEX$(I(4),1) ELSE $(24)=HEX$(I(4),1)
65 IF I(5)<17 THEN $(25)="0" + HEX$(I(5),1) ELSE $(25)=HEX$(I(5),1)
66 IF I(6)<17 THEN $(26)="0" + HEX$(I(6),1) ELSE $(26)=HEX$(I(6),1)
67 IF I(7)<17 THEN $(27)="0" + HEX$(I(7),1) ELSE $(27)=HEX$(I(7),1)
68 IF C<10 THEN $(28)="0" + HEX$(C,1) ELSE $(28)=HEX$(C,1)
69 REM P. "S20=",$(20)," |S21=",$(21)," |S22=",$(22)," |S23=",$(23)
70 REM P. "S24=",$(24)," |S25=",$(25)," |S26=",$(26)," |S27=",$(27)
71 REM P. "S24=",$(28)
REM ______________________________________________________________
REM Print final PROTOCOL!!
155 $(0)=CHR$(20)
165 REM P.">>>>",$(0),$(20),$(21),$(22),$(23),$(24),$(25),$(28)
REM ______________________________________________________________
REM UPB PIM Comms.
199 T(0)=S405_VH(16011): REM P."T(0)= ",T(0)
200 SETINPUT 1,0,S405_VH(16003),S405_VH(16002),S405_VH(16000),S405_VH(16001)
201 $(30)="" : INLEN2=0
202 REM P. "Setinput= ",S405_VH(16003),SPC(1),S405_VH(16002)
203 REM P. "Setinput= ",S405_VH(16000),SPC(1),S405_VH(16001)
204 DELAY S405_VH(16007)
REM $(1)=$(0),$(20),$(21),$(22),$(23),$(24),$(25),$(28)
205 PRINT2 $(0),$(20),$(21),$(22),$(23),$(24),$(25),$(28),CR
207 DO
208 C(0)=C(0)+1 : DELAY S405_VB(16010)
209 REM P. "Cnt= ",C(0), " "
210 WHILE C(0)<T(0).AND.INLEN2<S405_VH(16005)
211 REM P. "Final Count= ", C(0)
212 C(0)=0 : REM P. "Rst Final Cnt= ", C(0)
213 INPUT2 ,$(30) : $(33)=$(30)
220 GOSUB 1010
221 IF C4=CK8 THEN GOTO 224 ELSE GOTO 223
223 P. "FAIL FAIL FAIL FAIL FAIL FAIL" : DELAY S405_VB(16004) : GOTO 298
224 P. "PASS *** PASS *** PASS *** PASS *** PASS *** " : DELAY S405_VB(16004)
225 S405_C(410)=0 : P. "C410 is OFF"
REM 274 S405_VB(14050)=ASC($(30),1)
275 S405_VB(14051)=ASC($(30),2) : KVL(0)=ASC($(30),2)
276 S405_VB(14052)=ASC($(30),3) : KVL(1)=ASC($(30),3)
277 S405_VB(14053)=ASC($(30),4)
278 S405_VB(14054)=ASC($(30),5)
279 S405_VB(14055)=ASC($(30),6)
280 S405_VB(14056)=ASC($(30),7)
281 S405_VB(14057)=ASC($(30),8)
282 S405_VB(14060)=ASC($(30),9)
283 S405_VB(14061)=ASC($(30),10)
284 S405_VB(14062)=ASC($(30),11)
285 S405_VB(14063)=ASC($(30),12)
286 S405_VB(14064)=ASC($(30),13)
287 S405_VB(14065)=ASC($(30),14)
288 S405_VB(14066)=ASC($(30),15)
289 REM P."S30= ",$(30),CR,"I(10)= ",I(10),CR,"L= ",LEFT$(RIGHT$($(30),4),2)
290 $(31)=LEFT$(RIGHT$($(30),4),2): REM P. "S31= ",$(31)
291 LVL(0)=VAL("0"+$(31)+"H") : IN2(0)=INPLEN
292 IF KVL(0)=85.AND.(LVL(0)>=0.AND.LVL(0)<=64).AND.IN2(0)<4 THEN GOTO 293
293 IF KVL(1)<>13 THEN S405_VH(14030)=VAL("0"+$(31)+"H")
294 REM P. "KVL= ",KVL(0), CR, "LVL= ",LVL(0), CR, "Length= ",IN2(0)
295 $(30)="" : $(31)="" : INLEN2=0
REM ______________________________________________________________
REM END of light level request
298 DELAY S405_VH(16006)
299 GOTO 7
REM ______________________________________________________________
REM Sum connsecutive registers for checksum calculation (8 words)
308 M=S405_VH(15000)+S405_VH(15001)+S405_VH(15002)+S405_VH(15003)
309 N=S405_VH(15004)+S405_VH(15005)+S405_VH(15006)+S405_VH(15007)
310 L=M+N
311 P."Commanding":REM P. ">>>" : P."Sum = ", L
REM ______________________________________________________________
REM Load VRegisters and print value
320 I(50)=S405_VH(15000) : REM P."R0= ",I(50)
321 I(51)=S405_VH(15001) : REM P."R1= ",I(51)
322 I(52)=S405_VH(15002) : REM P."R2= ",I(52)
323 I(53)=S405_VH(15003) : REM P."R3= ",I(53)
324 I(54)=S405_VH(15004) : REM P."R4= ",I(54)
325 I(55)=S405_VH(15005) : REM P."R5= ",I(55)
326 I(56)=S405_VH(15006) : REM P."R6= ",I(56)
327 I(57)=S405_VH(15007) : REM P."R7= ",I(57)
329 $(40)=CHR$(I(50))+CHR$(I(51))+CHR$(I(52))+CHR$(I(53))
330 $(41)=CHR$(I(54))+CHR$(I(55))+CHR$(I(56))+CHR$(I(57))
REM ______________________________________________________________
REM Calculate Checksum
331 L=0 : FOR X=1TO4 : REM sum header
332 L=L+ASC($(40),X)
333 NEXT X
334 U=0 : For Q=1to4
335 U=U+ASC($(41),Q)
336 NEXT Q
337 A=L+U
338 REM P."A = ", A
348 C2=0
350 C2=NOT(A)+1 : REM invert and add 1
352 C2=C2.AND.0FFH : REM mask off high byte
354 REM P. "HEX Mask = ", HEX$(C2,1)
REM ______________________________________________________________
REM Append leading "0" in Hex value for place holder if necessary
360 IF I(50)<16 THEN $(50)="0" + HEX$(I(50),1) ELSE $(50)=HEX$(I(50),1)
361 IF I(51)<16 THEN $(51)="0" + HEX$(I(51),1) ELSE $(51)=HEX$(I(51),1)
362 IF I(52)<16 THEN $(52)="0" + HEX$(I(52),1) ELSE $(52)=HEX$(I(52),1)
363 IF I(53)<16 THEN $(53)="0" + HEX$(I(53),1) ELSE $(53)=HEX$(I(53),1)
364 IF I(54)<16 THEN $(54)="0" + HEX$(I(54),1) ELSE $(54)=HEX$(I(54),1)
365 IF I(55)<16 THEN $(55)="0" + HEX$(I(55),1) ELSE $(55)=HEX$(I(55),1)
366 IF I(56)<16 THEN $(56)="0" + HEX$(I(56),1) ELSE $(56)=HEX$(I(56),1)
367 IF I(57)<16 THEN $(57)="0" + HEX$(I(57),1) ELSE $(57)=HEX$(I(57),1)
368 IF C2<16 THEN $(58)="0" + HEX$(c2,1) ELSE $(58)=HEX$(c2,1)
369 REM P. "S50=",$(50)," |S51=",$(51)," |S52=",$(52)," |S53=",$(53)
370 REM P. "S54=",$(54)," |S55=",$(55)," |S56=",$(56)," |S57=",$(57)
371 REM P. "S58=",$(58)
REM ______________________________________________________________
REM Print final PROTOCOL!!
455 $(0)=CHR$(20)
REM 465 P.">>>>",$(0),$(50),$(51),$(52),$(53),$(54),$(55),$(56),$(57),$(58)
REM ______________________________________________________________
REM UPB PIM Comms.
499 T(0)=S405_VH(16031):REM P."T(0)= ",T(0)
500 SETINPUT 1,0,S405_VH(16023),S405_VH(16022),S405_VH(16020),S405_VH(16021)
501 $(60)="" : INLEN2=0
502 REM P. "Setinput =",S405_VH(16023),SPC(1),S405_VH(16022)
503 REM P. "Setinput =",S405_VH(16020),SPC(1),S405_VH(16021)
504 REM DELAY S405_VH(16027)
505 PRINT2 $(0),$(50),$(51),$(52),$(53),$(54),$(55),$(56),$(57),$(58),CR
519 DO
520 C(0)=C(0)+1 : DELAY S405_VB(16030)
521 REM P. "Cnt= ",C(0), " "
522 WHILE C(0)<T(0).AND.INLEN2<S405_VH(16025)
523 REM P. "Final Count= ", C(0)
524 C(0)=0 : REM P. "Rst Final Cnt= ", C(0)
525 INPUT2 ,$(60)
526 REM P."S60= ",$(60)
530 $(61)=RIGHT$($(60),1)
531 REM P. "$61= ", $(61)," ",ASC($(61),1)
532 IF ASC($(61),1) = 75 THEN GOTO 534 ELSE GOTO 533
533 P. "FAIL FAIL FAIL FAIL FAIL FAIL" : DELAY S405_VB(16004) : GOTO 1000
534 P. "PASS *** PASS *** PASS *** PASS *** PASS *** " : DELAY S405_VB(16004)
535 S405_C(411)=0 : P. "C411 is OFF"
540 S405_VB(15050)=ASC($(60),1)
545 S405_VB(15051)=ASC($(60),2)
550 S405_VB(15052)=ASC($(60),3)
551 S405_VB(15053)=ASC($(60),4)
552 S405_VB(15054)=ASC($(60),5)
553 S405_VB(15055)=ASC($(60),6)
554 S405_VB(15056)=ASC($(60),7)
555 S405_VB(15057)=ASC($(60),8)
556 IN2(1)=INPLEN
557 REM P."Length= ",IN2(1)
560 $(60)= "" : INLEN2=0
REM ______________________________________________________________
999 DELAY S405_VH(16026)
1000 GOTO 8
REM ______________________________________________________________
REM Calculate Checksum on return message of request string
REM ______________________________________________________________
1010 REM S30= ?}CU5PK PU 08 00 FA FF 01 86 64 14
1015 REM P. "$(33)= ",$(33)
1020 $(34)=RIGHT$($(33),16) : REM$(34)= :08 00 FA FF 01 86 64 14
1021 REM P. "$(34)= ",$(34)
1026 $(1)=LEFT$($(34),2) :REM P. "$(1)= ",$(1)
1030 CK1=VAL("0"+LEFT$($(34),2)+"H")
1031 REM P. "CK1= ",CK1 :REM 08
1040 CK2=VAL("0"+RIGHT$(LEFT$($(34),4),2)+"H") :REM 00
1050 CK3=VAL("0"+RIGHT$(LEFT$($(34),6),2)+"H") :REM FA
1060 CK4=VAL("0"+RIGHT$(LEFT$($(34),8),2)+"H") :REM FF
1070 CK5=VAL("0"+RIGHT$(LEFT$($(34),10),2)+"H") :REM 01
1080 CK6=VAL("0"+RIGHT$(LEFT$($(34),12),2)+"H") :REM 86
1090 CK7=VAL("0"+RIGHT$(LEFT$($(34),14),2)+"H") :REM 64 <<< Argument
1091 CK8=VAL("0"+RIGHT$(LEFT$($(34),16),2)+"H") :REM 14 <<< Checksum
1119 REM P. CK1," ",CK2," ",CK3," ",CK4," ",CK5," ",CK6," ",CK7," ",CK8
1120 C3=CK1+CK2+CK3+CK4+CK5+CK6+CK7
1125 IF C3>10 THEN GOTO 1140 ELSE GOTO 1190
1140 REM P. "C3= ",C3
1150 C4=0
1151 C4=NOT(C3)+1
1152 C4=C4.AND.0FFH
1153 REM P. "C4= ",C4
1154 REM P. "CK8= ",CK8
1190 RETURN
REM ______________________________________________________________
REM UPB Message Detected SUB
5000 P. CR,"---<< !UPB Message Detected! >>---",CR
5002 $(5)="P"

."$(5)= ",$(5),CR
5003 IF INSTR($(0),$(5))=0 THEN GOTO 5996
5004 P.$(5)," a Found at: ", INSTR($(0),$(19))
5005 S=INSTR($(0),$(5)): P. "S= ", S
5006 L=LEN($(0)) : P."L=",L
5007 T=L-S: P."T= ", T
5010 $(1)=RIGHT$($(0),T): P."$(1)= ",$(1)
REM 5010 $(1)=LEFT$($(0),20) : P."$(1)=",$(1),CR,"LEN=",LEN($(1))
5020 CK1=VAL("0"+RIGHT$(LEFT$($(1),3),2)+"H")
5021 CK2=VAL("0"+RIGHT$(LEFT$($(1),5),2)+"H")
5022 CK3=VAL("0"+RIGHT$(LEFT$($(1),7),2)+"H")
5023 CK4=VAL("0"+RIGHT$(LEFT$($(1),9),2)+"H")
5024 CK5=VAL("0"+RIGHT$(LEFT$($(1),11),2)+"H")
5025 CK6=VAL("0"+RIGHT$(LEFT$($(1),13),2)+"H")
5026 CK7=VAL("0"+RIGHT$(LEFT$($(1),15),2)+"H")
5027 CK8=VAL("0"+RIGHT$(LEFT$($(1),17),2)+"H")
5028 CK9=VAL("0"+RIGHT$(LEFT$($(1),19),2)+"H")
5050 P. CK1," ",CK2," ",CK3," ",CK4," ",CK5," ",CK6," ",CK7," ",CK8," ",CK9
5060 C4=CK1+CK2+CK3+CK4+CK5+CK6+CK7 : GOTO 5065
5061 C4=CK1+CK2+CK3+CK4+CK5+CK6+CK7 : GOTO 5079
5065 IF C4>10 THEN GOTO 5070 ELSE GOTO 5998
5070 P. "R1 C4= ",C4
5071 C5=0
5072 C5=NOT(C4)+1
5073 C5=C5.AND.0FFH
5074 P. "r1 C5= ",C5
5075 P. "CK9= ",CK9,CR : GOTO 5098
5079 IF C4>10 THEN GOTO 5080 ELSE GOTO 5998
5080 P. "R2 C4= ",C4
5081 C5=0
5082 C5=NOT(C4)+2
5083 C5=C5.AND.0FFH
5084 P. "r2 C5= ",C5
5085 P. "CK9= ",CK9 : GOTO 5099
5098 IF C5=CK9 THEN GOTO 5100 ELSE GOTO 5997 :REM CKSM round 1
5099 IF C5=CK9 THEN GOTO 5100 ELSE GOTO 5998 :REM CKSM round 2
5100 DPORT(0)=CK1
5101 DPORT(2)=CK2
5102 DPORT(4)=CK3
5103 DPORT(6)=CK4
5104 DPORT(8)=CK5
5105 DPORT(10)=CK6
5106 DPORT(12)=CK7
5107 DPORT(14)=CK8
5108 DPORT(16)=CK9
5120 BMOVE W, VH(22100),K(18)
5990 P. "Success" : DELAY S405_VH(22010): GOTO 5999
5996 P. "INSTR error" : GOTO 6000
5997 P. "Checksum error 1" : GOTO 5061
5998 P. "Checksum error 2" : GOTO 6000
5999 $(0)=""
6000 RETURN
-------------------------------------------------------------------------------------------------------------------
As far as the DVR acquisition board, I think the NV7000 is discontinued, not the NV7000H - this one supports H.264 hardware compression and is relatively new. Anyway, I wish aver would open up the modbus protocol so I can integrate it with my PLC by modbus, not limited to the number of hardware i/o.