Page 7 of 30

Re: dtgbot - Domoticz TeleGram BOT

Posted: Tuesday 20 October 2015 18:44
by jvdz
There clearly is an issue with the index of the room it is trying to retrieve the devices for. The idx field should be a number in stead of a name.
Could you post (or PM) the result of the json : http://192.168.1.XXX:8080/json.htm?type ... &used=true
Is "Planta Baja" a name of a room?

Jos

Re: dtgbot - Domoticz TeleGram BOT

Posted: Tuesday 20 October 2015 19:44
by satanasinc
jvdz wrote:There clearly is an issue with the index of the room it is trying to retrieve the devices for. The idx field should be a number in stead of a name.
Could you post (or PM) the result of the json : http://192.168.1.XXX:8080/json.htm?type ... &used=true
Is "Planta Baja" a name of a room?

Jos
Hi!

Thank you jvdz! PM send.

"Planta Baja" is a floor name not a room. It means low level in spanish.

I'm really very grateful jvdz.
Editing...

After jvdz help i got a new error in the dtb.log....
Spoiler: show
2015-10-20 20:37:41 - #### End populating menuarray
2015-10-20 20:37:41 - TelegramBotWhiteListedIDs user variable does not exist in Domoticz
2015-10-20 20:37:41 - So will allow any id to use the bot
2015-10-20 20:37:41 - JSON request <http://192.168.1.XXX:8080/json.htm?type ... ble&idx=11>
2015-10-20 20:37:41 - Decoded 1
2015-10-20 20:37:41 - dtgbotLogLevel set to: 1
2015-10-20 20:37:41 - TelegramBotWhiteListedIDs user variable does not exist in Domoticz
2015-10-20 20:37:41 - So will allow any id to use the bot
2015-10-20 20:37:41 - Getting 1 the previous Telegram bot message offset from Domoticz
2015-10-20 20:37:41 - 1 user variable does not exist in Domoticz so can not continue
---Edit--

Solved

Guys it may sound obvious, but do not use spaces in domoticz objects names.

Thnx to jvdz for the help. You are Jedi Master :lol:

Greetings from spain.

Re: dtgbot - Domoticz TeleGram BOT

Posted: Monday 16 November 2015 17:43
by fhwessels
Hi I just don't have any luck getting dtgbot stating. I dont use any password on Domoticz.

This is the error I am getting:

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 ?
Here is the details from Domoticz:

Code: Select all

{
result: [
{
LastUpdate: "2015-11-16 16:33:29",
Name: "TelegramBotOffset",
Type: "0",
Value: "1",
idx: "1"
},
{
LastUpdate: "2015-11-16 16:33:58",
Name: "TelegramBotMenu",
Type: "2",
Value: "Off",
idx: "2"
},
{
LastUpdate: "2015-11-16 16:34:34",
Name: "TelegramBotWhiteListedIDs",
Type: "2",
Value: "xxxxxxx",
idx: "3"
}
],
status: "OK",
title: "GetUserVariables"

Code: Select all

{
result: [
{
Devices: 16,
Name: "Main",
Order: "1",
idx: "2"
},
{
Devices: 4,
Name: "Study",
Order: "3",
idx: "3"
}
],
status: "OK",
title: "Plans"
}

Re: dtgbot - Domoticz TeleGram BOT

Posted: Monday 16 November 2015 18:07
by jvdz
You probably do not have any Scenes defined yet in Domoticz and the Function is "complaining" about that.
Please edit your dtg_domoticz.lua and update the below function with this version which should skip in case no Scenes are available:

Code: Select all

-- returns a list of Domoticz items based on type i.e. devices or scenes
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
Thanks
Jos

Re: dtgbot - Domoticz TeleGram BOT

Posted: Monday 16 November 2015 18:23
by fhwessels
Thanks jvdz once I create my scenes dtgbot started.

Re: dtgbot - Domoticz TeleGram BOT

Posted: Tuesday 17 November 2015 17:05
by fhwessels
I now have the bot up and running. When I type a command like "help" in from the telegram I don't get a response back from the bot. Why will that be?

Code: Select all

6 - Starting Telegram api Bot message handler
2015-11-17 17:47:46 - -----------------------------------------
2015-11-17 17:47:47 - Domoticz returned getuservariables after 2 attempts
2015-11-17 17:47:47 -  dtgbotLogLevel set to: 0
2015-11-17 17:47:47 - Loading command modules...
2015-11-17 17:47:47 - Loading module <utility>
2015-11-17 17:47:48 - found command <refresh>
2015-11-17 17:47:48 - Loading module <dtgmenu>
2015-11-17 17:47:48 - define LastCommand
2015-11-17 17:47:48 - found command <dtgmenu>
2015-11-17 17:47:48 - Loading module <list>
2015-11-17 17:47:48 - found command <list>
2015-11-17 17:47:48 - found command <dump>
2015-11-17 17:47:48 - Loading module <devices>
2015-11-17 17:47:48 - found command <devices>
2015-11-17 17:47:48 - found command <scenes>
2015-11-17 17:47:48 - Loading module <flick>
2015-11-17 17:47:48 - found command <flick>
2015-11-17 17:47:48 - Loading module <nflick>
2015-11-17 17:47:48 - found command <nflick>
2015-11-17 17:47:48 - Loading module <on>
2015-11-17 17:47:48 - found command <off>
2015-11-17 17:47:48 - found command <on>
2015-11-17 17:47:48 - Loading module <battery>
2015-11-17 17:47:48 - found command <batteries>
2015-11-17 17:47:48 - found command <battery>
2015-11-17 17:47:48 - Loading module <help>
2015-11-17 17:47:48 - found command <start>
2015-11-17 17:47:48 - found command <help>
2015-11-17 17:47:48 - Loading module <temperature>
2015-11-17 17:47:48 - found command <temperatures>
2015-11-17 17:47:48 - found command <tempall>
2015-11-17 17:47:48 - found command <temperature>
2015-11-17 17:47:48 - Decoded Off
2015-11-17 17:47:48 - TelegramBotWhiteListedIDs user variable does not exist in Domoticz
2015-11-17 17:47:48 - So will allow any id to use the bot
2015-11-17 17:47:48 -  dtgbotLogLevel set to: 0
2015-11-17 17:47:48 - TelegramBotWhiteListedIDs user variable does not exist in Domoticz
2015-11-17 17:47:48 - So will allow any id to use the bot
2015-11-17 17:47:48 - Getting TelegramBotOffset the previous Telegram bot message offset from Domo                      ticz
2015-11-17 17:47:48 - Decoded 1

Re: dtgbot - Domoticz TeleGram BOT

Posted: Tuesday 17 November 2015 18:15
by simonrg
fhwessels wrote:I now have the bot up and running. When I type a command like "help" in from the telegram I don't get a response back from the bot. Why will that be?
Try a slash infront of help - /help - should then get a response.
Check out the Telegram generic pages, they document things like this behaviour.

Re: dtgbot - Domoticz TeleGram BOT

Posted: Tuesday 17 November 2015 19:58
by fhwessels
hi I did try the /help as well and still don't get the response. Here is the info from the getUpdate log

Code: Select all

{
update_id: 121932669,
message: {
message_id: 201,
from: {
id: xxxxxxx,
first_name: "Francois",
last_name: "Wessels",
username: "fwessels"
},
chat: {
id: xxxxxx,
first_name: "Francois",
last_name: "Wessels",
username: "fwessels",
type: "private"
},
date: 1447786998,
text: "/help"
}
}
]

Re: dtgbot - Domoticz TeleGram BOT

Posted: Tuesday 17 November 2015 20:13
by jvdz
Can you show me the dtb.log with the details about processing this message?

Jos

Re: dtgbot - Domoticz TeleGram BOT

Posted: Wednesday 18 November 2015 15:23
by fhwessels
hi here is my dtb.log. where will I get the process message?

Code: Select all

2015-11-18 15:17:09 - DomoticzIP: 127.0.0.1
2015-11-18 15:17:09 - DomoticzPort: 8080
2015-11-18 15:17:09 - BotHomePath: /home/pi/dtgbot/
2015-11-18 15:17:09 - BotLuaScriptPath: /home/pi/dtgbot/lua/
2015-11-18 15:17:09 - BotBashScriptPath: /home/pi/dtgbot/bash/
2015-11-18 15:17:09 - TelegramBotToken: xxxxxxxxxxxxxxxxxxxI
2015-11-18 15:17:09 - TelegramBotOffset: TelegramBotOffset
2015-11-18 15:17:09 - -----------------------------------------
2015-11-18 15:17:09 - Starting Telegram api Bot message handler
2015-11-18 15:17:09 - -----------------------------------------
2015-11-18 15:17:10 - Domoticz returned getuservariables after 2 attempts
2015-11-18 15:17:11 -  dtgbotLogLevel set to: 0
2015-11-18 15:17:11 - Loading command modules...
2015-11-18 15:17:11 - Loading module <utility>
2015-11-18 15:17:11 - found command <refresh>
2015-11-18 15:17:11 - Loading module <dtgmenu>
2015-11-18 15:17:11 - define LastCommand
2015-11-18 15:17:11 - found command <dtgmenu>
2015-11-18 15:17:11 - Loading module <list>
2015-11-18 15:17:11 - found command <dump>
2015-11-18 15:17:11 - found command <list>
2015-11-18 15:17:11 - Loading module <devices>
2015-11-18 15:17:11 - found command <devices>
2015-11-18 15:17:11 - found command <scenes>
2015-11-18 15:17:11 - Loading module <flick>
2015-11-18 15:17:11 - found command <flick>
2015-11-18 15:17:11 - Loading module <nflick>
2015-11-18 15:17:11 - found command <nflick>
2015-11-18 15:17:11 - Loading module <on>
2015-11-18 15:17:11 - found command <off>
2015-11-18 15:17:11 - found command <on>
2015-11-18 15:17:11 - Loading module <battery>
2015-11-18 15:17:11 - found command <batteries>
2015-11-18 15:17:11 - found command <battery>
2015-11-18 15:17:11 - Loading module <help>
2015-11-18 15:17:11 - found command <help>
2015-11-18 15:17:11 - found command <start>
2015-11-18 15:17:11 - Loading module <temperature>
2015-11-18 15:17:11 - found command <tempall>
2015-11-18 15:17:11 - found command <temperature>
2015-11-18 15:17:11 - found command <temperatures>
2015-11-18 15:17:11 - Decoded Off
2015-11-18 15:17:11 - TelegramBotWhiteListedIDs user variable does not exist in Domoticz
2015-11-18 15:17:11 - So will allow any id to use the bot
2015-11-18 15:17:11 -  dtgbotLogLevel set to: 0
2015-11-18 15:17:11 - TelegramBotWhiteListedIDs user variable does not exist in Domoticz
2015-11-18 15:17:11 - So will allow any id to use the bot
2015-11-18 15:17:11 - Getting TelegramBotOffset the previous Telegram bot message offset from Domoticz
2015-11-18 15:17:11 - Decoded 1

Re: dtgbot - Domoticz TeleGram BOT

Posted: Wednesday 18 November 2015 16:31
by jvdz
When sending a text message to the BOT you defined, the dtgbot should start processing it and it will show up in the log.
I believe that the new BOTs are by default in private mode, which means only commands prefixed with a slash "/" will be send to the BOT.
https://core.telegram.org/bots look for /setprivacy

Have you followed the https://www.domoticz.com/wiki/Telegram_ ... ur_chat_id section in the WiKi?
Does that work?
Are there any errors listed in: dtb.log.errors?

You also haven't set the TelegramBotWhiteListedIDs yet, which you might want to do to ensure nobody else can send commands to your Domoticz setup.

Jos

Re: dtgbot - Domoticz TeleGram BOT

Posted: Wednesday 18 November 2015 16:58
by fhwessels
I done all of this in the wiki here is my info from the chat ID. I can also send message with curl command to the bod and that is working. There is no error dtb.log.error

Code: Select all

{
update_id: 121932675,
message: {
message_id: 215,
from: {
id: xxxxx,
first_name: "Francois",
last_name: "Wessels",
username: "fwessels"
},
chat: {
id: xxxxxxxx,
first_name: "Francois",
last_name: "Wessels",
username: "fwessels",
type: "private"
},
date: 1447856628,
text: "/help"
}
},
{
update_id: 121932676,
message: {
message_id: 216,
from: {
id: xxxxxxxx,
first_name: "Francois",
last_name: "Wessels",
username: "fwessels"
},
chat: {
id: xxxxxxxx,
first_name: "Francois",
last_name: "Wessels",
username: "fwessels",
type: "private"
},
date: 1447856670,
text: "/list"
}
},
{
update_id: 121932677,
message: {
message_id: 217,
from: {
id: xxxxxxxx,
first_name: "Francois",
last_name: "Wessels",
username: "fwessels"
},
chat: {
id: xxxxxxxx,
first_name: "Francois",
last_name: "Wessels",
username: "fwessels",
type: "private"
},
date: 1447856732,
text: "/dump"
}
}
]

Re: dtgbot - Domoticz TeleGram BOT

Posted: Wednesday 18 November 2015 17:26
by jvdz
DTGBOT.lua should be doing the same as what you have done manually.
Can you set the Domoticz uservariable TelegramBotLoglevel to 2, restart DTGBOT, send a command to the bot and show or send me the log (after removing any private info) ?
It should contain a lot more information about what it is doing exactly at startup.

Jos

Re: dtgbot - Domoticz TeleGram BOT

Posted: Wednesday 18 November 2015 17:37
by fhwessels
here is my log.

Code: Select all

2015-11-18 18:33:03 - -----------------------------------------
2015-11-18 18:33:03 - Starting Telegram api Bot message handler
2015-11-18 18:33:03 - -----------------------------------------
2015-11-18 18:33:03 - Domoticz returned getuservariables after 1 attempts
2015-11-18 18:33:03 - Decoded 2
2015-11-18 18:33:03 -  dtgbotLogLevel set to: 2
2015-11-18 18:33:03 - Loading command modules...
2015-11-18 18:33:03 - Loading module <utility>
2015-11-18 18:33:03 - found command <refresh>
2015-11-18 18:33:03 - function: 0x1f07d60
2015-11-18 18:33:03 - Loading module <dtgmenu>
2015-11-18 18:33:03 - define LastCommand
2015-11-18 18:33:03 - found command <dtgmenu>
2015-11-18 18:33:03 - function: 0x1ef0718
2015-11-18 18:33:03 - Loading module <list>
2015-11-18 18:33:03 - found command <list>
2015-11-18 18:33:03 - function: 0x1f4fe88
2015-11-18 18:33:03 - found command <dump>
2015-11-18 18:33:03 - function: 0x1f4fe88
2015-11-18 18:33:03 - Loading module <devices>
2015-11-18 18:33:03 - found command <devices>
2015-11-18 18:33:03 - function: 0x1f34ae8
2015-11-18 18:33:03 - found command <scenes>
2015-11-18 18:33:03 - function: 0x1f34ae8
2015-11-18 18:33:03 - Loading module <flick>
2015-11-18 18:33:03 - found command <flick>
2015-11-18 18:33:03 - function: 0x1f4f650
2015-11-18 18:33:03 - Loading module <nflick>
2015-11-18 18:33:03 - found command <nflick>
2015-11-18 18:33:03 - function: 0x1f50990
2015-11-18 18:33:03 - Loading module <on>
2015-11-18 18:33:03 - found command <on>
2015-11-18 18:33:03 - function: 0x1f345b8
2015-11-18 18:33:03 - found command <off>
2015-11-18 18:33:03 - function: 0x1f345b8
2015-11-18 18:33:03 - Loading module <battery>
2015-11-18 18:33:03 - found command <battery>
2015-11-18 18:33:03 - function: 0x1ef2018
2015-11-18 18:33:03 - found command <batteries>
2015-11-18 18:33:03 - function: 0x1ef2018
2015-11-18 18:33:03 - Loading module <help>
2015-11-18 18:33:03 - found command <help>
2015-11-18 18:33:03 - function: 0x1f46b68
2015-11-18 18:33:03 - found command <start>
2015-11-18 18:33:03 - function: 0x1f46b68
2015-11-18 18:33:03 - Loading module <temperature>
2015-11-18 18:33:03 - found command <tempall>
2015-11-18 18:33:03 - function: 0x1f48960
2015-11-18 18:33:03 - found command <temperature>
2015-11-18 18:33:03 - function: 0x1f48960
2015-11-18 18:33:03 - found command <temperatures>
2015-11-18 18:33:03 - function: 0x1f48960
2015-11-18 18:33:03 - JSON request <http://127.0.0.1:8080/json.htm?type=command&param=getuservariable                        &idx=2>
2015-11-18 18:33:03 - Decoded Off
2015-11-18 18:33:03 - WLidx 3
2015-11-18 18:33:03 - JSON request <http://127.0.0.1:8080/json.htm?type=command&param=getuservariable                        &idx=3>
2015-11-18 18:33:03 - Decoded 54005199
2015-11-18 18:33:03 - WLString: 54005199
2015-11-18 18:33:03 - Name :54005199
2015-11-18 18:33:03 - JSON request <http://127.0.0.1:8080/json.htm?type=command&param=getuservariable                        &idx=4>
2015-11-18 18:33:03 - Decoded 2
2015-11-18 18:33:03 -  dtgbotLogLevel set to: 2
2015-11-18 18:33:03 - WLidx 3
2015-11-18 18:33:03 - JSON request <http://127.0.0.1:8080/json.htm?type=command&param=getuservariable                        &idx=3>
2015-11-18 18:33:03 - Decoded XXXXXX
2015-11-18 18:33:03 - WLString:  XXXXXX
2015-11-18 18:33:03 - Name : XXXXXX
2015-11-18 18:33:03 - Getting TelegramBotOffset the previous Telegram bot message offset from Domotic                        z
2015-11-18 18:33:03 - TBOidx 1
2015-11-18 18:33:03 - JSON request <http://127.0.0.1:8080/json.htm?type=command&param=getuservariable                        &idx=1>
2015-11-18 18:33:03 - Decoded 1
2015-11-18 18:33:03 - TBO 1
2015-11-18 18:33:03 - https://api.telegram.org/botbotXXXXXXXXX/ WHY is there 2 botbot here is it right?
pi@raspberrypi ~ $

Re: dtgbot - Domoticz TeleGram BOT

Posted: Wednesday 18 November 2015 17:54
by jvdz
WHY is there 2 botbot here is it right?
Did you add the bot prefix in this line in /etc/profile.d/DomoticzData.sh?

Code: Select all

export TelegramBotToken="000000000:keykeykeykeykeykeykeykey"
Jos

Re: dtgbot - Domoticz TeleGram BOT

Posted: Wednesday 18 November 2015 18:17
by fhwessels
yes it did when I copy it. I removed it and now it is woking. Thanks for you help :D

Re: dtgbot - Domoticz TeleGram BOT

Posted: Wednesday 18 November 2015 18:20
by jvdz
Great to hear. 8-)
Don't forget to change the debuglevel back to 0 or else the logfile will grow pretty fast.

Enjoy
Jos

Re: dtgbot - Domoticz TeleGram BOT

Posted: Wednesday 18 November 2015 18:21
by fhwessels
will do

Re: dtgbot - Domoticz TeleGram BOT

Posted: Sunday 17 January 2016 22:34
by juankar
Hello
I wonder if with Telegram Remote Control is posible to get the status of devices. I just get a list of devices and I can on/off them, but I dont know if they are on or off!!!.
I mean with Remote Control, no with the new "bots system".
The info about bots I've found is not clear, and it looks like the remote control is easier for me.

Thanks

Re: dtgbot - Domoticz TeleGram BOT

Posted: Wednesday 20 April 2016 9:35
by MacJL
Hello,

I've made a Dokerfile to easily build and run Telegram BOT on my Raspberry.

To build and run it
1 -Install docker
Depend of your Linux ARM distribution. For example, with Raspbian Jessie, you can fin a '.deb' file here, with last versions of docker : http://blog.hypriot.com/downloads/

2 - Build the container image

Code: Select all

docker build -t telegrambot git://github.com/macjl/dtgbot-docker
3 - Run the container with your Telegram parameters :

Code: Select all

docker run -dt --restart=always --name telegrambot --env DomoticzIP=192.168.0.30 --env DomoticzPort=8080 --env TelegramBotToken="123456:ABCDEFG" --env TelegramChatId="987654321" telegrambot
4 - Verify the logs to see if everything is OK

Code: Select all

docker logs telegrambot
Please tell me if you like it!