In a bash script for example: (untested)
Code: Select all
TEXT=""
for WORD in "$@"
do
TEXT="$TEXT $WORD"
done
echo "total text:$TEXT"
Moderator: leecollings
Code: Select all
TEXT=""
for WORD in "$@"
do
TEXT="$TEXT $WORD"
done
echo "total text:$TEXT"
Yes, true. But actually in current format of dtgbot.lua I cannot pass multiple parameters to the script as it trims away everything else than alphanumerical characters, underscore and hyphen (and åäö as I added those as allowed as well). So the script sees only the trimmed parameter which is constructed from the message text processed in the above described manner. I tested once what happens if I add space as allowed but it wouldn't then execute the script and I had no time to debug further where the issue was.jvdz wrote: ↑Thursday 10 August 2017 10:12 You probably need to check many more parameters in your Announcement.sh as they are space delimited, so each word is an parameter on its own unless the text was quoted.
In a bash script for example: (untested)JosCode: Select all
TEXT="" for WORD in "$@" do TEXT="$TEXT $WORD" done echo "total text:$TEXT"
Code: Select all
#!/bin/sh
SendMsgTo=$1
Message=`echo "$@" | cut -d " " -f2-`
ResultString=`curl 'http://'$DomoticzIP':'$DomoticzPort'/json.htm?type=devices&rid=80' 2>/dev/null | jq -r .result[].Data | tr -d ' :%'`
if [ "$ResultString" = "SetLevel10" ] ; then
Status="InputBd"
Receiver="On"
elif [ "$ResultString" = "SetLevel20" || "$ResultString" = "SetLevel30" ] ; then
Status="InputTv"
Receiver="On"
elif [ "$ResultString" = "SetLevel40" ] ; then
Status="InputDvd"
Receiver="On"
else
Status="PowerOff"
Receiver="Off"
fi
/bin/bash /home/pi/domoticz/scripts/tts.sh $Status "$Message" $Receiver
curl --data 'chat_id='$SendMsgTo --data-urlencode 'text=The following message was played at home: '"$Message" 'https://api.telegram.org/bot'$TelegramBotToken'/sendMessage'
Code: Select all
#!/bin/sh
#Variables
VoiceFile="/home/pi/scripts/voice.oga"
ResultString=`curl 'http://'$DomoticzIP':'$DomoticzPort'/json.htm?type=devices&rid=80' 2>/dev/null | jq -r .result[].Data | tr -d ' :%'`
if [ "$ResultString" = "SetLevel10" ] ; then
Status="InputBd"
elif [ "$ResultString" = "SetLevel20" || "$ResultString" = "SetLevel30" ] ; then
Status="InputTv"
elif [ "$ResultString" = "SetLevel40" ] ; then
Status="InputDvd"
else
Status="PowerOff"
fi
#Set the receiver to correct input / volume and wait a bit if it has been off
node /home/pi/harmonyHubCLI/harmonyHubCli.js -l 192.168.11.70 -d Vahvistin -c '["InputSat"]' -m
if [ "$Status" = "PowerOff" ] ; then
sleep 4
fi
node /home/pi/harmonyHubCLI/harmonyHubCli.js -l 192.168.11.70 -d Vahvistin -c '["VolumeUp","VolumeUp","VolumeUp","VolumeUp","VolumeUp"]' -m
#Fetch the file and play it, then remove
wget -O "$VoiceFile" "https://api.telegram.org/file/bot"'$TelegramBotToken'"/"'$2'"
omxplayer -o hdmi "$VoiceFile"
sudo rm "$VoiceFile"
#Put receiver back to correct input/volume
node /home/pi/harmonyHubCLI/harmonyHubCli.js -l 192.168.11.70 -d Vahvistin -c '["VolumeDown","VolumeDown","VolumeDown","VolumeDown","VolumeDown","'$Status'"]' -m
Just pushed the update to the Master branch.
It should be supporting all characters now as I am now simply concatenate the raw command given to the shelled script.
You're welcome
.. and then play that automatically on the bigscreen TV and scare the shit out of the family?
Thanks!
Code: Select all
#!/bin/sh
#Can be used to send text message to Sonos
#Example: /announcement "This is a test" 20 office
Msg=$3
Vol=$4
Sonos=$5
if [ "$Msg" == "" ] ; then
Msg="No message found"
fi
#replace spaces with %20
Text=${Msg// /%20}
#if no volume is given the set volume to 5
if [ "$Vol" == "" ] ; then
Vol=5
fi
if [ "$Sonos" == "" ] || [ "$Sonos" == "office" ] || [ "$Sonos" == "Office" ] ; then
Son=115
both=false
elif [ "$Sonos" == "kitchen" ] || [ "$Sonos" == "Kitchen" ] ; then
Son=116
both=false
elif [ "$Sonos" == "all" ] || [ "$Sonos" == "both" ] ; then
both=true
fi
if [ "$both" == false ] ; then
curl --url "http://192.168.1.157/fp/sonos/index.php?zone="$Son"&action=sendMessage&message="$Text"&volume="$Vol
else
Son=115
curl --url "http://192.168.1.157/fp/sonos/index.php?zone="$Son"&action=sendMessage&message="$Text"&volume="$Vol
Son=116
curl --url "http://192.168.1.157/fp/sonos/index.php?zone="$Son"&action=sendMessage&message="$Text"&volume="$Vol
fi
Code: Select all
#!/bin/sh
#Variables
VoiceFile="/home/gerard/temp/voice.oga"
OutputFile="/var/www/html/fp/sonos/spraak/voice.mp3"
#Fetch the file, convert it and play it
wget -O "$VoiceFile" "https://api.telegram.org/file/bot"$TelegramBotToken"/"$2
avconv -i $VoiceFile -c:a libmp3lame -q:a 2 $OutputFile -y
curl --url "http://192.168.1.157/fp/sonos/index.php?zone=115&action=sendMessage&message=voice&volume=20"
This was very simple to add after the latest additions to dtgbot.lua. Just add another elseif after msg.voice for msg.video_note and add video_note.sh with appropriate content to process it (format is .mp4 so suggest to name it something like ~/video.mp4). And to the end (near end) of the script add
Code: Select all
(msg ~= nil and (msg.text ~= nil or msg.voice ~= nil))
Code: Select all
(msg ~= nil and (msg.text ~= nil or msg.voice ~= nil or msg.video_note ~= nil))
Users browsing this forum: No registered users and 1 guest