NiklasO

IVT to Domoticz

Jul 13th, 2016
147
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. commandArray = {}
  2. if uservariablechanged['IVTData'] then
  3.  
  4. ivtdata = uservariables["IVTData"]
  5.  
  6. function split(str,sep)
  7.     local array = {}
  8.     local reg = string.format("([^%s]+)",sep)
  9.     for mem in string.gmatch(str,reg) do
  10.         table.insert(array, mem)
  11.     end
  12.     return array
  13. end
  14.  
  15. -- A function in Lua similar to PHP's print_r, from http://luanet.net/lua/function/print_r
  16.  
  17. function print_r ( t )
  18.     local print_r_cache={}
  19.     local function sub_print_r(t,indent)
  20.         if (print_r_cache[tostring(t)]) then
  21.             print(indent.."*"..tostring(t))
  22.         else
  23.             print_r_cache[tostring(t)]=true
  24.             if (type(t)=="table") then
  25.                 for pos,val in pairs(t) do
  26.                     if (type(val)=="table") then
  27.                         print(indent.."["..pos.."] => "..tostring(t).." {")
  28.                         sub_print_r(val,indent..string.rep(" ",string.len(pos)+8))
  29.                         print(indent..string.rep(" ",string.len(pos)+6).."}")
  30.                     else
  31.                         print(indent.."["..pos.."] => "..tostring(val))
  32.                     end
  33.                 end
  34.             else
  35.                 print(indent..tostring(t))
  36.             end
  37.         end
  38.     end
  39.     sub_print_r(t,"  ")
  40. end
  41.  
  42. local array = split(ivtdata,";")
  43.  
  44. lopnr = array[1]
  45. framled_GT1 = array[2]
  46. ute_GT2 = array[3]
  47. tappvarmvatten_GT3_1 = array[4]
  48. varmvatten_GT3_2 = array[5]
  49. varmevatten_GT3_3 = array[6]
  50. rumstemp_GT5 = array[7]
  51. hetgastemperatur_GT6 = array[8]
  52. externgivare_temp_GT3_4 = array[9]
  53. tryckvakt_avfrost_GP3 = array[10]
  54. tryckvakt_hogtryck_HP = array[11]
  55. tryckvakt_logtryck_LP = array[12]
  56. externgivare_semester = array[13]
  57. kompressor_drift = array[14]
  58. schunt_oppna_SV1 = array[15]
  59. schunt_stang_SV1 = array[16]
  60. cirkpump_P1 = array[17]
  61. pryl_18 = array[18]
  62. larm = array[19]
  63. pryl_20 = array[20]
  64. pryl_21 = array[21]
  65. pryl_22 = array[22]
  66. borvarde_framledning_GT3_1 = array[23]
  67. pryl_24 = array[24]
  68. pryl_25 = array[25]
  69. pryl_26 = array[26]
  70. pryl_27 = array[27]
  71. pryl_28 = array[28]
  72. pryl_29 = array[29]
  73. extra_varmvatten1 = array[30]
  74. extra_varmvatten2 = array[31]
  75. extra_varmvatten3 = array[32]
  76. pryl_33 = array[33]
  77. elpatron1 = array[34]
  78. pryl_35 = array[35]
  79. elpatron2 = array[36]
  80. pryl_37 = array[37]
  81. pi_temp = array[38]
  82.  
  83. --print_r(array)
  84.  
  85. commandArray[#commandArray+1] = {['UpdateDevice'] = 436 .. '|0|' .. hetgastemperatur_GT6/10}
  86. commandArray[#commandArray+1] = {['UpdateDevice'] = 437 .. '|0|' .. ute_GT2/10}
  87. commandArray[#commandArray+1] = {['UpdateDevice'] = 440 .. '|0|' .. tappvarmvatten_GT3_1/10}
  88. commandArray[#commandArray+1] = {['UpdateDevice'] = 441 .. '|0|' .. varmvatten_GT3_2/10}
  89. commandArray[#commandArray+1] = {['UpdateDevice'] = 442 .. '|0|' .. varmevatten_GT3_3/10}
  90. commandArray[#commandArray+1] = {['UpdateDevice'] = 443 .. '|0|' .. framled_GT1/10}
  91. commandArray[#commandArray+1] = {['UpdateDevice'] = 444 .. '|0|' .. pi_temp}
  92. commandArray[#commandArray+1] = {['UpdateDevice'] = 449 .. '|0|' .. lopnr}
  93. --commandArray[#commandArray+1] = {['UpdateDevice'] = 450 .. '|0|' .. ivtdata}
  94. commandArray[#commandArray+1] = {['UpdateDevice'] = 451 .. '|0|' .. borvarde_framledning_GT3_1/10}
  95. --commandArray[#commandArray+1] = {['Variable:IVTDataTimestamp'] = tostring(os.time())}
  96.  
  97.  
  98. if (kompressor_drift == '1' and otherdevices['VP kompressor'] == 'Off') then
  99.     commandArray[#commandArray+1]={['VP kompressor']='On'}
  100. end
  101.  
  102. if (kompressor_drift == '0' and otherdevices['VP kompressor'] == 'On') then
  103.     commandArray[#commandArray+1]={['VP kompressor']='Off'}
  104. end
  105.  
  106. if (larm == '0' and otherdevices['VP larm'] == 'On') then
  107.     commandArray[#commandArray+1]={['VP larm']='Off'}
  108. end
  109.    
  110. if (larm ~= '0' and otherdevices['VP larm'] == 'Off') then
  111.     commandArray[#commandArray+1]={['VP larm']='On'}
  112. end
  113.  
  114. if (cirkpump_P1 == '1' and otherdevices['VP cirkulationspump (P1)'] == 'Off') then
  115.     commandArray[#commandArray+1]={['VP cirkulationspump (P1)']='On'}
  116. end
  117.  
  118. if (cirkpump_P1 == '0' and otherdevices['VP cirkulationspump (P1)'] == 'On') then
  119.     commandArray[#commandArray+1]={['VP cirkulationspump (P1)']='Off'}
  120. end
  121.  
  122.  
  123. if (schunt_oppna_SV1 == '1' and otherdevices['VP schunt öppnar (SV1)'] == 'Off') then
  124.     commandArray[#commandArray+1]={['VP schunt öppnar (SV1)']='On'}
  125. end
  126.  
  127. if (schunt_oppna_SV1 == '0' and otherdevices['VP schunt öppnar (SV1)'] == 'On') then
  128.     commandArray[#commandArray+1]={['VP schunt öppnar (SV1)']='Off'}
  129. end
  130.  
  131.  
  132. if (schunt_stang_SV1 == '1' and otherdevices['VP schunt stänger (SV1)'] == 'Off') then
  133.     commandArray[#commandArray+1]={['VP schunt stänger (SV1)']='On'}
  134. end
  135.  
  136. if (schunt_stang_SV1 == '0' and otherdevices['VP schunt stänger (SV1)'] == 'On') then
  137.     commandArray[#commandArray+1]={['VP schunt stänger (SV1)']='Off'}
  138. end
  139.  
  140. if (tryckvakt_avfrost_GP3 == '1' and otherdevices['VP tryckvakt avfrostning (GP3)'] == 'Off') then
  141.     commandArray[#commandArray+1]={['VP tryckvakt avfrostning (GP3)']='On'}
  142. end
  143.  
  144. if (tryckvakt_avfrost_GP3 == '0' and otherdevices['VP tryckvakt avfrostning (GP3)'] == 'On') then
  145.     commandArray[#commandArray+1]={['VP tryckvakt avfrostning (GP3)']='Off'}
  146. end
  147.  
  148. if (tryckvakt_hogtryck_HP == '1' and otherdevices['VP tryckvakt högtryck (GP3)'] == 'Off') then
  149.     commandArray[#commandArray+1]={['VP tryckvakt högtryck (GP3)']='On'}
  150. end
  151.  
  152. if (tryckvakt_hogtryck_HP == '0' and otherdevices['VP tryckvakt högtryck (GP3)'] == 'On') then
  153.     commandArray[#commandArray+1]={['VP tryckvakt högtryck (GP3)']='Off'}
  154. end
  155.  
  156. if (tryckvakt_logtryck_LP == '1' and otherdevices['VP tryckvakt lågtryck (GP1)'] == 'Off') then
  157.     commandArray[#commandArray+1]={['VP tryckvakt lågtryck (GP1)']='On'}
  158. end
  159.  
  160. if (tryckvakt_logtryck_LP == '0' and otherdevices['VP tryckvakt lågtryck (GP1)'] == 'On') then
  161.     commandArray[#commandArray+1]={['VP tryckvakt lågtryck (GP1)']='Off'}
  162. end
  163.  
  164. if (elpatron1 ~= '0' and otherdevices['VP elpatron 1'] == 'Off') then
  165.     commandArray[#commandArray+1]={['VP elpatron 1']='On'}
  166. end
  167.  
  168. if (elpatron1 == '0' and otherdevices['VP elpatron 1'] == 'On') then
  169.     commandArray[#commandArray+1]={['VP elpatron 1']='Off'}
  170. end
  171.  
  172. if (elpatron2 ~= '0' and otherdevices['VP elpatron 2'] == 'Off') then
  173.     commandArray[#commandArray+1]={['VP elpatron 2']='On'}
  174. end
  175.  
  176. if (elpatron2 == '0' and otherdevices['VP elpatron 2'] == 'On') then
  177.     commandArray[#commandArray+1]={['VP elpatron 2']='Off'}
  178. end
  179.    
  180. end
  181.  
  182. return commandArray
RAW Paste Data