FHEMHelper.sh.safe 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. # /bin/sh
  2. #
  3. # FHEMHelper.sh
  4. #
  5. # Script file to perform various external tasks for DoorPi
  6. #
  7. # Prof. Dr. Peter A. Henning, 2016
  8. #
  9. # $Id: FHEMHelper 2016-05 - pahenning $
  10. #
  11. ########################################################################################
  12. #
  13. # This programm is free software; you can redistribute it and/or modify
  14. # it under the terms of the GNU General Public License as published by
  15. # the Free Software Foundation; either version 2 of the License, or
  16. # (at your option) any later version.
  17. #
  18. # The GNU General Public License can be found at
  19. # http://www.gnu.org/copyleft/gpl.html.
  20. # A copy is found in the textfile GPL.txt and important notices to the license
  21. # from the author is found in LICENSE.txt distributed with these scripts.
  22. #
  23. # This script is distributed in the hope that it will be useful,
  24. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  26. # GNU General Public License for more details.
  27. #
  28. #########################################################################################
  29. # History
  30. # no_Legend 2016-09-28: Hinzufügen von verschiedenen Variablen, sowie bedingte Ausführung
  31. # der Textausgaben auf einem TTS_Device.
  32. #########################################################################################
  33. checkstream() {
  34. streampid=`pidof mjpg_streamer`
  35. if [ -z "$streampid" ]; then
  36. stream="off"
  37. else
  38. stream="on"
  39. fi
  40. }
  41. FHEMDP="A.Door.Pi" # FHEM Devicename for DoorPi
  42. FHEMIP="192.168.x.y" # IP address for DoorPi
  43. FHEMPORT="8083" # Port number for DoorPi
  44. FHEMHTTPS="false" # true for HTTPS, false without HTTPS
  45. curlprog="curl"
  46. curlargs="" # -k to disable HTTPS certificate check,
  47. # -u user:password for user and password
  48. HOME="/home/doorpi" # Doorpi Standard /usr/local/etc/DoorPi/
  49. default_target="yyyyy" # default telephone number to be called
  50. FHEMTTS="true" # true for TTS output, false without TTS
  51. FHEMTTSDEVICE="GalaxyTab" # FHEM Devicename for TTS device
  52. ### FHEM path ###
  53. if [ $FHEMHTTPS = "true" ]; then
  54. FHEM="https://$FHEMIP:$FHEMPORT/fhem?XHR=1&cmd.$FHEMDP"
  55. else
  56. FHEM="http://$FHEMIP:$FHEMPORT/fhem?XHR=1&cmd.$FHEMDP"
  57. fi
  58. ### execute commands ##
  59. case $1 in
  60. init) #-- send current target to FHEM
  61. target=`cat $HOME/calltarget`
  62. $curlprog $curlargs "$FHEM=setreading%20$FHEMDP%20call_target%20$target" &
  63. #-- send state of mjpg_streamer to FHEM
  64. streampid=`pidof mjpg_streamer`
  65. if [ -z "$streampid" ]; then
  66. $curlprog $curlargs "$FHEM=setreading%20$FHEMDP%20stream%20off" &
  67. else
  68. $curlprog $curlargs "$FHEM=setreading%20$FHEMDP%20stream%20on" &
  69. fi
  70. ;;
  71. doorunlockandopen)
  72. if [ $FHEMTTS = "true" ]; then
  73. $curlprog $curlargs "$FHEM=set%20$FHEMTTSDEVICE%20ttsSay%20Ein%20Bewohner%20betritt%20das%20Haus" &
  74. fi
  75. $curlprog $curlargs "$FHEM=set%20$FHEMDP%20door%20unlockandopen" &
  76. ;;
  77. wrongid)
  78. if [ $FHEMTTS = "true" ]; then
  79. $curlprog $curlargs "$FHEM=set%20FHEMTTSDEVICE%20ttsSay%20Unerlaubter%20Zutrittsversuch" &
  80. fi
  81. $curlprog $curlargs "$FHEM=set%20$FHEMDP%20door%20wrong_id" &
  82. ;;
  83. softlock)
  84. $curlprog $curlargs "$FHEM=set%20$FHEMDP%20door%20softlock" &
  85. ;;
  86. call)
  87. $curlprog $curlargs "$FHEM=set%20$FHEMDP%20call%20$2" &
  88. ;;
  89. gettarget)
  90. echo "{ReadingsVal('$FHEMDP','call_target','$default_target')}" | socat -t50 - TCP:$FHEMIP:7072 > $HOME/calltarget
  91. ;;
  92. purge)
  93. find $HOME/records/ -type f -ctime 1 -delete
  94. ;;
  95. movement)
  96. $curlprog $curlargs "$FHEM=set%20$FHEMDP%20door%20movement" &
  97. ;;
  98. sabotage)
  99. $curlprog $curlargs "$FHEM=set%20$FHEMDP%20door%20sabotage" &
  100. ;;
  101. esac