Advertisement
Guest User

Untitled

a guest
Feb 28th, 2020
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.39 KB | None | 0 0
  1. #!/bin/bash
  2. #set -e
  3.  
  4. CONFIG_PATH=/data/options.json
  5. MQTTIP=$(jq --raw-output ".MQTT_server" $CONFIG_PATH)
  6. MQTTPORT=$(jq --raw-output ".MQTT_port" $CONFIG_PATH)
  7. MQTTUSER=$(jq --raw-output ".MQTT_user" $CONFIG_PATH)
  8. MQTTPASS=$(jq --raw-output ".MQTT_password" $CONFIG_PATH)
  9. SCREENLOGICIP=$(jq --raw-output ".ScreenLogic_server" $CONFIG_PATH)
  10. POOLCIRCUIT=$(jq --raw-output ".pool_circuit" $CONFIG_PATH)
  11. SPACIRCUIT=$(jq --raw-output ".spa_circuit" $CONFIG_PATH)
  12. POOLLIGHTCIRCUIT=$(jq --raw-output ".pool_light_circuit" $CONFIG_PATH)
  13. SPALIGHTCIRCUIT=$(jq --raw-output ".spa_light_circuit" $CONFIG_PATH)
  14. JETSCIRCUIT=$(jq --raw-output ".jets_circuit" $CONFIG_PATH)
  15. CLEANERCIRCUIT=$(jq --raw-output ".cleaner_circuit" $CONFIG_PATH)
  16.  
  17. cd /node_modules/node-screenlogic
  18.  
  19. node initialize.js $SCREENLOGICIP
  20.  
  21. while [ 1 ]; do
  22. # change IP address (-h) port (-p) username (-u) and password (-P) to match your MQTT broker settings
  23. PAYLOAD=`mosquitto_sub -h $MQTTIP -p $MQTTPORT -u $MQTTUSER -P $MQTTPASS -v -t pentair/# -W 10 -C 1`
  24. if [ $? -gt 0 ]; then
  25. echo "MQTT Client exited with non-zero status"
  26. sleep 10
  27. else
  28. TOPIC=`echo $PAYLOAD | awk '{print $1}'`
  29. MESSAGE=`echo $PAYLOAD | awk '{print $2}'`
  30.  
  31. case $TOPIC in
  32. "pentair/circuit/500/command")
  33. if [ "${MESSAGE}" == "ON" ]; then
  34. ./set_circuit $SCREENLOGICIP 500 1
  35. elif [ "${MESSAGE}" == "OFF" ]; then
  36. ./set_circuit $SCREENLOGICIP 500 0
  37. fi
  38. ;;
  39. "pentair/circuit/501/command")
  40. if [ "${MESSAGE}" == "ON" ]; then
  41. ./set_circuit $SCREENLOGICIP 501 1
  42. elif [ "${MESSAGE}" == "OFF" ]; then
  43. ./set_circuit $SCREENLOGICIP 501 0
  44. fi
  45. ;;
  46. "pentair/circuit/502/command")
  47. if [ "${MESSAGE}" == "ON" ]; then
  48. ./set_circuit $SCREENLOGICIP 502 1
  49. elif [ "${MESSAGE}" == "OFF" ]; then
  50. ./set_circuit $SCREENLOGICIP 502 0
  51. fi
  52. ;;
  53. "pentair/circuit/503/command")
  54. if [ "${MESSAGE}" == "ON" ]; then
  55. ./set_circuit $SCREENLOGICIP 503 1
  56. elif [ "${MESSAGE}" == "OFF" ]; then
  57. ./set_circuit $SCREENLOGICIP 503 0
  58. fi
  59. ;;
  60. "pentair/circuit/504/command")
  61. if [ "${MESSAGE}" == "ON" ]; then
  62. ./set_circuit $SCREENLOGICIP 504 1
  63. elif [ "${MESSAGE}" == "OFF" ]; then
  64. ./set_circuit $SCREENLOGICIP 504 0
  65. fi
  66. ;;
  67. "pentair/circuit/505/command")
  68. if [ "${MESSAGE}" == "ON" ]; then
  69. ./set_circuit $SCREENLOGICIP 505 1
  70. elif [ "${MESSAGE}" == "OFF" ]; then
  71. ./set_circuit $SCREENLOGICIP 505 0
  72. fi
  73. ;;
  74. "pentair/circuit/506/command")
  75. if [ "${MESSAGE}" == "ON" ]; then
  76. ./set_circuit $SCREENLOGICIP 506 1
  77. elif [ "${MESSAGE}" == "OFF" ]; then
  78. ./set_circuit $SCREENLOGICIP 506 0
  79. fi
  80. ;;
  81. "pentair/circuit/507/command")
  82. if [ "${MESSAGE}" == "ON" ]; then
  83. ./set_circuit $SCREENLOGICIP 507 1
  84. elif [ "${MESSAGE}" == "OFF" ]; then
  85. ./set_circuit $SCREENLOGICIP 507 0
  86. fi
  87. ;;
  88. "pentair/circuit/508/command")
  89. if [ "${MESSAGE}" == "ON" ]; then
  90. ./set_circuit $SCREENLOGICIP 508 1
  91. elif [ "${MESSAGE}" == "OFF" ]; then
  92. ./set_circuit $SCREENLOGICIP 508 0
  93. fi
  94. ;;
  95. "pentair/circuit/509/command")
  96. if [ "${MESSAGE}" == "ON" ]; then
  97. ./set_circuit $SCREENLOGICIP 509 1
  98. elif [ "${MESSAGE}" == "OFF" ]; then
  99. ./set_circuit $SCREENLOGICIP 509 0
  100. fi
  101. ;;
  102. "pentair/circuit/510/command")
  103. if [ "${MESSAGE}" == "ON" ]; then
  104. ./set_circuit $SCREENLOGICIP 510 1
  105. elif [ "${MESSAGE}" == "OFF" ]; then
  106. ./set_circuit $SCREENLOGICIP 510 0
  107. fi
  108. ;;
  109. "pentair/circuit/511/command")
  110. if [ "${MESSAGE}" == "ON" ]; then
  111. ./set_circuit $SCREENLOGICIP 511 1
  112. elif [ "${MESSAGE}" == "OFF" ]; then
  113. ./set_circuit $SCREENLOGICIP 511 0
  114. fi
  115. ;;
  116. "pentair/circuit/512/command")
  117. if [ "${MESSAGE}" == "ON" ]; then
  118. ./set_circuit $SCREENLOGICIP 512 1
  119. elif [ "${MESSAGE}" == "OFF" ]; then
  120. ./set_circuit $SCREENLOGICIP 512 0
  121. fi
  122. ;;
  123. "pentair/circuit/513/command")
  124. if [ "${MESSAGE}" == "ON" ]; then
  125. ./set_circuit $SCREENLOGICIP 513 1
  126. elif [ "${MESSAGE}" == "OFF" ]; then
  127. ./set_circuit $SCREENLOGICIP 513 0
  128. fi
  129. ;;
  130. "pentair/circuit/514/command")
  131. if [ "${MESSAGE}" == "ON" ]; then
  132. ./set_circuit $SCREENLOGICIP 514 1
  133. elif [ "${MESSAGE}" == "OFF" ]; then
  134. ./set_circuit $SCREENLOGICIP 514 0
  135. fi
  136. ;;
  137. "pentair/circuit/515/command")
  138. if [ "${MESSAGE}" == "ON" ]; then
  139. ./set_circuit $SCREENLOGICIP 515 1
  140. elif [ "${MESSAGE}" == "OFF" ]; then
  141. ./set_circuit $SCREENLOGICIP 515 0
  142. fi
  143. ;;
  144. "pentair/circuit/516/command")
  145. if [ "${MESSAGE}" == "ON" ]; then
  146. ./set_circuit $SCREENLOGICIP 516 1
  147. elif [ "${MESSAGE}" == "OFF" ]; then
  148. ./set_circuit $SCREENLOGICIP 516 0
  149. fi
  150. ;;
  151. "pentair/circuit/517/command")
  152. if [ "${MESSAGE}" == "ON" ]; then
  153. ./set_circuit $SCREENLOGICIP 517 1
  154. elif [ "${MESSAGE}" == "OFF" ]; then
  155. ./set_circuit $SCREENLOGICIP 517 0
  156. fi
  157. ;;
  158. "pentair/circuit/518/command")
  159. if [ "${MESSAGE}" == "ON" ]; then
  160. ./set_circuit $SCREENLOGICIP 518 1
  161. elif [ "${MESSAGE}" == "OFF" ]; then
  162. ./set_circuit $SCREENLOGICIP 518 0
  163. fi
  164. ;;
  165. "pentair/circuit/519/command")
  166. if [ "${MESSAGE}" == "ON" ]; then
  167. ./set_circuit $SCREENLOGICIP 519 1
  168. elif [ "${MESSAGE}" == "OFF" ]; then
  169. ./set_circuit $SCREENLOGICIP 519 0
  170. fi
  171. ;;
  172. "pentair/heater/spa/mode/set")
  173. if [ "${MESSAGE}" == "heat" ]; then
  174. ./set_heater $SCREENLOGICIP 1 1
  175. elif [ "${MESSAGE}" == "off" ]; then
  176. ./set_heater $SCREENLOGICIP 1 0
  177. fi
  178. ;;
  179. "pentair/heater/pool/mode/set")
  180. if [ "${MESSAGE}" == "heat" ]; then
  181. ./set_heater $SCREENLOGICIP 0 1
  182. elif [ "${MESSAGE}" == "off" ]; then
  183. ./set_heater $SCREENLOGICIP 0 0
  184. fi
  185. ;;
  186. "pentair/heater/spa/temperature/set")
  187. if [ 1 == 1 ]; then
  188. ./set_temp $SCREENLOGICIP 1 "${MESSAGE}"
  189. fi
  190. ;;
  191. "pentair/heater/pool/temperature/set")
  192. if [ 1 == 1 ]; then
  193. ./set_temp $SCREENLOGICIP 0 "${MESSAGE}"
  194. fi
  195. esac
  196. fi
  197.  
  198. # change IP address (-h) port (-p) username (-u) and password (-P) to match your MQTT broker settings
  199. node send_state_to_ha.js $SCREENLOGICIP | awk -F, '{print "mosquitto_pub -h '"$MQTTIP"' -p '"$MQTTPORT"' -u '"$MQTTUSER"' -P '"$MQTTPASS"' -t " $1 " -m " $2}' | bash -s
  200.  
  201.  
  202. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement