Page 20 of 30
Re: dtgbot - Domoticz TeleGram BOT
Posted: Saturday 22 August 2020 13:09
by hoeby
That did the trick.
On the first test i also tried with
systemstatus.sh
But giving that as command didn't work. Now giving systemstatus it works.
When i give system or status, then it doesn't work.
The reason was because i have multi .sh files with curtain in it.
But liked that for other command, like systemstatus i only can give status and it works
Tried to make this, but that doens't work. Then it takes the
(line:match(cmda)) again
Code: Select all
if (line==cmda..".sh") then
print_to_log(0,line)
os.execute(BotBashScriptPath .. line .. ' ' .. SendTo .. ' ' .. stuff)
found=1
elseif (line~=cmda..".sh") then
if (line:match(cmda)) then
print_to_log(0,line)
os.execute(BotBashScriptPath .. line .. ' ' .. SendTo .. ' ' .. stuff)
found=1
end
end
Also tried this, also withou luck
Code: Select all
if (line==cmda..".sh") then
print_to_log(0,line)
os.execute(BotBashScriptPath .. line .. ' ' .. SendTo .. ' ' .. stuff)
found=1
else
if (line:match(cmda)) then
print_to_log(0,line)
os.execute(BotBashScriptPath .. line .. ' ' .. SendTo .. ' ' .. stuff)
found=1
end
end
I thoughed if the
IF is true, that the
ELSE is skipted.
Any ideas?
Re: dtgbot - Domoticz TeleGram BOT
Posted: Saturday 22 August 2020 13:44
by jvdz
Not sure what it is you want now: The original does a partial match of the command and runs all sh files that contain the command verb.
The change I gave is to make it only work when the command given is an exact match with the the bash filename without the ".sh" part.
So, what scenario are you now trying to build because enabling both these test doesn't make sense to me as the partial match will always be true so why do an exact match?
Re: dtgbot - Domoticz TeleGram BOT
Posted: Saturday 22 August 2020 14:04
by hoeby
I am trying to build:
If it is an exact match, than it has to follow that.
Otherwise it search for a match.
I have these .sh files:
- Curtain
- Curtain_open
- Curtain_close
When i set it as match. Than it does all those command.
Your modification works. But when i now give the command status, that is not exactly the name of the file and does give an error back.
Re: dtgbot - Domoticz TeleGram BOT
Posted: Saturday 22 August 2020 14:14
by jvdz
I understand that part, and that is how it always has worked, but what I do not understand how you would like it to be changed?
Maybe it would help when you describe the scenario's, so the command you provide and which scriptnames should be ran.
Re: dtgbot - Domoticz TeleGram BOT
Posted: Monday 24 August 2020 13:03
by hoeby
I didn't respond directly on your question.
First needed to think about which way to walk.
The reply menu's work. But i need to make the name exactly to the .sh file.
Therefor i would like to go work with the inline menu's. Here i can make a nice name and use other words to trigger the scripts.
Looks nicer for the user.
I would like to build something like the dtgmenu, but then custom made for my domoticz environment.
To have some idea what i mean, simple menu structure made.
Code: Select all
Home -----> Blinds --> Status = ? --------> Blinds open
| |
| ---> Blinds close
| |
| ---> Back to Home
|
---> Curtain --> Status = ? -------> Curtain open
| |
| ---> Curtain close
| |
| ---> Back to Home
|
---> Shutter ------> Parents --> Status = ? -------> Shutter open
| |
| ---> Shutter close
|
---> Child-M --> Status = ? -------> Shutter open
| |
| ---> Shutter close
|
---> Child-A --> Status = ? -------> Shutter open
| |
| ---> Shutter close
|
---> Back to Home
I tested with this URL
Code: Select all
'https://api.telegram.org/bot'..teleTok..'/sendMessage?chat_id='..chatId..'&text='..tekstpost..'&reply_markup={"inline_keyboard":[[{"text":"Keukenlamp aan","callback_data":"/lighton"},{"text":"Keukenlamp uit","callback_data":"/lightoff"}]]}'
And this to update
Code: Select all
'https://api.telegram.org/bot'..teleTok..'/editMessageReplyMarkup?chat_id='..chatId..'&text='..tekstremove..'&reply_markup={"inline_keyboard":[[{"text":"Aan Keukenlamp","callback_data":"gordijn"},{"text":"Aan Keukenlamp","callback_data":"/lighton"},{"text":"uit Keukenlamp ","callback_data":"/lightoff"}]]}&message_id='..id_message..''
The message ID i get with dzvents.
Both URL's are also send with dzvents.
But what is a good way to do this and also update the menu.
the dgtmenu has multi files to work. But reading them i don't get it how to modify them to make them work.
Is it good to start with?:
Send a message and get the message ID out of it.
When i have the message ID, it should be possible to extend the script with the option
Re: dtgbot - Domoticz TeleGram BOT
Posted: Monday 24 August 2020 13:16
by jvdz
Wouldn't it be easier when you simply use the "
command operation" in the callback? ....something like:
Code: Select all
'https://api.telegram.org/bot'..teleTok..'/sendMessage?chat_id='..chatId..'&text='..tekstpost..'&reply_markup={"inline_keyboard":[[{"text":"Keukenlamp aan","callback_data":"keukenlamp lighton"},{"text":"Keukenlamp uit","callback_data":"keukenlamp lightoff"}]]}'
In this way you can have an keukenlamp.sh or lua in DTGBOT that will then perform the operation specified in as parameter, sending the command to domoticz via a JSON call. This then also allows for the button text to be shorter/different for the actual command.
Jos
Re: dtgbot - Domoticz TeleGram BOT
Posted: Monday 24 August 2020 15:15
by hoeby
jvdz wrote: ↑Monday 24 August 2020 13:16
Wouldn't it be easier when you simply use the "
command operation" in the callback? ....something like:
Code: Select all
'https://api.telegram.org/bot'..teleTok..'/sendMessage?chat_id='..chatId..'&text='..tekstpost..'&reply_markup={"inline_keyboard":[[{"text":"Keukenlamp aan","callback_data":"keukenlamp lighton"},{"text":"Keukenlamp uit","callback_data":"keukenlamp lightoff"}]]}'
In this way you can have an keukenlamp.sh or lua in DTGBOT that will then perform the operation specified in as parameter, sending the command to domoticz via a JSON call. This then also allows for the button text to be shorter/different for the actual command.
Tried it to change the callback_data to a name of a script that already exists. But then nothing happens when i choose that option.
Do you mean that i can make a keukenlamp.sh or lua
In that script i need something like (very basic written):
Re: dtgbot - Domoticz TeleGram BOT
Posted: Monday 24 August 2020 16:26
by jvdz
hoeby wrote: ↑Monday 24 August 2020 15:15
Do you mean that i can make a keukenlamp.sh or lua
In that script i need something like (very basic written):
Yes... that is what I propose. So let's take this example inline keyboard (as posted previously):
Code: Select all
'https://api.telegram.org/bot'..teleTok..'/sendMessage?chat_id='..chatId..'&text='..tekstpost..'&reply_markup={"inline_keyboard":[[{"text":"Keukenlamp aan","callback_data":"keukenlamp lighton"},{"text":"Keukenlamp uit","callback_data":"keukenlamp lightoff"}]]}'
... That should work with a DTGBOT bash script keukenlamp.sh like this (Untested):
Code: Select all
#!/bin/sh
domourl="http://192.168.0.??:8080" #Domoticz server url
idx="123" # set to IDX of lamp
LogFile="/var/tmp/my_dtgbotcommands.log" # logfile for debugging
newstate="?" # newstate for lamp used by script
if [ "$1" == "lighton" ]; then
newstate="On"
elif [ "$1" == "lightoff" ]; then
newstate="Off"
else
echo "Invalid parameter: $1" >> $LogFile
exit 1
fi
wget -O - "$domourl/json.htm?type=command¶m=switchlight&idx=$idx&switchcmd=$newstate" >> $LogFile 2>&1
echo "Send $newstate to domoticz " >> $LogFile
Hope that makes it all a bit clearer.
Re: dtgbot - Domoticz TeleGram BOT
Posted: Monday 24 August 2020 16:38
by hoeby
Thanks Jos, for the support
I tried the script, but got an error back (seen in the my_dtgbotcommands.log)
Where chat-id was my number
Found this in the dtb.log.errors. The chat-ID is on the whitelist in variable
Code: Select all
/home/pi/dtgbot/bash/keukenlamp.sh: 9: [: chat-ID: unexpected operator
Re: dtgbot - Domoticz TeleGram BOT
Posted: Monday 24 August 2020 17:23
by hoeby
hoeby wrote: ↑Monday 24 August 2020 16:38
Thanks Jos, for the support
I tried the script, but got an error back (seen in the my_dtgbotcommands.log)
Where chat-id was my number
Found this in the dtb.log.errors. The chat-ID is on the whitelist in variable
Code: Select all
/home/pi/dtgbot/bash/keukenlamp.sh: 9: [: chat-ID: unexpected operator
Also need to look over. When i test it now, i don't see in the log that there is an incoming message. Now i send the telegram api from dzvents. Is that good? Or sends it the callback to where it comes from and therefor nothing happens?
Re: dtgbot - Domoticz TeleGram BOT
Posted: Monday 24 August 2020 18:37
by jvdz
There is no chat-id in my posted keukenlamp.sh script, so what exactly did you put in your keukenlamp.sh script?
Re: dtgbot - Domoticz TeleGram BOT
Posted: Monday 24 August 2020 19:04
by hoeby
This is in:
Code: Select all
#!/bin/sh
domourl="http://192.168.XXX.XXX:XXXX" #Domoticz server url
idx="27" # set to IDX of lamp
LogFile="/var/tmp/my_dtgbotcommands.log" # logfile for debugging
newstate="?" # newstate for lamp used by script
if [ "$1" == "lighton" ]; then
newstate="On"
elif [ "$1" == "lightoff" ]; then
newstate="Off"
else
echo "Invalid parameter: $1" >> $LogFile
exit 1
fi
wget -O - "$domourl/json.htm?type=command¶m=switchlight&idx=$idx&switchcmd=$newstate" >> $LogFile 2>&1
echo "Send $newstate to domoticz " >> $LogFile
It looks like $1 is the chat-id for some reason
Re: dtgbot - Domoticz TeleGram BOT
Posted: Monday 24 August 2020 19:22
by jvdz
Ok... I have done some testing and this is now working for me:
Code: Select all
#!/bin/sh
domourl="http://192.168.0.??:8080" #Domoticz server url
idx="123" # set to IDX of lamp
LogFile="/var/tmp/my_dtgbotcommands.log" # logfile for debugging
newstate="?" # newstate for lamp used by script
# $S1 is the telegram chatid of the sending party which you can check on for security when needed.
# $S2-$Sx are the subsequent provide parameters space delimited.
if [ "$2" = "lighton" ]; then
newstate="On"
elif [ "$2" = "lightoff" ]; then
newstate="Off"
else
echo "Invalid parameter: $1" >> $LogFile
exit 1
fi
echo "$domourl/json.htm?type=command¶m=switchlight&idx=$idx&switchcmd=$newstate" >> $LogFile 2>&1
echo "Send $newstate to domoticz " >> $LogFile
Re: dtgbot - Domoticz TeleGram BOT
Posted: Monday 24 August 2020 19:53
by hoeby
I don't get it what is happening
Tried it an it worked, this is written in de log file
Code: Select all
http://192.168.XXX.XXX:XXXX/json.htm?type=command¶m=switchlight&idx=27&switchcmd=On
Send On to domoticz
http://192.168.XXX.XXX:XXXX/json.htm?type=command¶m=switchlight&idx=27&switchcmd=Off
Send Off to domoticz
Nothing changed, but when i try it again, then nothing it happening anymore.
I receive the question in the app. Then i push one of the buttons and looked in the log. There is no incoming message.
When doing triggering other scripts, that works without issues.
Re: dtgbot - Domoticz TeleGram BOT
Posted: Monday 24 August 2020 20:00
by jvdz
Did you see I didn't include the WGET line in my test script as I didn't want to test against domoticz but just needed to test the DTGBOT part of it?
So add an curl or wget statement under the echo that shows the url to actually perform it.
Jos
Re: dtgbot - Domoticz TeleGram BOT
Posted: Monday 24 August 2020 20:08
by hoeby
I saw that. I was not testing with domoticz.
I was testing to see if the /var/tmp/my_dtgbotcommands.log file was getting updatet.
But it did 1x ON and 1x OFF, but that was it
Re: dtgbot - Domoticz TeleGram BOT
Posted: Monday 24 August 2020 20:12
by jvdz
Ok, so what does the DTG.log say when the command is processed?
Re: dtgbot - Domoticz TeleGram BOT
Posted: Monday 24 August 2020 20:21
by hoeby
That is the issue.
The dtg.log isn't updated, like there is no callback when the button is pushed.
therefor i tried this command
Code: Select all
'https://api.telegram.org/bot'..teleTok..'/sendMessage?chat_id='..chatId..'&text='..tekstpost..'&reply_markup={"keyboard":[[{"text":"keukenlamp lighton"},{"text":"keukenlamp lightoff"}]]}'
Then the script works without problems.
The problem looks to be in the string for inline_keyboard.
Re: dtgbot - Domoticz TeleGram BOT
Posted: Tuesday 25 August 2020 8:48
by hoeby
I looked at the inline-keyboard string, but can't find a wrong thing in it.
Tried to connect a esp universal telegram bot and fired the command to the this device. When i then choose an option, than it works.
When i fire the same command to dtgbot, than i get the message, but when i choose an option nothing happens.
Looking in the dtg.log there is no message detected by the dtgbot.
Any idea's what i need to check?
Re: dtgbot - Domoticz TeleGram BOT
Posted: Tuesday 25 August 2020 10:08
by jvdz
I have tested the whole process by sending the posted inline keyboard to my DTGBOT, click one of the buttons and check the DTGBOT.LOG & my_dtgbotcommands.log and they both contain the expected result, so have no idea what you are doing wrong.
You do mean with this statement "same command to dtgbot" to say that you fire the URL using the BOTTOKEN of DTGBOT so the selected button command is send to it... right?
Jos