Page 14 of 30

Re: dtgbot - Domoticz TeleGram BOT

Posted: Thursday 05 October 2017 23:13
by thorbj
So dtgbot and the Telegram notification system isn't the same? Sorry for my mix-up.

I have this dzVents script:

Code: Select all

return {
    active = true,
    on = {
        timer = {'at 22:42-06:00'},
    },
    execute = function(domoticz, device)
        -- your script logic goes here, something like this:

        if (domoticz.devices('AJ lampe').state == 'On') then
            domoticz.devices('AJ lampe').switchOff()
            domoticz.notify('Leselys AJ lampe slått av for natten.', domoticz.PRIORITY_LOW)
            domoticz.log('Leselys AJ lampe slått av for natten.')
        end
    end
}
here I have the followinng command passing a notification to domoticz:

Code: Select all

domoticz.notify('Leselys AJ lampe slått av for natten.', domoticz.PRIORITY_LOW)
When this script triggers, I see the following in the log: Notification sent (http) => Success
but in my telegram client on my phone I only get a message saying -2.

EDIT: I may have posted in the wrong forum. I tested with pushbullet also, and I got the same message there. I suppose it is a dzVents/domoticz/lua issue.

Re: dtgbot - Domoticz TeleGram BOT

Posted: Friday 06 October 2017 10:42
by jvdz
thorbj wrote: Thursday 05 October 2017 23:13 So dtgbot and the Telegram notification system isn't the same? Sorry for my mix-up.
No worries, but the sending of notifications is done by an https request to the setup telegram bot.
DTGBOT is used to read message send to the Telegram Bot to perform commands/actions in Domoticz.
thorbj wrote: Thursday 05 October 2017 23:13 EDIT: I may have posted in the wrong forum. I tested with pushbullet also, and I got the same message there. I suppose it is a dzVents/domoticz/lua issue.
Yes, that seems like a good place to ask this question then as I am not using dzVents and still am in plain LUA scripting mode. :)

Jos

Re: dtgbot - Domoticz TeleGram BOT

Posted: Sunday 19 November 2017 2:38
by mrbrown38
I've hit a wall and think I need some help. I am running:
Raspberry Pi 3
Raspbian Stretch Lite (2017-09-07)
Domoticz (Beta v3.8740) - Note: I had to update to the beta release to get Domoticz to work on Stretch.

The issue I am having is with the lua libraries (I think). I have wiped the SD card for my setup and started from scratch twice with the same result following the instructions on Page 1. This is the error I am given from dtb.log.errors:

Code: Select all

/usr/bin/lua5.2: error loading module 'ssl.core' from file '/usr/local/lib/lua/5.2/ssl.so':
	libssl.so.1.0.0: cannot open shared object file: No such file or directory
stack traceback:
	[C]: in ?
	[C]: in function 'require'
	/usr/local/share/lua/5.2/ssl.lua:7: in main chunk
	[C]: in function 'require'
	/usr/local/share/lua/5.2/ssl/https.lua:10: in main chunk
	[C]: in function 'require'
	/home/pi/dtgbot/dtgbot.lua:95: in main chunk
	[C]: in ?
The files are in their respective directories, even though it says no such file or directory. I've been banging my head on the issue all day and am stumped. Any advice?

Re: dtgbot - Domoticz TeleGram BOT

Posted: Sunday 19 November 2017 9:19
by jvdz
Isn't this the same issue as we've seen with the latest Domoticz Beta version where we had to load this separate ssl version?
viewtopic.php?f=6&t=18932&start=40#p149295

I am not on Stretch so can't test this.

Jos

Re: dtgbot - Domoticz TeleGram BOT

Posted: Sunday 19 November 2017 16:45
by mrbrown38
Thank you so much, jvdz! The following from that post resolved my issue:

Code: Select all

sudo wget http://ftp.nl.debian.org/debian/pool/main/o/openssl/libssl1.0.0_1.0.1t-1+deb8u6_armhf.deb
sudo dpkg -i libssl1.0.0_1.0.1t-1+deb8u6_armhf.deb

Re: dtgbot - Domoticz TeleGram BOT

Posted: Monday 27 November 2017 20:39
by quilae
Just for the record:
I've tried to install dtgbot according to the instructions on this page: https://www.domoticz.com/wiki/Remote_Co ... legram_Bot.
Result: a working system in 1 attempt.

I found a few things that might be interesting for the wiki:
- I struggled a while with the term TelegramChatId in the file DomoticzData.sh. Since I've a working system this id is apparently the id of the user the bot is supposed to chat with. So usually that's your own id (not the id of bot itself).
- I decided to skip the part about building and installing jq 1.4. I noticed there's a jq version 1.5 for over two years now so jq 1.4 seems obsolete now. Instead I just did: apt-get install jq and this yields also jq 1.5.
Thanks and keep up the good work.

Re: dtgbot - Domoticz TeleGram BOT

Posted: Thursday 25 January 2018 12:12
by woody4165
Hi all
I'm having troubles with DTGBOT that freezes from time to time.
Now it's freezed, meaning that if I run

Code: Select all

sudo service dtgbot status
I get

Code: Select all

● dtgbot.service - LSB: A Telegram bot designed to control Domoticz
   Loaded: loaded (/etc/init.d/dtgbot)
   Active: active (running) since Wed 2018-01-24 20:01:36 CET; 16h ago
  Process: 746 ExecStart=/etc/init.d/dtgbot start (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/dtgbot.service
           ├─778 /bin/sh /home/linaro/dtgbot/dtgbot /var/run/dtgbot.pid
           └─790 /usr/bin/lua5.2 /home/linaro/dtgbot/dtgbot.lua

Warning: Journal has been rotated since unit was started. Log output is incomplete or unavailable.
that seems to be ok, but if I send the /dtgmenu from the bot I get no response.

If I restart the service, it start working again, but it will freeze again in a few hours.

I've updated yesterday following the Wiki to the latest version from GitHub.

What can I check?

Thanks

Re: dtgbot - Domoticz TeleGram BOT

Posted: Thursday 25 January 2018 13:35
by jvdz
I have had this also happen in the past and made some change to allow Monit to monitor this situation.
It seems to happen when DTGBOT has made the curl call to Telegram and is in waiting mode for either a timeout or an message to arrive, and the internet connection is somehow interrupted. In this case the Curl call to Telegram stays open forever resulting in a hanging DTGBOT script.
I have added a extra logging to write a date/time to a logfile in the Tempdir define directory for DTGBOT and also added a rule to Monit to test for the age of this file:

Code: Select all

check file dtgloop with path /var/tmp/dtgloop.txt
  start program = "/home/pi/dtgbot/restartbot.sh" timeout 20 seconds
  if timestamp > 2 minutes then restart
  if 5 restarts within 5 cycles then timeout
Just verify the filelocation and add this to Monit. The DTGBOT template for Monit is also available in Github.
https://github.com/steps39/dtgbot/blob/ ... GBOTconfig

Jos

Re: dtgbot - Domoticz TeleGram BOT

Posted: Thursday 25 January 2018 14:16
by woody4165
Thanks Jo's.

I will try and let you know.

Just for curiosity, where can I find information on how dtgbot works?
My domoticz is not open to internet and I'm wondering how the bot communicate to dtgbot without having any port open

Thanks

Re: dtgbot - Domoticz TeleGram BOT

Posted: Thursday 25 January 2018 18:04
by jvdz
woody4165 wrote: Thursday 25 January 2018 14:16 Just for curiosity, where can I find information on how dtgbot works?
My domoticz is not open to internet and I'm wondering how the bot communicate to dtgbot without having any port open

Thanks
I assume you mean that you do not have a port forwarded from the Internet side to the Internal Domoticz server?
The way Telegram Bot/DTGBOT works is that an DTG.LUA script ( the Service) is ran and has an loop in which it starts an session to retrieve the current messages. It will return immediately in case messages are queued or elese the session will "hang" for about 1 minute after which it ends anyway. THe script tests whether any message needs to be processed and then start from the top with the next iteration.
So all you need is to be able to browse and Internet Website from Domoticz as script initiates the connection.

Jos

Re: dtgbot - Domoticz TeleGram BOT

Posted: Friday 26 January 2018 8:09
by woody4165
Even after placing the check in /etc/monit/monitrc dtgbot freezes

Code: Select all

# Monitor the DTGBOT Service
check process dtgbot with pidfile /var/run/dtgbot.pid
  start program = "/home/linaro/dtgbot/restartbot.sh" timeout 20 seconds
  stop  program = "/home/linaro/dtgbot/stopbot.sh" timeout 20 seconds
  if 5 restarts within 5 cycles then timeout

# Monitor the DTGBOT loop file which should be updated each minute.
# Restart DTGBOT when not updated in 2 minutes
check file dtgloop with path /var/tmp/dtgloop.txt
  start program = "/home/linaro/dtgbot/restartbot.sh" timeout 20 seconds
  if timestamp > 2 minutes then restart
  if 5 restarts within 5 cycles then timeout
These are the monit messages

Code: Select all

Timestamp failed Service dtgloop 

	Date:        Fri, 26 Jan 2018 03:54:52
	Action:      restart
	Host:        cubietruck
	Description: timestamp test failed for /var/tmp/dtgloop.txt

Your faithful employee,
Monit

Code: Select all

Execution failed Service dtgloop 

	Date:        Fri, 26 Jan 2018 03:54:55
	Action:      alert
	Host:        cubietruck
	Description: failed to start (exit status -1) -- no output

Your faithful employee,
Monit

Code: Select all

Timeout Service dtgloop 

	Date:        Fri, 26 Jan 2018 04:19:57
	Action:      unmonitor
	Host:        cubietruck
	Description: service restarted 5 times within 5 cycles(s) - unmonitor

Your faithful employee,
Monit

but strangely the dtgbot service is "active (running)" but no response....

What else can I check?

Thanks

Re: dtgbot - Domoticz TeleGram BOT

Posted: Friday 26 January 2018 8:23
by jvdz
Did you actually check whether the file exists?
Is the file location correct?
Are you running a recent version of dtgbot?

Jos

Re: dtgbot - Domoticz TeleGram BOT

Posted: Friday 26 January 2018 8:30
by woody4165
File exists and location is /var/tmp

Code: Select all

-rw-r--r-- 1 root root   8071 Jan 26 08:25 /var/tmp/dtb.log
-rw-r--r-- 1 root root 693714 Jan 26 08:25 /var/tmp/dtgloop.txt
I downloaded dtgbot two days ago following the wiki.

Don't know if this is the issue, but I just saw that the .sh files (restartbot and stopbot) where not executable, now I changed with chmod 755.

Rebooted the cubietruck and I will check during the day.

Re: dtgbot - Domoticz TeleGram BOT

Posted: Friday 26 January 2018 8:48
by simonrg
woody4165 wrote: Friday 26 January 2018 8:30Don't know if this is the issue, but I just saw that the .sh files (restartbot and stopbot) where not executable, now I changed with chmod 755.
The scripts need to be executable or they will not run, so assuming your permissions are now:

Code: Select all

-rwxr-xr-x 1 pi pi   963 Aug 23 08:56 restartbot.sh
-rwxr-xr-x 1 pi pi   442 Aug 23 08:56 stopbot.sh
then monit should do its job and keep dtgbot running.

Re: dtgbot - Domoticz TeleGram BOT

Posted: Friday 26 January 2018 8:54
by woody4165
Yes, now they are now executable

Code: Select all

-rwxr-xr-x 1 linaro admin 963 Jan 24 12:22 restartbot.sh
-rwxr-xr-x 1 linaro admin 442 Jan 24 12:22 stopbot.sh
In the wiki http://www.domoticz.com/wiki/Remote_Con ... legram_Bot is not reported to make them executable, but only the dtgbot file and the files in dtgbot/bash.
Maybe it should be updated.

Thanks!

Re: dtgbot - Domoticz TeleGram BOT

Posted: Friday 26 January 2018 17:02
by jvdz
Agree the wiki needs some updating.Simon was doing that in the past but had been pretty busy of late, so will take it up when I have some time. Firstly need to figure out how to get access to be able to modify the wiki.

Jos

Re: dtgbot - Domoticz TeleGram BOT

Posted: Friday 26 January 2018 23:07
by simonrg
woody4165 wrote: Friday 26 January 2018 8:54 n the wiki http://www.domoticz.com/wiki/Remote_Con ... legram_Bot is not reported to make them executable, but only the dtgbot file and the files in dtgbot/bash.
Great, it looks like you have been in and updated the wiki as now install says:

Code: Select all

cd ~
git clone https://github.com/steps39/dtgbot.git
cd ~/dtgbot
chmod 755 dtgbot
chmod 755 *.sh
cd ~/dtgbot/bash
chmod 755 *.sh
So all the .sh are corectly made executable.

Good thing with the wiki is we can all improve it.
Thanks, Simon

Re: dtgbot - Domoticz TeleGram BOT

Posted: Friday 26 January 2018 23:42
by simonrg
jvdz wrote: Friday 26 January 2018 17:02 Agree the wiki needs some updating.Simon was doing that in the past but had been pretty busy of late, so will take it up when I have some time. Firstly need to figure out how to get access to be able to modify the wiki.

Jos
Jos, thanks for being so active over dtgbot, all recent improvements have been yours. I have added your Monit set-up into the wiki as a new section "Keeping dtgbot Running", hope it makes sense please correct / rewrite as you feel most useful. I seem to have been busy since August 2015, as that was the last time I updated the wiki page :lol: .
Best wishes, Simon
P.S. to access the wiki you should just be able to log on with your forum user name and password, then Edit will appear on each section of a page.

Re: dtgbot - Domoticz TeleGram BOT

Posted: Saturday 27 January 2018 7:29
by jvdz
Hey Simon, thanks for that quick update.
Will have a look and make updates where appropriate.

Jos

Re: dtgbot - Domoticz TeleGram BOT

Posted: Saturday 27 January 2018 8:52
by woody4165
Hi all

I've made the small modification in the Wiki regarding the

Code: Select all

chmod 755 *.sh
in the dtgbot folder

Still having issue even after this.

This morning dtgbot has freezed again.

in the dtb.log no errors, last rows are:

Code: Select all

2018-01-26 21:43:40 - Handle command function started with /dtgmenu and xxxx
2018-01-26 21:43:40 - dtgbot: Start DTGMENU ... (1) /dtgmenu
2018-01-26 21:43:40 - ==> menu.lua process:/dtgmenu
2018-01-26 21:43:40 - Decoded On
2018-01-26 21:43:40 -  Set DTGMENU Off
2018-01-26 21:43:40 - ==< Show main menu
2018-01-26 21:43:41 - Message sent (1) 200
2018-01-26 21:43:41 - dtgbot: dtgmenu ended and text send ...return:200
2018-01-26 21:43:41 - Succesfully handled incoming request
In the dtgloop.txt I get

Code: Select all

2018-01-27 03:43:18
2018-01-27 03:44:08
2018-01-27 03:44:58
2018-01-27 03:45:49
2018-01-27 03:46:39
2018-01-27 03:47:30
2018-01-27 03:48:20
2018-01-27 03:49:11
2018-01-27 03:50:01
2018-01-27 03:50:52
What is strange seeing this file, is that it gets interruptions every night around 3:50.

Then I found that around that time my router Fritz does a forced close of the VDSL connection. It last just the time to get back the line.

So I've tested right now restarting dtgbot, testing was working and simulating a forced close of my xDSL connection and...dtgbot now does not respond.
What can I do in this case? This mean that everytime there is any kind of connection closing I have to restart the service?

If someone can test this and return if it's only me having this issue, could be great.

In the meantime, I've added a dtgbot restart in crontab at 4:10AM everynight...

Thanks