dtgbot - Domoticz TeleGram BOT
Moderator: leecollings
-
- Posts: 29
- Joined: Wednesday 18 June 2014 23:57
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Netherlands
- Contact:
Re: dtgbot - Domoticz TeleGram BOT
The TelegramBotOffset. I changed the current value +1 as it says in the wiki. That worked for me.
Another thing, that (i think) is very nice. I implemented the custom keyboard to respons to telegram. I'm a rookie in scripting and get everything off the internet. I now place an extra line for the custom keyboard at the end of every bash script I make. Maybe it can be done in lua, so you get standaard a coupe of buttons to push. You don't need to type anymore. Just hit the button. I'll post a screenshot later on.
Another thing, that (i think) is very nice. I implemented the custom keyboard to respons to telegram. I'm a rookie in scripting and get everything off the internet. I now place an extra line for the custom keyboard at the end of every bash script I make. Maybe it can be done in lua, so you get standaard a coupe of buttons to push. You don't need to type anymore. Just hit the button. I'll post a screenshot later on.
-
- Posts: 329
- Joined: Tuesday 16 July 2013 22:54
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 3.8807
- Location: North East England
- Contact:
Re: dtgbot - Domoticz TeleGram BOT
Strange the error you were showing was due to Domoticz replying "not authorized" so by adding one to the offset you have skipped the command that caused the problem, but if do the same command again you should see the same error.Slayer007 wrote:The TelegramBotOffset. I changed the current value +1 as it says in the wiki. That worked for me.
Another thing, that (i think) is very nice. I implemented the custom keyboard to respons to telegram. I'm a rookie in scripting and get everything off the internet. I now place an extra line for the custom keyboard at the end of every bash script I make. Maybe it can be done in lua, so you get standaard a coupe of buttons to push. You don't need to type anymore. Just hit the button. I'll post a screenshot later on.
Jvdz (and I) is (are) In the process of implementing custom keyboards in dtgbot, it is in the menus branch of dtgbot on github, but not yet ready for mass consumption, as you say very neat, just trying to automate it and make it possible for others to use. Hope to have it on the wiki soon, why don't you document your approach on the wiki too, (if you haven't already).
Raspberry Pi 2 B - 2A@5V PSU - Raspbian + Domoticz + RFXtrx(89), LightwaveRF House(dimmers, sockets, wireless/mood switches), Owl CM113, 4 LaCross Temp / Humidity Sensors, 4 Siemens PIR, Smappee, Solaredge, ESP8266
-
- Posts: 29
- Joined: Wednesday 18 June 2014 23:57
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Netherlands
- Contact:
Re: dtgbot - Domoticz TeleGram BOT
Here a little example from my custom keyboard. This is a code in bash I put at the end of every bash script. The "id=" extract the username who asked for a command. So it says: How can I help you, user?
In the screenshot you see how it looks like.
Code: Select all
id=`curl --data 'chat_id='$SendMsgTo --data-urlencode 'text='"$ResultString" 'https://api.telegram.org/bot'$TelegramBotToken'/sendMessage'| grep -Po ',"chat":{"id":.*,"first_name":"\K.*?(?=")'`
sleep 1
curl --data 'chat_id='$SendMsgTo --data-urlencode 'reply_markup= {"keyboard":[["Coffee "],["Meterstanden"],[" Lights On "]]}' --data-urlencode 'text='"How can I help you, user_name"? 'https://api.telegram.org/bot'$TelegramBotToken'/sendMessage'
- Attachments
-
- IMG_4111.PNG (176.22 KiB) Viewed 7638 times
- 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
Let me share a "teaser" on what Simon and I have been working on in the last couple of weeks.
Please remember that this is still work in progress as we are also trying to make this as dynamic as possible to fit everybody's needs without too much manual config effort.
Base approach we have taken at this moment for dtgmenu's logic:
Jos
Please remember that this is still work in progress as we are also trying to make this as dynamic as possible to fit everybody's needs without too much manual config effort.
Base approach we have taken at this moment for dtgmenu's logic:
- Read all Rooms from domoticz and make that the level 1 menu. (image 1)
- Read all devices/scenes in the room and show them as buttons with their current status (image 2)
- When you select a device, a 3rd level menu is shown at the top which gives you the pre-defined actions for the device type (image 2 middle/right)
- Currently supports "Lighting 2" => Switch (On/Off) and Dimmers (On/Off and pre-defines levels) but also ? for a manual option to specify the level.
- Also the option to just show the weather/ temperature info on a menu with buttons.(image 3)
- Static options: This will allow for any bash/lua commands to start them via the menu with also the option to prompt for a parameter before running that command.
- It does also have language support so the below Dutch standard replies will be available in any language we define and we plan to use the Domoticz settings as the language to use.
Jos
Last edited by jvdz on Monday 24 August 2015 19:59, edited 1 time in total.
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
- G3rard
- Posts: 669
- Joined: Wednesday 04 March 2015 22:15
- Target OS: -
- Domoticz version: No
- Location: The Netherlands
- Contact:
Re: dtgbot - Domoticz TeleGram BOT
That looks great! I hope this can be shared soon.
Not using Domoticz anymore
-
- Posts: 29
- Joined: Wednesday 18 June 2014 23:57
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Netherlands
- Contact:
Re: dtgbot - Domoticz TeleGram BOT
Looks really great. Can't wait to implement this. Keep up the good work!
Can anyone help me. I have a little bit problems with the command. I have multiple bash-scripts, for example:
meter.sh
system.sh
morning.sh
room.sh
living_room.sh
When I send a textmessage to my bot, for example "m", it executes all scripts.
When I send a message "ro", then it execute's morning.sh and room.sh. And when I send "em" it executes meter/system.sh.
The same with "room". Sending a message "room" will execute both scripts with room in it.
Is there anyway to send a message wich only executes the exact match? Or can I make my own commands? For example: When I send a message "Sunny", it will execute system.sh?
I'm trying to understand the script, but I can't really see what I have to adapt?
(and can you please send an example of your lua-script that handles the custom keyboard, so I already can play with it?)
Can anyone help me. I have a little bit problems with the command. I have multiple bash-scripts, for example:
meter.sh
system.sh
morning.sh
room.sh
living_room.sh
When I send a textmessage to my bot, for example "m", it executes all scripts.
When I send a message "ro", then it execute's morning.sh and room.sh. And when I send "em" it executes meter/system.sh.
The same with "room". Sending a message "room" will execute both scripts with room in it.
Is there anyway to send a message wich only executes the exact match? Or can I make my own commands? For example: When I send a message "Sunny", it will execute system.sh?
I'm trying to understand the script, but I can't really see what I have to adapt?
(and can you please send an example of your lua-script that handles the custom keyboard, so I already can play with it?)
-
- Posts: 329
- Joined: Tuesday 16 July 2013 22:54
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 3.8807
- Location: North East England
- Contact:
Re: dtgbot - Domoticz TeleGram BOT
Messages should only be executing with exact match ignoring case, it looks like you might have something funny with the prefix character, have you set it for your bot on Telegram?Slayer007 wrote:When I send a textmessage to my bot, for example "m", it executes all scripts.
When I send a message "ro", then it execute's morning.sh and room.sh. And when I send "em" it executes meter/system.sh.
The same with "room". Sending a message "room" will execute both scripts with room in it.
Is there anyway to send a message wich only executes the exact match? Or can I make my own commands? For example: When I send a message "Sunny", it will execute system.sh?
I'm trying to understand the script, but I can't really see what I have to adapt?
(and can you please send an example of your lua-script that handles the custom keyboard, so I already can play with it?)
Below is an example function from @jvdz of a Lua function which uses a custom keyboard within Lua, using curl to do the https communications.
The function will send a message to one or both of the people based on names with the given user codes.
Code: Select all
— Send Telegram Bot message
— sendid can be a send2userx name or their id and also be send2both to send to both telegram accounts
— the function will also minimise the Keyboard to just the Menu button
function TelegramMsg(sendto,message)
token = "yourbottoken"
usercode1 = 12343567
usercode2 = 12345678
send2both = "both"
send2user1 = "Henk"
send2user2 = "Greta"
reply_markup = '--data-urlencode \"reply_markup={\\\"keyboard\\\":[[\\\"menu\\\"]],\\\"resize_keyboard\\\":true}\"'
if (sendto == 'Both' or sendto == send2user1 or sendto == usercode1) then
os.execute('curl —data chat_id='..usercode1.. ' —data-urlencode "text='..message..'" '..reply_markup..' "https://api.telegram.org/bot'..token..'/sendMessage" ')
end
if (sendto == 'Both' or sendto == send2user2 or sendto == usercode2) then
os.execute('curl —data chat_id='..usercode2..' —data-urlencode "text='..message..'" '..reply_markup..' "https://api.telegram.org/bot'..token..'/sendMessage" ')
end
end
Raspberry Pi 2 B - 2A@5V PSU - Raspbian + Domoticz + RFXtrx(89), LightwaveRF House(dimmers, sockets, wireless/mood switches), Owl CM113, 4 LaCross Temp / Humidity Sensors, 4 Siemens PIR, Smappee, Solaredge, ESP8266
- 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
This is an updated version which will only send the reply_markup when the dtgmenu is enabled.
Cheers
Jos
Cheers
Jos
Code: Select all
-- Send Telegram Bot message
-- sendid can be a send2userx name or their id and also be send2both to send to both telegram accounts
-- the function will also minimise the Keyboard to just the Menu button
function TelegramMsg(sendto,message)
token = "yourbottoken"
usercode1 = 12343567
usercode2 = 12345678
send2both = "both"
send2user1 = "Henk"
send2user2 = "Greta"
reply_markup = ""
--
-- Check whether the dtgmenu is switched on and only then send the reply_markup
if uservariables['TelegramBotMenu'] == "On" then
reply_markup = '--data-urlencode \"reply_markup={\\\"keyboard\\\":[[\\\"menu\\\"]],\\\"resize_keyboard\\\":true}\"'
end
-- check and send to user1
if (sendto == send2both or sendto == send2user1 or sendto == usercode1) then
os.execute('curl —data chat_id='..usercode1.. ' —data-urlencode "text='..message..'" '..reply_markup..' "https://api.telegram.org/bot'..token..'/sendMessage" ')
end
-- check and send to user2
if (sendto == send2both or sendto == send2user2 or sendto == usercode2) then
os.execute('curl —data chat_id='..usercode2..' —data-urlencode "text='..message..'" '..reply_markup..' "https://api.telegram.org/bot'..token..'/sendMessage" ')
end
end
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
Re: dtgbot - Domoticz TeleGram BOT
Hi,
I've installed the bot according to the latest wiki. However I am getting the following error when starting the service:
Edit: Fixed by manually compiling and installing luasocket, luasec, luajson so they are 64-bit compatible. Now however, I get this error, for which i have no idea what to do Seems to me like a bug in lua-json...
I've installed the bot according to the latest wiki. However I am getting the following error when starting the service:
Code: Select all
domoticz@domoticz:/var/tmp$ cat dtb.log.errors
/usr/bin/lua5.2: error loading module 'socket.core' from file '/usr/local/lib/lua/5.2/socket/core.so':
/usr/local/lib/lua/5.2/socket/core.so: [b]wrong ELF class: ELFCLASS32[/b]
stack traceback:
[C]: in ?
[C]: in function 'require'
/usr/local/share/lua/5.2/socket.lua:12: in main chunk
[C]: in function 'require'
/usr/local/share/lua/5.2/socket/http.lua:10: in main chunk
[C]: in function 'require'
/home/domoticz/dtgbot/dtgbot.lua:92: in main chunk
[C]: in ?
Code: Select all
/usr/bin/lua5.2: /usr/local/share/lua/5.2/json/util.lua:55: bad argument #1 to 'pairs' (table expected, got string)
stack traceback:
[C]: in function 'pairs'
/usr/local/share/lua/5.2/json/util.lua:55: in function </usr/local/share/lua/5.2/json/util.lua:50>
(...tail calls...)
/usr/local/share/lua/5.2/json/decode.lua:108: in function </usr/local/share/lua/5.2/json/decode.lua:107>
(...tail calls...)
/usr/local/share/lua/5.2/json/decode.lua:157: in function </usr/local/share/lua/5.2/json/decode.lua:156>
(...tail calls...)
/home/domoticz/dtgbot//dtg_domoticz.lua:40: in function 'variable_list'
/home/domoticz/dtgbot//dtg_domoticz.lua:47: in function 'variable_list_names_idxs'
/home/domoticz/dtgbot/dtgbot.lua:172: in function 'dtgbot_initialise'
/home/domoticz/dtgbot/dtgbot.lua:229: in main chunk
[C]: in ?
-
- Posts: 19
- Joined: Sunday 13 September 2015 20:24
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: dtgbot - Domoticz TeleGram BOT
Hi,
how can i control Domoticz from an url? When i send a message through https://api.telegram.org/bot11111111:BB ... 78&text=0N 2
Domoticz doesnt respond, it looks like dtgbot doesnt listen to the messages that are sent throug the bots account instead of my own.
how can i control Domoticz from an url? When i send a message through https://api.telegram.org/bot11111111:BB ... 78&text=0N 2
Domoticz doesnt respond, it looks like dtgbot doesnt listen to the messages that are sent throug the bots account instead of my own.
- 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
Won't you create an endless message loop when you send a message to the Bot account from the Bot Account as DTGBOT will reply with a success/failure message, and how would you know whether or not it was successful?
Jos
Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
-
- Posts: 19
- Joined: Sunday 13 September 2015 20:24
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: dtgbot - Domoticz TeleGram BOT
Is it possible to send a message from a url/http request as the user instead of the bot?
-
- Posts: 329
- Joined: Tuesday 16 July 2013 22:54
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 3.8807
- Location: North East England
- Contact:
Re: dtgbot - Domoticz TeleGram BOT
I guess you would need to create another Bot and then send the message from there to common group chat.savage007 wrote:Hi,
how can i control Domoticz from an url? When i send a message through https://api.telegram.org/bot11111111:BB ... 78&text=0N 2
Domoticz doesnt respond, it looks like dtgbot doesnt listen to the messages that are sent throug the bots account instead of my own.
If you think about it there is no way for the bot to know whether Domoticz sent the bot message or another instance of the bot sent the message.
Raspberry Pi 2 B - 2A@5V PSU - Raspbian + Domoticz + RFXtrx(89), LightwaveRF House(dimmers, sockets, wireless/mood switches), Owl CM113, 4 LaCross Temp / Humidity Sensors, 4 Siemens PIR, Smappee, Solaredge, ESP8266
- 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
I am not sure what the exact underlying goal is of your question, but in general I would say JSON is the way to go for URL links to change devices in Domoticz.savage007 wrote:Is it possible to send a message from a url/http request as the user instead of the bot?
Sending an telegram message via an URL feels more like a workaround for something that is already available directly, but maybe you can share the scenario you are thinking of?
Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
-
- Posts: 108
- Joined: Sunday 23 February 2014 21:40
- Target OS: Raspberry Pi / ODroid
- Domoticz version: V3.5613
- Location: Netherlands
- Contact:
Re: dtgbot - Domoticz TeleGram BOT
I feel stupid, but I followed the complet wiki (at least I think I did), but it isn't working YET.
The log dtg.log shows
The log dtg.log.errors says:
My bet: my lua 5.2 is not complete? Is there some easy way to fix this?
Regards
The log dtg.log shows
Code: Select all
2015-09-28 23:34:21 - DomoticzIP: X.X.X.X
2015-09-28 23:34:21 - DomoticzPort: 8080
2015-09-28 23:34:21 - BotHomePath: /home/pi/dtgbot/
2015-09-28 23:34:21 - BotLuaScriptPath: /home/pi/dtgbot/lua/
2015-09-28 23:34:21 - BotBashScriptPath: /home/pi/dtgbot/bash/
2015-09-28 23:34:21 - TelegramBotToken: 11111111:KEYKEYKEYKEYKEYKEY
2015-09-28 23:34:21 - TelegramBotOffset: TelegramBotOffset
2015-09-28 23:34:21 - -----------------------------------------
2015-09-28 23:34:21 - Starting Telegram api Bot message handler
2015-09-28 23:34:21 - -----------------------------------------
Code: Select all
/usr/bin/lua5.2: /home/pi/dtgbot/dtgbot.lua:92: module 'socket.http' not found:
no field package.preload['socket.http']
no file '/usr/local/share/lua/5.2/socket/http.lua'
no file '/usr/local/share/lua/5.2/socket/http/init.lua'
no file '/usr/local/lib/lua/5.2/socket/http.lua'
no file '/usr/local/lib/lua/5.2/socket/http/init.lua'
no file './socket/http.lua'
no file '/usr/share/lua/5.2/socket/http.lua'
no file '/usr/share/lua/5.2/socket/http/init.lua'
no file './socket/http.lua'
no file '/usr/local/lib/lua/5.2/socket/http.so'
no file '/usr/lib/arm-linux-gnueabihf/lua/5.2/socket/http.so'
no file '/usr/lib/lua/5.2/socket/http.so'
no file '/usr/local/lib/lua/5.2/loadall.so'
no file './socket/http.so'
no file '/usr/local/lib/lua/5.2/socket.so'
no file '/usr/lib/arm-linux-gnueabihf/lua/5.2/socket.so'
no file '/usr/lib/lua/5.2/socket.so'
no file '/usr/local/lib/lua/5.2/loadall.so'
no file './socket.so'
stack traceback:
[C]: in function 'require'
/home/pi/dtgbot/dtgbot.lua:92: in main chunk
[C]: in ?
Regards
-
- Posts: 329
- Joined: Tuesday 16 July 2013 22:54
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 3.8807
- Location: North East England
- Contact:
Re: dtgbot - Domoticz TeleGram BOT
Installation is not plug and play and all of it has to work for any of it to work.mschut wrote:My bet: my lua 5.2 is not complete? Is there some easy way to fix this?
Looks like you haven't got the Lua libraries installed correctly, repeat this part of the wiki instructions, and that should fix it:
http://www.domoticz.com/wiki/Remote_Con ... _Libraries
Raspberry Pi 2 B - 2A@5V PSU - Raspbian + Domoticz + RFXtrx(89), LightwaveRF House(dimmers, sockets, wireless/mood switches), Owl CM113, 4 LaCross Temp / Humidity Sensors, 4 Siemens PIR, Smappee, Solaredge, ESP8266
-
- Posts: 108
- Joined: Sunday 23 February 2014 21:40
- Target OS: Raspberry Pi / ODroid
- Domoticz version: V3.5613
- Location: Netherlands
- Contact:
Re: dtgbot - Domoticz TeleGram BOT
Wow, thanks. So simple, now it's working like a charm!
-
- Posts: 41
- Joined: Monday 19 October 2015 12:15
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.9700
- Location: Spain
- Contact:
Re: dtgbot - Domoticz TeleGram BOT
Hi!
First of all. excuse my bad english.
After install Telegrambot i cant start the service.
I cant find where is the problem. Anybody can help me please?.
Here is my log file.
dtb.log.errors
Thanx and greeting from spain.
satanasinc
First of all. excuse my bad english.
After install Telegrambot i cant start the service.
I cant find where is the problem. Anybody can help me please?.
Here is my log file.
dtb.log.errors
- Spoiler: show
- Spoiler: show
Thanx and greeting from spain.
satanasinc
- 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
It seems there is an issue retrieving the Room information for the defined rooms in Domoticz.
How many rooms do you have defined?
Could you :
How many rooms do you have defined?
Could you :
- create the uservariable: TelegramBotLoglevel as Integer
- Set TelegramBotLoglevel to: 1
- Start dtgbot and post the logs again as that should now show more details.
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
-
- Posts: 41
- Joined: Monday 19 October 2015 12:15
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.9700
- Location: Spain
- Contact:
Re: dtgbot - Domoticz TeleGram BOT
Hi!jvdz wrote:It seems there is an issue retrieving the Room information for the defined rooms in Domoticz.
How many rooms do you have defined?
Could you :Jos
- create the uservariable: TelegramBotLoglevel as Integer
- Set TelegramBotLoglevel to: 1
- Start dtgbot and post the logs again as that should now show more details.
jvdz thanks for your help.
Two rooms configured in domoticz.
I added the variable to domoticz with these result...
dtb.log
- Spoiler: show
- Spoiler: show
Greetings from spain
Who is online
Users browsing this forum: No registered users and 1 guest