Page 9 of 30

Re: dtgbot - Domoticz TeleGram BOT

Posted: Friday 29 April 2016 16:25
by jvdz
The DTGBOT is running a loop requesting the "getUpdates?timeout=60&offset=xxxx" status. This will wait for about a minute for incoming messages after which the connection is ended by the server. In case there is no message the request is simply done again.
In case a Telegram message arrives for the BOT, the call returns right away and the message is processed.
This is the basic process used to retrieve the messages for the BOT.
The alternative could be to have Telegram deliver the messages, but that would mean you need to open up a port on your firewall and NAT to your PI, but this isn't implemented.

Jos

Re: dtgbot - Domoticz TeleGram BOT

Posted: Wednesday 25 May 2016 22:42
by woody4165
Hi all

don't understand why, but dtgbot stopped working.
It worked well until some days ago, and now nothing...

I'm getting into the roomplan error, as explained in the last part of the wiki http://www.domoticz.com/wiki/Remote_Con ... legram_Bot

But I have four Roomplan defined, as I already did, and no change from when it was working.

I get exacting the same errors as descrobed in the Wiki.

I get also active(exited) when I check status

Code: Select all

● dtgbot.service - LSB: A Telegram bot designed to control Domoticz
   Loaded: loaded (/etc/init.d/dtgbot)
   Active: active (exited) since mer 2016-05-25 22:45:14 CEST; 12s ago
  Process: 3985 ExecStop=/etc/init.d/dtgbot stop (code=exited, status=0/SUCCESS)
  Process: 4148 ExecStart=/etc/init.d/dtgbot start (code=exited, status=0/SUCCESS)

mag 25 22:45:14 raspberrypi dtgbot[4148]: Starting Telegram Bot for Domoticz ... Done.
mag 25 22:45:14 raspberrypi systemd[1]: Started LSB: A Telegram bot designed to control Do...cz.
Hint: Some lines were ellipsized, use -l to show in full.

What can I check?

Thanks

Re: dtgbot - Domoticz TeleGram BOT

Posted: Thursday 26 May 2016 9:25
by jvdz
Set the domoticz user variable TelegramBotLoglevel to 2, start dtgbot and show or PM the dtg.log and dtg.log.errors so I can see what is happening.

Jos

Re: dtgbot - Domoticz TeleGram BOT

Posted: Thursday 26 May 2016 11:10
by woody4165
Hi jvdz

I created the uservariable TelegramBotLogLevel, since I haven't got it.

Code: Select all

TelegramBotLogLevel	Integer	2
I then reboot it and this is what I have in dtb.log

Code: Select all

2016-05-26 10:47:48 - DomoticzIP: 192.168.1.xxx
2016-05-26 10:47:48 - DomoticzPort: 8080
2016-05-26 10:47:48 - BotHomePath: /home/pi/dtgbot/
2016-05-26 10:47:48 - BotLuaScriptPath: /home/pi/dtgbot/lua/
2016-05-26 10:47:48 - BotBashScriptPath: /home/pi/dtgbot/bash/
2016-05-26 10:47:48 - TelegramBotToken: xxxxxxxx
2016-05-26 10:47:48 - TelegramBotOffset: TelegramBotOffset
2016-05-26 10:47:48 - -----------------------------------------
2016-05-26 10:47:48 - Starting Telegram api Bot message handler
2016-05-26 10:47:48 - -----------------------------------------
2016-05-26 10:47:51 - Domoticz returned getuservariables after 3 attempts

and the dtb.log.errors

Code: Select all

/usr/bin/lua5.2: /home/pi/dtgbot//dtg_domoticz.lua:125: attempt to get length of global 'result' (a nil value)
stack traceback:
	/home/pi/dtgbot//dtg_domoticz.lua:125: in function 'device_list_names_idxs'
	/home/pi/dtgbot/dtgbot.lua:174: in function 'dtgbot_initialise'
	/home/pi/dtgbot/dtgbot.lua:229: in main chunk
	[C]: in ?
I don't see any differences in the log with this uservariable set to 2 or without it.

Re: dtgbot - Domoticz TeleGram BOT

Posted: Thursday 26 May 2016 11:32
by jvdz
ah, i see the debug logging is set later so that indeed doesn't give more information. guess that needs changing.
Could you provide the output for this URL:

Code: Select all

http://xxx.xxx.xxx.xxx:8080/json.htm?type=plans&order=name&used=true
Jos

Re: dtgbot - Domoticz TeleGram BOT

Posted: Thursday 26 May 2016 11:44
by woody4165
This is what I get:

Code: Select all

{
  "result" : [
     {
        "Devices" : 12,
        "Name" : "Meteo",
        "Order" : "2",
        "idx" : "x"
     },
     {
        "Devices" : 0,
        "Name" : "NAS",
        "Order" : "3",
        "idx" : "x"
     },
     {
        "Devices" : 6,
        "Name" : "Persiane",
        "Order" : "4",
        "idx" : "x"
     },
     {
        "Devices" : 7,
        "Name" : "Irrigation",
        "Order" : "5",
        "idx" : "x"
     }
  ],
  "status" : "OK",
  "title" : "Plans"
}
Thanks

Re: dtgbot - Domoticz TeleGram BOT

Posted: Thursday 26 May 2016 11:50
by woody4165
Now I removed the NAS roomplan which has no devices inside, but no changes

Re: dtgbot - Domoticz TeleGram BOT

Posted: Thursday 26 May 2016 12:02
by jvdz
Still doesn't make much sense as it seems the url does return what is expected, but the error indicates nothing is received.
I've proposed this update to the device_list_names_idxs function in dtg_domoticz.lua to avoid the error:

Code: Select all

function device_list_names_idxs(DeviceType)
  --returns a devcie idx based on its name
  local idx, k, record, decoded_response
  decoded_response = device_list(DeviceType)
  result = decoded_response['result']
  devices = {}
  devicesproperties = {}
  if result ~= nil then
    for i = 1, #result do
      record = result[i]
      if type(record) == "table" then
        if DeviceType == "plans" then
          devices[record['Name']] = record['idx']
          else
          devices[string.lower(record['Name'])] = record['idx']
          devices[record['idx']] = record['Name']
          if DeviceType == 'scenes' then
            devicesproperties[record['idx']] = {Type=record['Type'], SwitchType = record['Type']}
          end
        end
      end
    end
  end
  return devices, devicesproperties
end
You could change it for yourself, but I expect the menu to be pretty empty.
Jos

Re: dtgbot - Domoticz TeleGram BOT

Posted: Thursday 26 May 2016 12:05
by woody4165
The strange thing is that it was working until one week ago.
I probably have updated something (for sure the Domoticz bet to the last one) and some packages in Raspbian, but not in dgtbot.
I've tried reinstalling it, step by step, but nothing changes.

I will try this afternoon your update...
Thanks

Re: dtgbot - Domoticz TeleGram BOT

Posted: Thursday 26 May 2016 12:27
by jvdz
We can take this offline (in PM) and simply start step by step the debugging until we found the the reason, but you will have to make regular updates to the LUA scripts for this.

Jos

Re: dtgbot - Domoticz TeleGram BOT

Posted: Thursday 26 May 2016 12:41
by woody4165
ok, thanks for your availability. :)
I will do it most probably starting tomorrow.

Re: dtgbot - Domoticz TeleGram BOT

Posted: Thursday 26 May 2016 14:06
by woody4165
jvdz wrote:Still doesn't make much sense as it seems the url does return what is expected, but the error indicates nothing is received.
I've proposed this update to the device_list_names_idxs function in dtg_domoticz.lua to avoid the error:

...

You could change it for yourself, but I expect the menu to be pretty empty.
Jos
Hi Jos

I just tried the script update you propose and now it's working!!!!

Thanks!

What was the trick?

Re: dtgbot - Domoticz TeleGram BOT

Posted: Monday 04 July 2016 21:01
by leoncornelissen
Can you share the script update?
I have problems getting the DTGbot service up and running.

If I send "devices" I don't get any response or the services crashes

Re: dtgbot - Domoticz TeleGram BOT

Posted: Monday 04 July 2016 21:12
by woody4165
Just go to post 168 of this 3d, it should be less than five post before your.

Re: dtgbot - Domoticz TeleGram BOT

Posted: Monday 04 July 2016 21:16
by jvdz
The update to the original script is posted a few posts up, but in case you want to debug the setup, then simply change the Domoticz variable TelegramBotLoglevel to 2, restart the service and check both dtb.log and dtb.log.errors for any errors.

Jos

Re: dtgbot - Domoticz TeleGram BOT

Posted: Thursday 04 August 2016 19:15
by cris77
Hi everybody,
After a lot of reading, and trail and error I managed to get the control by telegram working.
Great work!!! very nice function.
However I have one question (I'm not a programmer at all).
I would like to send a http post command ( for wife acceptence) to my bot with a switch command to open my gates. Now it works with "On xxxxx" but ultimatly i would like to create a shortcut on the telephone to do this. I would appreciate if someone could help me. I have looked around but can't find a solution
Thanks

Re: dtgbot - Domoticz TeleGram BOT

Posted: Monday 08 August 2016 23:35
by hannibal2206
Hi,

I believe I have followed all installation instructions, however I cannot send any commands to the bot.

The service is running :

pi@raspberrypi3:~/dtgbot$ sudo service dtgbot status
â dtgbot.service - LSB: A Telegram bot designed to control Domoticz
Loaded: loaded (/etc/init.d/dtgbot)
Active: active (exited) since Mon 2016-08-08 23:30:20 CEST; 5min ago
Process: 14193 ExecStop=/etc/init.d/dtgbot stop (code=exited, status=0/SUCCESS)
Process: 15121 ExecStart=/etc/init.d/dtgbot start (code=exited, status=0/SUCCESS)

Aug 08 23:30:20 raspberrypi3 dtgbot[15121]: Starting Telegram Bot for Domoticz ... Done.
Aug 08 23:30:20 raspberrypi3 systemd[1]: Started LSB: A Telegram bot designed to control Domoticz.

Output of dtb.log :

pi@raspberrypi3:~$ tail -f /var/tmp/dtb.log
2016-08-08 23:30:21 - Decoded xxxxxx
2016-08-08 23:30:21 - WLString: xxxxxx
2016-08-08 23:30:21 - Decoded 0
2016-08-08 23:30:21 - dtgbotLogLevel set to: 0
2016-08-08 23:30:21 - WLidx 11
2016-08-08 23:30:21 - Decoded xxxxxx
2016-08-08 23:30:21 - WLString: xxxxxx
2016-08-08 23:30:21 - Getting TelegramBotOffset the previous Telegram bot message offset from Domoticz
2016-08-08 23:30:21 - Decoded 783075188

The output of dtb.log.errors :

pi@raspberrypi3:~$ tail -f /var/tmp/dtb.log.errors
/usr/bin/lua5.2: /home/pi/dtgbot/dtgbot.lua:549: attempt to index global 'msg' (a nil value)
stack traceback:
/home/pi/dtgbot/dtgbot.lua:549: in main chunk
[C]: in ?
tail: /var/tmp/dtb.log.errors: file truncated
/usr/bin/lua5.2: /home/pi/dtgbot/dtgbot.lua:549: attempt to index global 'msg' (a nil value)
stack traceback:
/home/pi/dtgbot/dtgbot.lua:549: in main chunk
[C]: in ?

Any ideas ?

Re: dtgbot - Domoticz TeleGram BOT

Posted: Tuesday 09 August 2016 16:42
by simonrg
cris77 wrote:I would like to send a http post command ( for wife acceptence) to my bot with a switch command to open my gates. Now it works with "On xxxxx" but ultimatly i would like to create a shortcut on the telephone to do this. I would appreciate if someone could help me. I have looked around but can't find a solution
Thanks
Sadly, I think you are right, I don't think it is possible to send a message as an http post command.

This is effectively a Telegram question and would not require any modification to allow dtgbot to do what you want to, if Telegram allowed it. It doesn't due to the security issues it would raise.

The bot sends a message effectively via an http post - so dtgbot sends an http post command to the Telegram api, which results in a message popping up in your Telegram client, but you can't send a http post command to the bot this way.

My only thought was whether you could have a bot that could send a message to another bot, but I don't think this is possible.

So rather than an http post command, you would need to code a Telegram client, which would be a single button on a phone.

jvdz is working on inline menus which while running in a Telegram client do present simple buttons to push.

Re: dtgbot - Domoticz TeleGram BOT

Posted: Tuesday 09 August 2016 16:59
by simonrg
hannibal2206 wrote:.......
The output of dtb.log.errors :

pi@raspberrypi3:~$ tail -f /var/tmp/dtb.log.errors
/usr/bin/lua5.2: /home/pi/dtgbot/dtgbot.lua:549: attempt to index global 'msg' (a nil value)
stack traceback:
/home/pi/dtgbot/dtgbot.lua:549: in main chunk
[C]: in ?
tail: /var/tmp/dtb.log.errors: file truncated
/usr/bin/lua5.2: /home/pi/dtgbot/dtgbot.lua:549: attempt to index global 'msg' (a nil value)
stack traceback:
/home/pi/dtgbot/dtgbot.lua:549: in main chunk
[C]: in ?

Any ideas ?
Only ideas -
You could have a command that is causing a problem, so try increase the bot offset - http://www.domoticz.com/wiki/Remote_Con ... use_Errors

Re: dtgbot - Domoticz TeleGram BOT

Posted: Tuesday 09 August 2016 21:56
by hannibal2206
a bit further ..

Using the service won't work, but running interactively "lua dtgbot.lua" things start to work !

Need to find what the difference is ..