Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.50 KB | None | 0 0
  1. import socket
  2. import time
  3. import argparse
  4.  
  5. parser = argparse.ArgumentParser()
  6. parser.add_argument("hostIP", help='Rinnai Touch Host IP address')
  7.  
  8. # Must be one of these
  9. parser.add_argument("--mode",choices=['heat','evap','cool','rc'], help='What function are we acting on')
  10. parser.add_argument("--action",choices=['on','off'], help='What are we doing to the mode')
  11.  
  12. parser.add_argument("--heatTemp",type=int,choices=range(20,30))
  13. parser.add_argument("--heatZone",choices=['A','B','C','D'], help='Which Zone?')
  14. parser.add_argument("--zoneAction",choices=['on','off'], help='What are we doing to the zone')
  15. parser.add_argument("--heatFan",choices=['on','off'], help='Turn the Heater circulation fan on/off')
  16.  
  17. parser.add_argument("--evapFanSpeed",type=int,choices=range(1,16))
  18. parser.add_argument("--evapPump",choices=['on','off'], help='Turn the Evap pump on/off')
  19. parser.add_argument("--evapFan",choices=['on','off'], help='Turn the Evap fan on/off')
  20.  
  21. args = parser.parse_args()
  22.  
  23. print(args)
  24.  
  25. # Touch Box IP address
  26. port = 27847
  27. touchIP = args.hostIP
  28.  
  29. # create an ipv4 (AF_INET) socket object using the tcp protocol (SOCK_STREAM)
  30. client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  31.  
  32. # connect the client
  33. print("Connecting ...")
  34. client.connect((touchIP, port))
  35. time.sleep(0.2)
  36. response = client.recv(4096)
  37. print(response)
  38.  
  39. # setup some basic commands
  40. # Top level mode
  41. # Operating mode
  42. modeEvapCmd = 'N000001{"SYST": {"OSS": {"MD": "E" } } }'
  43. modeHeatCmd = 'N000001{"SYST": {"OSS": {"MD": "H" } } }'
  44.  
  45. # Heating Commands
  46. #heatCmd = 'N000001{"HGOM": {"OOP": {"ST": "{}" } } }' # N = On, F = Off
  47. heatOnCmd = 'N000001{"HGOM": {"OOP": {"ST": "N" } } }'
  48. heatOffCmd = 'N000001{"HGOM": {"OOP": {"ST": "F" } } }'
  49.  
  50. heatSetTemp = 'N000001{{"HGOM": {{"GSO": {{"SP": "{temp}" }} }} }}'
  51. heatCircFanOn = 'N000001{"HGOM": {"OOP": {"ST": "Z" } } }'
  52.  
  53. #heatZone = 'N000001{"HGOM": {"Z{zone}O": {"UE": "{}" } } }' # Y = On, N = Off
  54. heatZoneOn = 'N000001{{"HGOM": {{"Z{zone}O": {{"UE": "Y" }} }} }}'
  55. heatZoneOff = 'N000001{{"HGOM": {{"Z{zone}O": {{"UE": "N" }} }} }}'
  56. heatZoneA = 'N000001{"HGOM": {"ZAO": {"UE": "{}" } } }' # Y = On, N = Off
  57. heatZoneB = 'N000001{"HGOM": {"ZBO": {"UE": "{}" } } }'
  58. heatZoneC = 'N000001{"HGOM": {"ZCO": {"UE": "{}" } } }'
  59. heatZoneD = 'N000001{"HGOM": {"ZDO": {"UE": "{}" } } }'
  60.  
  61. # Evap Cooling commands
  62. #evapCmd = 'N000001{"ECOM": {"GSO": {"SW": "{}" } } }' # N = On, F = Off
  63. evapOnCmd = 'N000001{"ECOM": {"GSO": {"SW": "N" } } }'
  64. evapOffCmd = 'N000001{"ECOM": {"GSO": {"SW": "F" } } }'
  65.  
  66. #evapPumpCmd = 'N000001{"ECOM": {"GSO": {"PS": "{}" } } }' # N = On, F = Off
  67. evapPumpOn = 'N000001{"ECOM": {"GSO": {"PS": "N" } } }'
  68. evapPumpOff = 'N000001{"ECOM": {"GSO": {"PS": "F" } } }'
  69.  
  70. #evapFanCmd = 'N000014{"ECOM": {"GSO": {"FS": "{}" } } }' # N = On, F = Off
  71. evapFanOn = 'N000014{"ECOM": {"GSO": {"FS": "N" } } }'
  72. evapFanOff = 'N000014{"ECOM": {"GSO": {"FS": "F" } } }'
  73. evapFanSpeed = 'N000001{{"ECOM": {{"GSO": {{"FL": "{speed}" }} }} }}' # 1 - 16
  74.  
  75. def SendToTouch(client,cmd):
  76. """Send the command and return the response."""
  77. print("DEBUG: {}".format(cmd))
  78. response = "NA"
  79. client.send(cmd.encode())
  80. response = client.recv(4096)
  81. return response
  82.  
  83. def HandleMode(args,client):
  84. """Process setting mode and its state."""
  85. if args.mode == "heat":
  86. # Make sure we are in heater mode
  87. resp = SendToTouch(client,modeHeatCmd)
  88. print(resp)
  89. # Give it a chance if there are further commands
  90. time.sleep(2)
  91.  
  92. if args.action is not None:
  93. if args.action == "on":
  94. resp = SendToTouch(client,heatOnCmd)
  95. print(resp)
  96. else:
  97. # Assume it is off cmd then
  98. # Assume we are in heater mode, otherwise no need to turn it Off
  99. resp = SendToTouch(client,heatOffCmd)
  100. print(resp)
  101. return
  102.  
  103. if args.heatTemp is not None:
  104. # Assume on already
  105. resp = SendToTouch(client,heatSetTemp.format(temp=args.heatTemp))
  106. print(resp)
  107.  
  108. if args.heatZone is not None:
  109. if args.zoneAction == "on":
  110. # Assume on already
  111. resp = SendToTouch(client,heatZoneOn.format(zone=args.heatZone))
  112. print(resp)
  113. elif args.zoneAction == "off":
  114. resp = SendToTouch(client,heatZoneOff.format(zone=args.heatZone))
  115. print(resp)
  116. return
  117.  
  118. elif args.mode =="evap":
  119. # Make sure we are in evap mode
  120. resp = SendToTouch(client,modeEvapCmd)
  121. print(resp)
  122. # Give it a chance
  123. time.sleep(2)
  124.  
  125. if args.action is not None:
  126. if args.action == "on":
  127.  
  128. resp = SendToTouch(client,evapOnCmd)
  129. print(resp)
  130. else:
  131. # Assume it is off cmd then
  132. # Assume we are in heater mode, otherwise no need to turn it Off
  133. resp = SendToTouch(client,evapOffCmd)
  134. print(resp)
  135. return
  136.  
  137. if args.evapFanSpeed is not None:
  138. resp = SendToTouch(client,evapFanSpeed.format(speed=args.evapFanSpeed))
  139. print(resp)
  140.  
  141. if args.evapFan is not None:
  142. if args.evapFan == "on":
  143. resp = SendToTouch(client,evapFanOn)
  144. print(resp)
  145. else:
  146. # Assume off cmd then
  147. resp = SendToTouch(client,evapFanOff)
  148. print(resp)
  149.  
  150. else:
  151. print("Not implemented yet")
  152.  
  153. if args.mode is not None:
  154. HandleMode(args,client)
  155. else:
  156. exit()
  157.  
  158. client.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement