voip2fhem 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #!/bin/bash
  2. # Interface from Asterisk to fhem
  3. # this file is called from /etc/asterisk/extensions.conf
  4. # Martin Haas 071214
  5. # if you want to use the english spoken espeak then change "espeak -v de" to "espeak"
  6. FHEM=localhost # if not localhost then set the port inside of FHEM to global
  7. FHEMport=7072
  8. location=/var/tmp/voip2fhem # later the owner must be asterisk.asterisk!
  9. [[ ! -d $location ]] && mkdir $location
  10. ####################################################
  11. ##
  12. providesound()
  13. {
  14. lvoice="$location/$(echo $voice | sed -e 's/-//g' -e 's/[ .:]/_/g').gsm"
  15. echo $lvoice
  16. if [ ! -f $lvoice ]
  17. then
  18. espeak -v de -s 120 -w /tmp/asterisk.wav "$voice"
  19. sox /tmp/asterisk.wav -r 8000 -c 1 $lvoice resample -ql
  20. fi
  21. cp $lvoice /tmp/asterisk$type.gsm
  22. }
  23. ###################################
  24. ##
  25. case "$3" in
  26. ######################################
  27. KS300)
  28. temperature=$(echo "list $1" | netcat -w1 $FHEM $FHEMport | grep temperature | awk '{print $4}')
  29. [[ ${temperature:0:1} == - ]] && temperature="minus $temperature" ## negativ temperature
  30. voice=$2; type=1; providesound "$voice" $type
  31. voice=$temperature; type=2; providesound "$voice" $type
  32. ;;
  33. ######################################
  34. FHT)
  35. temperature=$(echo "list $1" | netcat -w1 $FHEM $FHEMport | grep measured-temp | awk '{print $4}')
  36. voice=$2; type=1; providesound "$voice" $type
  37. voice=$temperature; type=2; providesound "$voice" $type
  38. ;;
  39. ######################################
  40. FS20STATE)
  41. state=$(echo "list $1" | netcat -w1 $FHEM $FHEMport | grep STATE | awk '{print $2}')
  42. voice=$2; type=1; providesound "$voice" $type
  43. voice=$state; type=2; providesound "$voice" $type
  44. ;;
  45. #####################################
  46. HMS100)
  47. temperature=$(echo "list $1" | netcat -w1 $FHEM $FHEMport | grep STATE | awk '{print $3}')
  48. voice=$2; type=1; providesound "$voice" $type
  49. voice=$temperature; type=2; providesound "$voice" $type
  50. ;;
  51. ######################################
  52. FS20)
  53. echo "set $1 toggle" | netcat -w1 $FHEM $FHEMport
  54. voice=$2; type=1; providesound "$voice" $type
  55. ;;
  56. esac