Page 23 of 30
Re: dtgbot - Domoticz TeleGram BOT
Posted: Tuesday 27 July 2021 21:40
by Welsyntoffie
This is what my bash file looks like...
Code: Select all
#!/bin/bash
# Change the rid values below to match the sensors on your devices page in Domoticz
# Settings
SendMsgTo=$1
TmpFileName=$TempFileDir'SystemStatus.txt'
#Send sensor values with telegram
#$TelegramScript msg $SendMsgTo "Please wait, gathering data..."
#curl 'https://api.telegram.org/bot'$TelegramBotToken'/sendMessage?chat_id='$SendMsgTo'&text=Please%20wait%20gathering%20data'
curl --data 'chat_id='$SendMsgTo --data-urlencode 'text=Please wait, gathering data...' 'https://api.telegram.org/bot'$TelegramBotToken'/sendMessage'
##############################################################################
ResultString="-CPU temperature: "
ResultString+=`curl 'http://'$DomoticzIP':'$DomoticzPort'/json.htm?type=devices&rid=34' 2>/dev/null | jq -r .result[]."Temp"`
ResultString+="°C\n"
ResultString+="-CPU Usage: "
ResultString+=`curl 'http://'$DomoticzIP':'$DomoticzPort'/json.htm?type=devices&rid=43' 2>/dev/null | jq -r .result[]."Data"`
ResultString+="\n"
ResultString+="-Memory Usage: "
ResultString+=`curl 'http://'$DomoticzIP':'$DomoticzPort'/json.htm?type=devices&rid=42' 2>/dev/null | jq -r .result[]."Data"`
ResultString+="\n"
ResultString+="-UpTime: "
ResultString+=`curl 'http://'$DomoticzIP':'$DomoticzPort'/json.htm?type=devices&rid=45' 2>/dev/null | jq -r .result[]."Data"`
ResultString+="\n"
Updates=`sudo aptitude search '~U' | wc -l`
if [[ $Updates -ge 1 ]] ; then
ResultString+="-Apt-get updates available: "
ResultString+=$Updates
ResultString+="\n"
fi
InstalledVersion=`curl "http://"$DomoticzIP":"$DomoticzPort"/json.htm?type=command¶m=checkforupdate&forced=true" 2>/dev/null | jq -r ."ActVersion"`
UpdateVersion=`curl "http://"$DomoticzIP":"$DomoticzPort"/json.htm?type=command¶m=checkforupdate&forced=true" 2>/dev/null | jq -r ."Revision"`
if [[ $InstalledVersion -lt $UpdateVersion ]] ; then
ResultString+="-Domoticz update available! (version "
ResultString+=$UpdateVersion
ResultString+=") "
ResultString+="\n"
fi
##############################################################################
#InstalledFW=`curl "http://"$DomoticzIP":"$DomoticzPort"/json.htm?type=hardware&filter=idx=1" 2>/dev/null | jq -r .result[].Mode2 | grep -v "^0"`
InstalledFW=` curl "http://"$DomoticzIP":"$DomoticzPort"/json.htm?type=hardware&filter=idx=1" 2>/dev/null | jq -r '.result[] | select(.Name=="RFXCOM")| .Mode2'`
echo $InstalledFW
if [ "$InstalledFW" -ge 0 -a "$InstalledFW" -le 99 ]; then
grepvar="8" #Type1 firmware
LatestFW=`curl -s "http://blog.rfxcom.com/?feed=rss2" | grep -m 1 "firmware version" | sed "s/.*[^0-9]\([0-9][0-9]\)[^0-9].*/\1/"`
fi
if [ "$InstalledFW" -ge 100 -a "$InstalledFW" -le 199 ]; then
grepvar="1" #Type2 firmware
LatestFW=`curl -s "http://blog.rfxcom.com/?feed=rss2" | grep -m 1 "firmware version" | sed "s/.*[^0-9]\([0-9][0-9][0-9]\)[^0-9].*[^0-9][0-9][0-9][0-9][^0-9].*/\1/"`
fi
if [ "$InstalledFW" -ge 200 -a "$InstalledFW" -le 299 ]; then
grepvar="2" #EXT firmware
LatestFW=`curl -s "http://blog.rfxcom.com/?feed=rss2" | grep -m 1 "firmware version" | sed "s/.*[^0-9][0-9][0-9][0-9][^0-9].*[^0-9]\([0-9][0-9][0-9]\)[^0-9].*/\1/"`
fi
if [[ $InstalledFW -lt $LatestFW ]] ; then
ResultString+="-RFXtrx update available! (version "
ResultString+=$LatestFW
ResultString+=") "
ResultString+="\n"
fi
##############################################################################
echo -e $ResultString > $TmpFileName
ResultString=`cat $TmpFileName`
#$TelegramScript send_text $SendMsgTo $TmpFileName
#curl 'https://api.telegram.org/bot'$TelegramBotToken'/sendMessage?chat_id='$SendMsgTo'&text='"$ResultString"
curl --data 'chat_id='$SendMsgTo --data-urlencode 'text='"$ResultString" 'https://api.telegram.org/bot'$TelegramBotToken'/sendMessage'
Re: dtgbot - Domoticz TeleGram BOT
Posted: Wednesday 28 July 2021 12:03
by jvdz
I just realized what the issue is and can replicate it.
The supplied bash files all needs some changes as the returned text to stdout will now be send as response to the send command.
This is a change since the latest update to allow for changing the returned text in stead of the fixed "Done".
I will have a look and provide an update when done.
I saw you also opened a github issue this morning.
Jos
Re: dtgbot - Domoticz TeleGram BOT
Posted: Wednesday 28 July 2021 12:51
by jvdz
Ok, I have updated the systemstatus.sh bash script so it simply returns the correct string and skips the use of temp file.
Please also give it a try to see if that works for you as well. ALL: This update requires the latest version of DTGBOT.
EDIT 14:15: Also fixed the check for RFXCOM updates
Code: Select all
#!/bin/bash
# Change the rid values below to match the sensors on your devices page in Domoticz
# Settings
SendMsgTo=$1
#Send start of gathering msg to telegram
Result=`curl --data 'chat_id='$SendMsgTo --data-urlencode 'text=Please wait, gathering data...' 'https://api.telegram.org/bot'$TelegramBotToken'/sendMessage' 2>/dev/null`
##############################################################################
ResultString="-CPU temperature: "
ResultString+=`curl 'http://'$DomoticzIP':'$DomoticzPort'/json.htm?type=devices&rid=15' 2>/dev/null | jq -r .result[]."Temp"`
ResultString+="°C\n"
ResultString+="-CPU Usage: "
ResultString+=`curl 'http://'$DomoticzIP':'$DomoticzPort'/json.htm?type=devices&rid=16' 2>/dev/null | jq -r .result[]."Data"`
ResultString+="\n"
ResultString+="-Memory Usage: "
ResultString+=`curl 'http://'$DomoticzIP':'$DomoticzPort'/json.htm?type=devices&rid=12' 2>/dev/null | jq -r .result[]."Data"`
ResultString+="\n"
ResultString+="-SD usage: "
ResultString+=`curl 'http://'$DomoticzIP':'$DomoticzPort'/json.htm?type=devices&rid=13' 2>/dev/null | jq -r .result[]."Data"`
ResultString+="\n"
Updates=`sudo aptitude search '~U' | wc -l`
if [[ $Updates -ge 1 ]] ; then
ResultString+="-Apt-get updates available: "
ResultString+=$Updates
ResultString+="\n"
fi
InstalledVersion=`curl "http://"$DomoticzIP":"$DomoticzPort"/json.htm?type=command¶m=checkforupdate&forced=true" 2>/dev/null | jq -r ."ActVersion"`
UpdateVersion=`curl "http://"$DomoticzIP":"$DomoticzPort"/json.htm?type=command¶m=checkforupdate&forced=true" 2>/dev/null | jq -r ."Revision"`
if [[ $InstalledVersion -lt $UpdateVersion ]] ; then
ResultString+="-Domoticz update available! (version "
ResultString+=$UpdateVersion
ResultString+=") "
ResultString+="\n"
fi
##############################################################################
InstalledFW=`curl "http://"$DomoticzIP":"$DomoticzPort"/json.htm?type=hardware&filter=idx=1" 2>/dev/null | jq -r '.result[] | select(.Name=="RFXCOM")| .version'`
InstalledFW=`echo $InstalledFW | sed "s/.*\/\([0-9]*\)[^0-9]*/\1/"`
LatestFW=`curl -s "http://blog.rfxcom.com/?feed=rss2" | grep -m 1 "firmware version" | sed "s/.*version \(.*\)<\/t.*/\1/"`
if [[ $InstalledFW -lt $LatestFW ]] ; then
ResultString+="-RFXtrx update available: $LatestFW"
ResultString+=" installed: $InstalledFW"
ResultString+="\n"
fi
##############################################################################
echo -ne "$ResultString"
Re: dtgbot - Domoticz TeleGram BOT
Posted: Wednesday 28 July 2021 17:59
by Welsyntoffie
jvdz wrote: ↑Wednesday 28 July 2021 12:03
I saw you also opened a github issue this morning.
Yes I did. I thought I was at the end of my rope here. Sorry
Re: dtgbot - Domoticz TeleGram BOT
Posted: Wednesday 28 July 2021 18:22
by Welsyntoffie
jvdz wrote: ↑Wednesday 28 July 2021 12:51
Ok, I have updated the systemstatus.sh bash script so it simply returns the correct string and skips the use of temp file.
Please also give it a try to see if that works for you as well. ALL: This update requires the latest version of DTGBOT.
EDIT 14:15: Also fixed the check for RFXCOM updates
Well done. I dont get the unwanted message anymore.
However. The message gathering data comes through as a message.
The 2nd message with the data comes as a reply.
Before this update the message containing the data was a message/response and not a reply

Right click and open image in new tab works.
Another image

of what I would love to see
Edit 19:59 - Been playing around with it some more. The "Reply" thing is not that big of an issue. The original issue is resolved. I get what I want when I want it. Thank you
Re: dtgbot - Domoticz TeleGram BOT
Posted: Wednesday 28 July 2021 19:59
by jvdz
I know and that is because in the past you would get "Done" as a fixed reply...right?
I made the change in the last version of DTGBOT.LUA that when the bash script doesn't return anything it will default to "Done", but when there is any output piped to stdout, this will be the reply content.
Hence the reason all bash scripts needs changes.Honestly: I never use them and they have been broken for a while now I notices as JSON calls to Domoticz and to RFXCOM aren't correct anymore, which I have now also adapted in this script. (my local version has some more changes.)
Either way: These supplied scripts are meant as examples which you can adapt to your own needs.
ps: Images aren't there so don't know exactly what it is you would like to see.
Jos
Re: dtgbot - Domoticz TeleGram BOT
Posted: Wednesday 28 July 2021 20:07
by Welsyntoffie
https://imgur.com/BkiNJ5w
That should do it.
Thank you for the update.
But you already explained why it replies. I am NO programmer, so playing around with the bash scripts will tak eme some time.
Raspberry Pi is new to me. Been using arduino's and SIM900's to get notifications.
This method is cheap and modern, keeping up with the changing times and leaving sms system's behind.
Edit 20:15. Here is the image of the updated output I get.
https://ibb.co/pym41qk - Good enough
everything is working. Notifications, relay switching, virtual button switching. Getting temps from sensors around the house and outside and other analog sensors I have.
You claim its broken, but its working great for me so far. 2 days
Re: dtgbot - Domoticz TeleGram BOT
Posted: Wednesday 28 July 2021 20:23
by jvdz
Good to see it is working for you. My claim it was broken was about the checks it does in the script.
The check for the RFXCOM wasn't working anymore and I believe the same counts for the check for a new Domoticz version.
Other than that it will report the device statuses fine.

I've pushed the latest version I have now to GITHUB.
Re: dtgbot - Domoticz TeleGram BOT
Posted: Wednesday 28 July 2021 21:04
by Welsyntoffie
jvdz wrote: ↑Wednesday 28 July 2021 20:23
The check for the RFXCOM wasn't working anymore and I believe the same counts for the check for a new Domoticz version.
o, I see, I am not using any RFXcom. I will read up on bash and lua like I did few years ago when I started with arduino and then play around.
But for now its working perfect for my needs.
Thank you
Re: dtgbot - Domoticz TeleGram BOT
Posted: Tuesday 03 August 2021 5:14
by Welsyntoffie
For some reason my dtgbot hangs. Monit does not restart the service.
Monit monitor says Execution failed | Does not Exist. I installed monit as described and used the code provided.
I I manually stop dtgbot service and then start it monit displays OK and the uptime starts counting.
I also noticed the dtgloop inside monit will monitor for a while then disable monitoring, even though the file is still being updated constantly as described.
Do you the cause of this maybe. or trouble shooting
Re: dtgbot - Domoticz TeleGram BOT
Posted: Tuesday 03 August 2021 9:04
by jvdz
Did you set the execution flag with chmod +x for the script ran by monit to restart the dtgbot service?
Re: dtgbot - Domoticz TeleGram BOT
Posted: Tuesday 03 August 2021 13:36
by Welsyntoffie
jvdz wrote: ↑Tuesday 03 August 2021 9:04
Did you set the execution flag with chmod +x for the script ran by monit to restart the dtgbot service?
sudo chmod +x /home/pi/dtgbot/stopbot.sh
and
sudo chmod +x /home/pi/dtgbot/restartbot.sh
I did this aswell... sudo chmod +x /etc/profile.d/DomoticzData.sh
Execution failed | Does not exist
I did aswell...
Code: Select all
N.B. If your Domoticz system is password protected even for local network then you will need to replace "127.0.0.1" with "username:[email protected]"
And set it to be executable:
DONE
Re: dtgbot - Domoticz TeleGram BOT
Posted: Tuesday 03 August 2021 15:44
by jvdz
When do you get this?
Welsyntoffie wrote: ↑Tuesday 03 August 2021 13:36
Execution failed | Does not exist
To debug you can check all of these to get some insight where things are failing. You can also email the info so I can check for you.
What is the result of:
ls -l /home/pi/dtgbot
What happens when you run those stop.sh & restart.sh manually?
What information do you see in dtgbot.log & dtb.log.errors?
what information do you see in monit.log?
Re: dtgbot - Domoticz TeleGram BOT
Posted: Wednesday 04 August 2021 1:30
by Welsyntoffie
I'm not at home, so was trying to VNC and check all this. When I finally got access I noticed that it rebooted (watchdog). But even after this dtgbot was still not working. So what I did next from from a fresh reboot...
jvdz wrote: ↑Tuesday 03 August 2021 15:44
When do you get this?
Shows up in monit web interface.
What is the result of: ls -l /home/pi/dtgbot
Code: Select all
drwxr-xr-x 2 pi pi 4096 Jul 30 02:01 bash
-rwxr-xr-x 1 pi pi 1586 Aug 2 00:55 cam_collage2.sh
-rwxr-xr-x 1 pi pi 1328 Aug 2 01:08 cam_collage.sh
-rwxr-xr-x 1 pi pi 394 Jul 31 02:36 cam.sh
-rwxr-xr-x 1 pi pi 118 Jul 26 22:23 dtgbot.sh
-rw-r--r-- 1 pi pi 2081 Jul 30 06:29 dtgbot.cfg
-rw-r--r-- 1 pi pi 24599 Jul 29 20:49 dtgbot.lua
-rw-r--r-- 1 pi pi 12423 Jul 26 22:23 dtg_domoticz.lua
drwxr-xr-x 2 pi pi 4096 Jul 26 22:23 img
drwxr-xr-x 2 pi pi 4096 Jul 27 21:50 lua
-rw-r--r-- 1 pi pi 583 Jul 26 22:23 monit.DTGBOTconfig
-rw-r--r-- 1 pi pi 12423 Jul 26 22:23 README.md
-rwxr-xr-x 1 pi pi 964 Aug 2 00:32 restartbot.sh
-rwxr-xr-x 1 pi pi 443 Jul 26 22:23 stopbot.sh
What happens when you run those stop.sh & restart.sh manually?
Nothing was happening. In terminal ran stop.sh and it went to next line after awhile. Same with restart.sh.
What information do you see in dtgbot.log & dtb.log.errors?
Yeah, this helped. dtb.log.errors was empty.
dtgbot.log was interesting.
Domoticz did not return getuservariables after 21 attempts
So I stopped domoticz systemctl stop domoticz.service and then started it again.
I then used sudo service dtgbot stop waited 60 seconds and used sudo service dtgbot start
After that I started receiving my queued messages.
What happens when you run those stop.sh & restart.sh manually?
This I will test again once I am at home. Using a 3G connection and an android phone via VNC is difficult.
EDIT 04:27 - The stop script actually worked and the service was stopped. The restart script does not do anything. I managed some bit with my phone and VNC.
Re: dtgbot - Domoticz TeleGram BOT
Posted: Wednesday 04 August 2021 7:15
by Welsyntoffie
jvdz wrote: ↑Tuesday 03 August 2021 15:44
When do you get this?
What happens when you run those stop.sh & restart.sh manually?
When I run restartbot.sh manual...
Code: Select all
04/08/2021 07:08:48 restartbot.sh started but is already running so stopping this one. (3)
2021-08-04 07:08:50
2021-08-04 07:09:41
2021-08-04 07:10:33
2021-08-04 07:11:24
2021-08-04 07:12:15
2021-08-04 07:13:06
2021-08-04 07:13:58
Monit log...
Code: Select all
[SAST Aug 4 07:25:04] info : 'dtgbot' trying to restart
[SAST Aug 4 07:25:04] info : 'dtgbot' stop: '/home/pi/dtgbot/stopbot.sh'
[SAST Aug 4 07:25:25] info : 'dtgbot' start: '/home/pi/dtgbot/restartbot.sh'
[SAST Aug 4 07:25:45] error : 'dtgbot' failed to start (exit status -1) -- Program '/home/pi/dtgbot/restartbot.sh' timed out after 20 s
[SAST Aug 4 07:25:45] info : 'dtgbot' restart action failed
[SAST Aug 4 07:25:45] error : 'dtgbot' process is not running
[SAST Aug 4 07:25:45] info : 'dtgbot' trying to restart
[SAST Aug 4 07:25:45] info : 'dtgbot' start: '/home/pi/dtgbot/restartbot.sh'
[SAST Aug 4 07:26:05] error : 'dtgbot' failed to start (exit status -1) -- Program '/home/pi/dtgbot/restartbot.sh' timed out after 20 s
[SAST Aug 4 07:28:05] error : 'dtgbot' process is not running
[SAST Aug 4 07:28:05] info : 'dtgbot' trying to restart
[SAST Aug 4 07:28:05] info : 'dtgbot' start: '/home/pi/dtgbot/restartbot.sh'
[SAST Aug 4 07:28:25] error : 'dtgbot' failed to start (exit status -1) -- Program '/home/pi/dtgbot/restartbot.sh' timed out after 20 s
EDIT 07:76...
This seems to work perfect... I changed monit check to 300 seconds and time outs to 60 seconds...
Re: dtgbot - Domoticz TeleGram BOT
Posted: Saturday 04 September 2021 14:53
by tbryla
Hello,
At the beginning I'd like to say that it's an awesome project. I spent last few days playing with dgtbot and it's amazing. As I plan to add more devices in my system, I want to start using dgtmenu. The problem is that, when I send "dgtmenu" I recive the message below and only "menu" button is available.

- domoticz.png (188.05 KiB) Viewed 1515 times
How to add more buttons to dtgmenu? Or maybe it's just a matter of configuration and I 've missed something? Below is my DomoticzData.sh file.
Code: Select all
#!/bin/bash
# Variables to avoid having to set local system information in individual automation scripts
#I can't get the next line to work during start-up so have gone to 127 instead
#export DomoticzIP=$(hostname -I|sed 's/[ ]*$//')
export DomoticzIP="XXXXXXXXXXXXXXXXXXX"
export DomoticzPort="8080"
export TempFileDir="/var/tmp/"
export BotHomePath="/home/tbryla/dtgbot/"
export BotBashScriptPath=$BotHomePath"bash/"
export BotLuaScriptPath=$BotHomePath"lua/"
export BotLuaLog=$TempFileDir"dtb.log"
export TelegramChatId='XXXXXXXXXXXXXXXXXXXXXXX'
export TelegramBotToken="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
export TelegramBotOffset="TelegramBotOffset"
export TelegramBotMenu="On"
export TelegramBotLogLevel=2
Thanks
Tom
Re: dtgbot - Domoticz TeleGram BOT
Posted: Saturday 04 September 2021 15:06
by jvdz
tbryla wrote: ↑Saturday 04 September 2021 14:53
How to add more buttons to dtgmenu?
Or maybe it's just a matter of configuration and I 've missed something? Below is my DomoticzData.sh file.
DTGMENU will show each defined "RoomPlan" as a separate menu button and when clicked show the devices in the "RoomPlan" without any further config
--- or ---
you can define buttons manually in file dtgmenu.cfg:
Code: Select all
---------------------------------
--> define the mainmenu menuitems.
-- ["xxx"] = Specify the name of the Submenu. EG: Lights; Screens; Misc
-- whitelist ="" insert the whitelisted numbers for this menu or lleave blank to shoe it for everybody
-- showdevstatus="" The devices status will be inserted in the menubuttons when set to "y" for this submenu. Useful for ligths,screens etc
-- Menuwidth =x Override the default DevMenuwidth with the value x for this specific submenu.
--
--> define the buttons(Device/Scene/Command) of each submenu
-- buttons={
-- ["xxx"] = Specify the name of the Device/Scene or command.
-- whitelist ="" insert the whitelisted numbers for this button or leave blank to shoe it for everybody
-- actions ="" By default, the "menu_lang["XX"].devices_options" will be shown for the different DeviceTypes. This parameter allow you to override this default
-- showactions =true Show the actions right away for this device when the submenu is selected.
-- prompt =true Prompt for an extra paramters. eg when button=temperature, you need the sensor name prompted before running the command.
static_dtgmenu_submenus = {
["Misc"] = {whitelist="",showdevstatus="n",Menuwidth=3,
buttons={
["refresh"] = {whitelist=""},
["dtgmenu"] = {whitelist=""},
["systemstatus"]= {whitelist=""},
["tempall"] = {whitelist=""},
["battery"] = {whitelist="",prompt=true},
["batteries"] = {whitelist=""},
}
},
-- ["menu2"] = {whitelist="",showdevstatus="y",Menuwidth=2,
-- buttons={
-- ["switch1"] = {whitelist=""},
-- ["switch2"] = {whitelist=""},
-- }
-- },
}
Jos
Re: dtgbot - Domoticz TeleGram BOT
Posted: Saturday 04 September 2021 18:11
by tbryla
Hi Jos,
That's odd as I already have defined a plan and added devices there. How can I troubleshot it?
Thanks
Tomasz
Re: dtgbot - Domoticz TeleGram BOT
Posted: Saturday 04 September 2021 18:24
by jvdz
Just have a look at the dtgbot.log for issues.
We can also take this offline and I can have a look for you at both logs (dtgbot.log & dtgbot.log.error) to see what is happening. just mail them to my github email address. It helps to set the domoticz variable TelegramBotLoglevel to 9 and restart dtgbot for much more detailed messages.
Jos
Re: dtgbot - Domoticz TeleGram BOT
Posted: Sunday 05 September 2021 17:47
by tbryla
Hi Jos,
Thank you for takinkg this offline and helping me to solve the problem. For other users who may have the same issue. Please set this variable in your domoticz server, not in DomoticzData.sh file

.

- 2021-09-05 17_44_33-Window.png (9.42 KiB) Viewed 1493 times
Regards
Tom