dtgbot - Domoticz TeleGram BOT

Client tools or tools that can connect with Domoticz. Tools for Windows, iOS, Android, Linux etc.

Moderator: leecollings

hoeby
Posts: 528
Joined: Saturday 02 June 2018 11:05
Target OS: Raspberry Pi / ODroid
Domoticz version: V2022.1
Location: Echt, Netherlands
Contact:

Re: dtgbot - Domoticz TeleGram BOT

Post 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?
Thin-client --> Docker Domoticz main environment
Pi3A+ --> Google home (GAssistPi)
Pi3B+ --> Docker (P1monitor, Domoticz test environment, Ubiquity controller)
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: dtgbot - Domoticz TeleGram BOT

Post 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?
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
hoeby
Posts: 528
Joined: Saturday 02 June 2018 11:05
Target OS: Raspberry Pi / ODroid
Domoticz version: V2022.1
Location: Echt, Netherlands
Contact:

Re: dtgbot - Domoticz TeleGram BOT

Post 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.
Thin-client --> Docker Domoticz main environment
Pi3A+ --> Google home (GAssistPi)
Pi3B+ --> Docker (P1monitor, Domoticz test environment, Ubiquity controller)
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: dtgbot - Domoticz TeleGram BOT

Post 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.
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
hoeby
Posts: 528
Joined: Saturday 02 June 2018 11:05
Target OS: Raspberry Pi / ODroid
Domoticz version: V2022.1
Location: Echt, Netherlands
Contact:

Re: dtgbot - Domoticz TeleGram BOT

Post 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
Thin-client --> Docker Domoticz main environment
Pi3A+ --> Google home (GAssistPi)
Pi3B+ --> Docker (P1monitor, Domoticz test environment, Ubiquity controller)
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: dtgbot - Domoticz TeleGram BOT

Post 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
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
hoeby
Posts: 528
Joined: Saturday 02 June 2018 11:05
Target OS: Raspberry Pi / ODroid
Domoticz version: V2022.1
Location: Echt, Netherlands
Contact:

Re: dtgbot - Domoticz TeleGram BOT

Post 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):

Code: Select all

if lighton then
if lightoff then
Thin-client --> Docker Domoticz main environment
Pi3A+ --> Google home (GAssistPi)
Pi3B+ --> Docker (P1monitor, Domoticz test environment, Ubiquity controller)
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: dtgbot - Domoticz TeleGram BOT

Post 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):

Code: Select all

if lighton then
if lightoff then
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&param=switchlight&idx=$idx&switchcmd=$newstate"  >> $LogFile 2>&1
echo "Send $newstate to domoticz " >> $LogFile
Hope that makes it all a bit clearer. :)
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
hoeby
Posts: 528
Joined: Saturday 02 June 2018 11:05
Target OS: Raspberry Pi / ODroid
Domoticz version: V2022.1
Location: Echt, Netherlands
Contact:

Re: dtgbot - Domoticz TeleGram BOT

Post by hoeby »

Thanks Jos, for the support

I tried the script, but got an error back (seen in the my_dtgbotcommands.log)

Code: Select all

Invalid parameter: chat-id
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
Thin-client --> Docker Domoticz main environment
Pi3A+ --> Google home (GAssistPi)
Pi3B+ --> Docker (P1monitor, Domoticz test environment, Ubiquity controller)
hoeby
Posts: 528
Joined: Saturday 02 June 2018 11:05
Target OS: Raspberry Pi / ODroid
Domoticz version: V2022.1
Location: Echt, Netherlands
Contact:

Re: dtgbot - Domoticz TeleGram BOT

Post 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)

Code: Select all

Invalid parameter: chat-id
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?
Thin-client --> Docker Domoticz main environment
Pi3A+ --> Google home (GAssistPi)
Pi3B+ --> Docker (P1monitor, Domoticz test environment, Ubiquity controller)
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: dtgbot - Domoticz TeleGram BOT

Post by jvdz »

There is no chat-id in my posted keukenlamp.sh script, so what exactly did you put in your keukenlamp.sh script?
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
hoeby
Posts: 528
Joined: Saturday 02 June 2018 11:05
Target OS: Raspberry Pi / ODroid
Domoticz version: V2022.1
Location: Echt, Netherlands
Contact:

Re: dtgbot - Domoticz TeleGram BOT

Post 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&param=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
Last edited by hoeby on Monday 24 August 2020 19:35, edited 1 time in total.
Thin-client --> Docker Domoticz main environment
Pi3A+ --> Google home (GAssistPi)
Pi3B+ --> Docker (P1monitor, Domoticz test environment, Ubiquity controller)
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: dtgbot - Domoticz TeleGram BOT

Post 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&param=switchlight&idx=$idx&switchcmd=$newstate"  >> $LogFile 2>&1
echo "Send $newstate to domoticz " >> $LogFile
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
hoeby
Posts: 528
Joined: Saturday 02 June 2018 11:05
Target OS: Raspberry Pi / ODroid
Domoticz version: V2022.1
Location: Echt, Netherlands
Contact:

Re: dtgbot - Domoticz TeleGram BOT

Post 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&param=switchlight&idx=27&switchcmd=On
Send On to domoticz 
http://192.168.XXX.XXX:XXXX/json.htm?type=command&param=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.
Thin-client --> Docker Domoticz main environment
Pi3A+ --> Google home (GAssistPi)
Pi3B+ --> Docker (P1monitor, Domoticz test environment, Ubiquity controller)
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: dtgbot - Domoticz TeleGram BOT

Post 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
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
hoeby
Posts: 528
Joined: Saturday 02 June 2018 11:05
Target OS: Raspberry Pi / ODroid
Domoticz version: V2022.1
Location: Echt, Netherlands
Contact:

Re: dtgbot - Domoticz TeleGram BOT

Post 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
Thin-client --> Docker Domoticz main environment
Pi3A+ --> Google home (GAssistPi)
Pi3B+ --> Docker (P1monitor, Domoticz test environment, Ubiquity controller)
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: dtgbot - Domoticz TeleGram BOT

Post by jvdz »

Ok, so what does the DTG.log say when the command is processed?
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
hoeby
Posts: 528
Joined: Saturday 02 June 2018 11:05
Target OS: Raspberry Pi / ODroid
Domoticz version: V2022.1
Location: Echt, Netherlands
Contact:

Re: dtgbot - Domoticz TeleGram BOT

Post 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.
Thin-client --> Docker Domoticz main environment
Pi3A+ --> Google home (GAssistPi)
Pi3B+ --> Docker (P1monitor, Domoticz test environment, Ubiquity controller)
hoeby
Posts: 528
Joined: Saturday 02 June 2018 11:05
Target OS: Raspberry Pi / ODroid
Domoticz version: V2022.1
Location: Echt, Netherlands
Contact:

Re: dtgbot - Domoticz TeleGram BOT

Post 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?
Thin-client --> Docker Domoticz main environment
Pi3A+ --> Google home (GAssistPi)
Pi3B+ --> Docker (P1monitor, Domoticz test environment, Ubiquity controller)
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: dtgbot - Domoticz TeleGram BOT

Post 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
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests