dtgbot - Domoticz TeleGram BOT

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

Moderator: leecollings

User avatar
beamzer
Posts: 19
Joined: Sunday 17 August 2014 20:18
Target OS: Raspberry Pi / ODroid
Domoticz version: stable
Contact:

Re: dtgbot - Domoticz TeleGram BOT

Post by beamzer »

hmm, i was thinking more in the way the devices function works. Making a bash or lua script that lists them is not such a problem. But then i would like to change the values. At the moment i use 0, 1 and 2. A submenu with variables would be beter even. I was hoping someone already coded some of this.
Domoticz stable on a Raspberry Pi 3
RFXtrx433E - RFLink - Smartmeter (through RasPi-Zero-W) - Hue - BMP180 - DHT22 - Wemos D1 Mini's with PIR
User avatar
beamzer
Posts: 19
Joined: Sunday 17 August 2014 20:18
Target OS: Raspberry Pi / ODroid
Domoticz version: stable
Contact:

Re: dtgbot - Domoticz TeleGram BOT

Post by beamzer »

this works for getting the data from all variables

Code: Select all

#!/bin/bash
SendMsgTo=$1
mapfile -t varia  < <(curl --silent 'http://domoticz.local:8080/json.htm?type=command&param=getuservariables' | jq '.result[]|{(.Name): .Value}' | egrep -v '[{}\]' | tr -d \" )

for v in "${varia[@]}"
do
   curl --data 'chat_id='$SendMsgTo --data-urlencode 'text='"$v" 'https://api.telegram.org/bot'$TelegramBotToken'/sendMessage'
done
Domoticz stable on a Raspberry Pi 3
RFXtrx433E - RFLink - Smartmeter (through RasPi-Zero-W) - Hue - BMP180 - DHT22 - Wemos D1 Mini's with PIR
User avatar
beamzer
Posts: 19
Joined: Sunday 17 August 2014 20:18
Target OS: Raspberry Pi / ODroid
Domoticz version: stable
Contact:

Re: dtgbot - Domoticz TeleGram BOT

Post by beamzer »

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.

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&param=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&param=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&param=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
	
Usage:
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.
Domoticz stable on a Raspberry Pi 3
RFXtrx433E - RFLink - Smartmeter (through RasPi-Zero-W) - Hue - BMP180 - DHT22 - Wemos D1 Mini's with PIR
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 »

beamzer 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.
-snip-
Ah ok, you mean you like support for variables in DTGMENU like we now have for devices. Well that would required quite some changes in the logic as it currently is using the Room definitions by default with the option to add "specials" via DTGMENU.CFG.
So it would require an update to the code to distinguish between Devices and UserVariables and be able to update those, but anything is possible. 8-)
I probably do not really see how this is useful for a large community yet. You stated you want to set a uservariable to 0,1 or 2, so I probably would look at an solution with a selector switch rather than using a user variable, but again, maybe I do not really understand your requirement properly

Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
sejtam
Posts: 10
Joined: Saturday 22 February 2014 9:16
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: dtgbot - Domoticz TeleGram BOT

Post by sejtam »

Has anyone found the correct way to handle the lua5.2 issues with libssl.so.1.0.0 and lubvrypto.so.1.0.0 etc?

I just installed dtgbot as per the instructions, and it seems that the lus5.2 wants to use libssl.so.1.0.0 and libvrypto.so.1.0.0

But

# apt list --installed | egrep -i '(ssl|crypto)'

libevent-openssl-2.1-6/stable,now 2.1.8-stable-4 armhf [installed,automatic]
libk5crypto3/stable,now 1.17-3 armhf [installed,automatic]
libmbedcrypto3/stable,now 2.16.0-1 armhf [installed,automatic]
libssl-dev/stable,now 1.1.1c-1 armhf [installed]
libssl1.0.2/stable,now 1.0.2q-2 armhf [installed,automatic]
libssl1.1/stable,now 1.1.1c-1 armhf [installed]
openssl/stable,now 1.1.1c-1 armhf [installed,automatic]
python-asn1crypto/stable,now 0.24.0-1 all [installed,automatic]
python-crypto/stable,now 2.6.1-9+b1 armhf [installed,automatic]
python-cryptography/stable,now 2.6.1-3 armhf [installed,automatic]
python-openssl/stable,now 19.0.0-1 all [installed,automatic]
python3-asn1crypto/stable,now 0.24.0-1 all [installed,automatic]
python3-crypto/stable,now 2.6.1-9+b1 armhf [installed,automatic]
python3-cryptography/stable,now 2.6.1-3 armhf [installed,automatic]
python3-openssl/stable,now 19.0.0-1 all [installed,automatic]

So there are libssl1.1 ans 1.0.2 installed, not 1.0.0
User avatar
beamzer
Posts: 19
Joined: Sunday 17 August 2014 20:18
Target OS: Raspberry Pi / ODroid
Domoticz version: stable
Contact:

Re: dtgbot - Domoticz TeleGram BOT

Post by beamzer »

Yes, you have to install libssl1.0.0, on my rapsberry pi it has:

Code: Select all

sudo apt list --installed | egrep -i '(ssl|crypto)'

libgnutls-openssl27/oldoldstable,now 3.3.30-0+deb8u1 armhf [installed]
libio-socket-ssl-perl/oldoldstable,now 2.002-2+deb8u3 all [installed,automatic]
libk5crypto3/oldoldstable,now 1.12.1+dfsg-19+deb8u5 armhf [installed,automatic]
libnet-smtp-ssl-perl/oldoldstable,now 1.01-3 all [installed,automatic]
libnet-ssleay-perl/oldoldstable,now 1.65-1+deb8u1 armhf [installed,automatic]
libssl-dev/oldoldstable,now 1.0.1t-1+deb8u11 armhf [installed]
libssl-doc/oldoldstable,now 1.0.1t-1+deb8u11 all [installed,automatic]
libssl1.0.0/oldoldstable,now 1.0.1t-1+deb8u11 armhf [installed]
openssl/oldoldstable,now 1.0.1t-1+deb8u11 armhf [installed,automatic]
python-cryptography/oldoldstable,now 0.6.1-1+deb8u1 armhf [installed,automatic]
python-openssl/oldoldstable,now 0.14-1 all [installed,automatic]
python-passlib/oldoldstable,now 1.6.1-1 all [installed]
ssl-cert/oldoldstable,now 1.0.35 all [installed,automatic]
I have:
in: /etc/sources.list

Code: Select all

deb http://archive.raspbian.org/raspbian/ jessie main contrib non-free rpi
and then:

Code: Select all

sudo apt-get update
sudo apt-get install libssl1.0.0
Domoticz stable on a Raspberry Pi 3
RFXtrx433E - RFLink - Smartmeter (through RasPi-Zero-W) - Hue - BMP180 - DHT22 - Wemos D1 Mini's with PIR
sejtam
Posts: 10
Joined: Saturday 22 February 2014 9:16
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: dtgbot - Domoticz TeleGram BOT

Post by sejtam »

really? There is no way to make it use 1.1 or 1.0.2?
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 »

Have you seen my post in the previous page of this thread?
jvdz wrote: Thursday 07 February 2019 11:47 I don't have a RPI3b so can test with that.... maybe others have tested this?
Maybe @simonrg can tell us which sources he used to compile these libraries, but my guess is these:
https://github.com/diegonehab/luasocket -> socket.* stuff
https://github.com/brunoos/luasec -> /usr/local/lib/lua/5.2/ssl.so
And some post above about needing to recompile them?

Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
Nautilus
Posts: 722
Joined: Friday 02 October 2015 12:12
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Finland
Contact:

Re: dtgbot - Domoticz TeleGram BOT

Post by Nautilus »

Hi, I hadn't needed dtgbot for a while. Now I tried to use it again after a few months and didn't get any reply to my messages. I tried taking all troubleshootin steps that I found relevant, but no help. In error file there is nothing, in the log file there's just the basic info of the script starting, reading the variables etc. My first assumption was something wrong with TelegramBotOffset and incremented it with one. Then I looked at https://www.domoticz.com/wiki/Remote_Co ... use_Errors and checked update_id as suggested and found it to be no where near to what there was in the variable in Domoticz. So I updated it to the correct update_id but that did not help either. So I have dtgbot running, nothing in error log, nothing except the startup message in normal log and no response when I send any command to the bot. I can confirm it worked a couple of months ago and there has not been any major changes in the setup meanwhile. Where should I continue troubleshooting? Can I somehow reset the chat with the bot and start again from TelegramBotOffset = 1?
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 »

Nautilus wrote: Thursday 13 February 2020 14:56 Where should I continue troubleshooting? Can I somehow reset the chat with the bot and start again from TelegramBotOffset = 1?
Could it be that you are also (like me) running on an older Raspbian OS, as I had also this kind of issue Thursday last week?
Long story short: It seems the the Telegram API site stopped support for “tlsv1” and the older version of LUASEC, which performs the webcalls is using that as default protocol. So I solved that by adding a wrapper function to DTGBOT.lua to set the protocol to “tlsv1_2” and all is working again for me.
The update was committed to https://github.com/steps39/dtgbot/blob/ ... dtgbot.lua . This i s the only file that was modified, so just download it and give it a try.

Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
User avatar
beamzer
Posts: 19
Joined: Sunday 17 August 2014 20:18
Target OS: Raspberry Pi / ODroid
Domoticz version: stable
Contact:

Re: dtgbot - Domoticz TeleGram BOT

Post by beamzer »

jvdz wrote: Thursday 13 February 2020 15:46 Could it be that you are also (like me) running on an older Raspbian OS, as I had also this kind of issue Thursday last week?
Long story short: It seems the the Telegram API site stopped support for “tlsv1” and the older version of LUASEC, which performs the webcalls is using that as default protocol. So I solved that by adding a wrapper function to DTGBOT.lua to set the protocol to “tlsv1_2” and all is working again for me.
The update was committed to https://github.com/steps39/dtgbot/blob/ ... dtgbot.lua . This i s the only file that was modified, so just download it and give it a try.

Jos
Thanks! it now works again, :D
Domoticz stable on a Raspberry Pi 3
RFXtrx433E - RFLink - Smartmeter (through RasPi-Zero-W) - Hue - BMP180 - DHT22 - Wemos D1 Mini's with PIR
Nautilus
Posts: 722
Joined: Friday 02 October 2015 12:12
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Finland
Contact:

Re: dtgbot - Domoticz TeleGram BOT

Post by Nautilus »

beamzer wrote: Thursday 13 February 2020 21:10
jvdz wrote: Thursday 13 February 2020 15:46 Could it be that you are also (like me) running on an older Raspbian OS, as I had also this kind of issue Thursday last week?
Long story short: It seems the the Telegram API site stopped support for “tlsv1” and the older version of LUASEC, which performs the webcalls is using that as default protocol. So I solved that by adding a wrapper function to DTGBOT.lua to set the protocol to “tlsv1_2” and all is working again for me.
The update was committed to https://github.com/steps39/dtgbot/blob/ ... dtgbot.lua . This i s the only file that was modified, so just download it and give it a try.

Jos
Thanks! it now works again, :D
Same here, thanks a lot! :D
Nautilus
Posts: 722
Joined: Friday 02 October 2015 12:12
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Finland
Contact:

Re: dtgbot - Domoticz TeleGram BOT

Post by Nautilus »

jvdz wrote: Friday 03 August 2018 14:53 I will have a look at this as that shouldn't be too hard to add. (His famous last words :D )

Jos
Now after browsing through the thread I noticed this and tried it on a channel where I have the same bot. But immediately if I send a command to this channel, the bot sends a message to the 1-on-1 chat that id is not whitelisted. Is this the channel id that should be whitelisted? I guess my id is still the same. I tried adding the channel id to whitelist, but then dtgbot stopped working altogether. Maybe because the channel id is in format "-##########"? Or am I missing some configuration step?
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 »

Nautilus wrote: Friday 14 February 2020 11:47
jvdz wrote: Friday 03 August 2018 14:53 I will have a look at this as that shouldn't be too hard to add. (His famous last words :D )

Jos
Now after browsing through the thread I noticed this and tried it on a channel where I have the same bot. But immediately if I send a command to this channel, the bot sends a message to the 1-on-1 chat that id is not whitelisted. Is this the channel id that should be whitelisted? I guess my id is still the same. I tried adding the channel id to whitelist, but then dtgbot stopped working altogether. Maybe because the channel id is in format "-##########"? Or am I missing some configuration step?
A channel has its own ID swhich will be the senderID for DTGBOT, so you need to add that ChannelID to the Whitelist.

Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
Nautilus
Posts: 722
Joined: Friday 02 October 2015 12:12
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Finland
Contact:

Re: dtgbot - Domoticz TeleGram BOT

Post by Nautilus »

jvdz wrote: Friday 14 February 2020 12:02
Nautilus wrote: Friday 14 February 2020 11:47
jvdz wrote: Friday 03 August 2018 14:53 I will have a look at this as that shouldn't be too hard to add. (His famous last words :D )

Jos
Now after browsing through the thread I noticed this and tried it on a channel where I have the same bot. But immediately if I send a command to this channel, the bot sends a message to the 1-on-1 chat that id is not whitelisted. Is this the channel id that should be whitelisted? I guess my id is still the same. I tried adding the channel id to whitelist, but then dtgbot stopped working altogether. Maybe because the channel id is in format "-##########"? Or am I missing some configuration step?
A channel has its own ID swhich will be the senderID for DTGBOT, so you need to add that ChannelID to the Whitelist.

Jos
Ok, then I did the correct thing, can it be that it doesn't handle the hyphen (-) in the id correctly and therefore breaks?
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 »

Nautilus wrote: Friday 14 February 2020 13:18 Ok, then I did the correct thing, can it be that it doesn't handle the hyphen (-) in the id correctly and therefore breaks?
It's working fine here. Have you restarted DTGBOT as the whitelist is only read from Domoticz at startup of DTGBOT?
You can see in the DTG.log which id's it found.

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

Nautilus wrote: Friday 14 February 2020 13:18 Ok, then I did the correct thing, can it be that it doesn't handle the hyphen (-) in the id correctly and therefore breaks?
It's working fine here. Have you restarted DTGBOT as the whitelist is only read from Domoticz at startup of DTGBOT?
You can see in the DTG.log which id's it found.

Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
Nautilus
Posts: 722
Joined: Friday 02 October 2015 12:12
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Finland
Contact:

Re: dtgbot - Domoticz TeleGram BOT

Post by Nautilus »

jvdz wrote: Friday 14 February 2020 13:24
Nautilus wrote: Friday 14 February 2020 13:18 Ok, then I did the correct thing, can it be that it doesn't handle the hyphen (-) in the id correctly and therefore breaks?
It's working fine here. Have you restarted DTGBOT as the whitelist is only read from Domoticz at startup of DTGBOT?
You can see in the DTG.log which id's it found.

Jos
Yes I did restart. But I will test again this evening, just in case :)
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 »

Here is an actual DTG.LOG example from last night (with the numbers changed for privacy ;) ), where a command was send via a channel.
I use it to connect my google Home to Domoticz by using IFTTT to send a Telegram message to a channel, which is read and processed by DTGBOT to perform the Domoticz command. 8-)

Code: Select all

2020-02-13 18:01:12 - found command <secsystem>
2020-02-13 18:01:12 - Decoded On
2020-02-13 18:01:13 - Decoded 0
2020-02-13 18:01:13 -  dtgbotLogLevel set to: 0
2020-02-13 18:01:13 - WLidx 20
2020-02-13 18:01:13 - Decoded 86260000|95070000|-100000890000
2020-02-13 18:01:13 - WLString: 86260000|95070000|-100000890000
2020-02-13 18:01:13 - Getting TelegramBotOffset the previous Telegram bot message offset from Domoticz
2020-02-13 18:01:13 - Decoded 724578503
2020-02-13 18:02:03 - 
2020-02-13 18:02:03 - ### In contact with Telegram servers
.................... very long line with dots, one for each longpoll cycle .................
2020-02-13 23:53:17 - WhiteList: 86260000
2020-02-13 23:53:17 - WhiteList: 95070000
2020-02-13 23:53:17 - WhiteList: -100000890000
2020-02-13 23:53:17 - Handle command function started with command-goes-here!On! February 13, 2020 at 11:53PM and -100000890000  Group:-100000890000   channelmsg:true
Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
Nautilus
Posts: 722
Joined: Friday 02 October 2015 12:12
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Finland
Contact:

Re: dtgbot - Domoticz TeleGram BOT

Post by Nautilus »

Well, I tested again - same issue. The log stayed empty, nothing in errors either after adding the new whitelisted id. But nothing happened either. Then I tried again and put a trailing | after the second id and vóila, it works :)
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests