Thank you! Would be great if available on standardbeamzer wrote: ↑Sunday 28 July 2019 11:48 Ok, this is the complete script where i can read and set domoticz variables.
If someone knows how to do this script in a telegram menu structure, i would be very interested. But at the moment this works for me.
Usage:Code: Select all
#!/bin/bash # # Ewald 20190728 # # if you would like to display with index in front, use this: # mapfile -t varia < <(curl --silent 'http://domoticz.local:8080/json.htm?type=command¶m=getuservariables' | jq -r -c '.result[]| {Name,idx,Value}' | perl -ne '/Name\":\"(\S+?)\".*idx\":\"(\d+).*Value\":\"(\S+?)\"/ && print "\[$2\] $1: $3\n"') # but display without the index allows for easier copy and paste to set a variable SendMsgTo=$1 if [ -z "$2" ]; then mapfile -t varia < <(curl --silent 'http://domoticz.local:8080/json.htm?type=command¶m=getuservariables' | jq -r -c '.result[]| {Name, Value}' | perl -ne '/Name\":\"(\S+?)\".*Value\":\"(\S+?)\"/ && print "$1 $2\n"') for v in "${varia[@]}" do if [[ $v != Telegram* ]]; then # leave out the dtgbot variables that start with Telegram # another option to display only the variables ending in Alert is: [[ $v == *Alert ]] curl --silent --data 'chat_id='$SendMsgTo --data-urlencode 'text='"$v" 'https://api.telegram.org/bot'$TelegramBotToken'/sendMessage' fi done else if [[ "$#" -ne 3 ]]; then curl --silent --data 'chat_id='$SendMsgTo --data-urlencode 'text='"Sorry, i need TWO arguments, VariableName and Value" 'https://api.telegram.org/bot'$TelegramBotToken'/sendMessage' exit 0 fi VAR=$2; VAL=$3 if [[ $VAR == Telegram* ]]; then curl --silent --data 'chat_id='$SendMsgTo --data-urlencode 'text='"Sorry, no changing Telegram variables" 'https://api.telegram.org/bot'$TelegramBotToken'/sendMessage' exit 0 fi CHECK=$(curl --silent "http://"$DomoticzIP":"$DomoticzPort"/json.htm?type=command¶m=updateuservariable&vname="$2"&vtype=0&vvalue="$3 | jq -r '.status') if [[ $CHECK == "OK" ]]; then curl --silent --data 'chat_id='$SendMsgTo --data-urlencode 'text='"$VAR = $VAL" 'https://api.telegram.org/bot'$TelegramBotToken'/sendMessage' else curl --silent --data 'chat_id='$SendMsgTo --data-urlencode 'text='"Oops, that didn't work" 'https://api.telegram.org/bot'$TelegramBotToken'/sendMessage' fi fi
the script is named varia.sh and put into dtgbot/bash. So entering varia in Telegram will give you all the variables except for the dtgbot specific variables. I left those out because they are security related, especially the TelegramBotWhiteListedIDs. The script doesn't allow you to change those either.
Using varia variablename value you can change the value of a specific variable.
In my case I use variable for playlist of media player and I change it to:
Code: Select all
CHECK=$(curl --silent "http://"$DomoticzIP":"$DomoticzPort"/json.htm?type=command¶m=updateuservariable&vname="$2"&vtype=String&vvalue="$3 | jq -r '.status')