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
I've read that there's no security in the bot. So anyone that knows the name of my bot, can turn my lights on, for example.
I read in this forum that you can make a user variabele in domoticz. But i can't get it to work. I don't know exactly what to do. Can anyone help me or is there another security that can be implemented.
I don't want to use groups. Just two phones who can talk with the bot seperately.
At first i worked with one of the first telegrams, but somehow that didn't work anymore. This looks a lot more stable, with lost of possibilities. Thanks for the wiki Simon. Works perfect!
I read in this forum that you can make a user variabele in domoticz. But i can't get it to work. I don't know exactly what to do. Can anyone help me or is there another security that can be implemented.
I don't want to use groups. Just two phones who can talk with the bot seperately.
At first i worked with one of the first telegrams, but somehow that didn't work anymore. This looks a lot more stable, with lost of possibilities. Thanks for the wiki Simon. Works perfect!
-
- 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
There wasn't security in the bot, there is now.Slayer007 wrote:I've read that there's no security in the bot. So anyone that knows the name of my bot, can turn my lights on, for example.
I read in this forum that you can make a user variabele in domoticz. But i can't get it to work. I don't know exactly what to do. Can anyone help me or is there another security that can be implemented.
In dtgbot.cfg the name of the Domoticz variable is defined
Code: Select all
WLName = 'TelegramBotWhiteListedIDs'
Code: Select all
1234343423|0982384343
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
Yeah,
That's exactly what I did. I put in some dummy id's, to check wether I can still send messages. It's still working alttough my id wasn't in the list.
This is what I put in domoticz.
Am I forgetting something to do?
Edit: Forgot to restart the bot. Now it's working just fine
That's exactly what I did. I put in some dummy id's, to check wether I can still send messages. It's still working alttough my id wasn't in the list.
This is what I put in domoticz.
Am I forgetting something to do?
Edit: Forgot to restart the bot. Now it's working just fine
- Attachments
-
- domo.PNG (14.99 KiB) Viewed 4279 times
Last edited by Slayer007 on Wednesday 19 August 2015 19:09, edited 1 time in total.
-
- Posts: 51
- Joined: Tuesday 22 April 2014 22:17
- Target OS: OS X
- Domoticz version: Beta
- Location: France
- Contact:
Re: dtgbot - Domoticz TeleGram BOT
Hello,
I have this error when trying to obtain temperature :
I have this error when trying to obtain temperature :
Code: Select all
/usr/bin/lua5.2: /home/pi/dtgbot/lua//temperature.lua:31: attempt to concatenate global 'Humidity' (a nil value)
stack traceback:
/home/pi/dtgbot/lua//temperature.lua:31: in function 'temperature'
/home/pi/dtgbot/lua//temperature.lua:44: in function 'handler'
/home/pi/dtgbot/dtgbot.lua:293: in function 'HandleCommand'
/home/pi/dtgbot/dtgbot.lua:400: in function 'on_msg_receive'
/home/pi/dtgbot/dtgbot.lua:490: in main chunk
[C]: in ?
-
- Posts: 51
- Joined: Tuesday 22 April 2014 22:17
- Target OS: OS X
- Domoticz version: Beta
- Location: France
- Contact:
Re: dtgbot - Domoticz TeleGram BOT
And another one with specials caracters in Devices names :
Code: Select all
Succesfully handled incoming request
TelegramBotOffset 726956497
JSON request <http://127.0.0.1:8080/json.htm?type=command¶m=updateuservariable&idx=2&vname=TelegramBotOffset&vtype=integer&vvalue=726956497>
.{"ok":true,"result":[]}
.{"ok":true,"result":[]}
.{"ok":true,"result":[{"update_id":726956497,
"message":{"message_id":198,"from":{"id":xxxxxx,"first_name":"xxxxxxx","last_name":"xxxxxx","username":"xxxxxx"},"chat":{"id":xxxxxx,"first_name":"xxxxxx","last_name":"xxxxxx","username":"xxxxxx"},"date":1439995113,"text":"\/temperature \"V\u00e9randa\""}}]}
Message: 1
update_id 726956497
/temperature "Véranda"
No on WhiteList: 2
WhiteList: xxxxxx
WhiteList: xxxxxx
Handle command function started with /temperature "Véranda" and xxxxxx
JSON request <http://127.0.0.1:8080/json.htm?type=devices&order=name>
V randa does not exist
https://api.telegram.org/botxxxxxx:xxxxxx/sendMessage?timeout=60&chat_id=xxxxxx&reply_to_message_id=198&text=V+randa+does+not+exist
200
-
- Posts: 51
- Joined: Tuesday 22 April 2014 22:17
- Target OS: OS X
- Domoticz version: Beta
- Location: France
- Contact:
Re: dtgbot - Domoticz TeleGram BOT
I have created a simple script that add the chat ids to telegram TelegramBotWhiteListedIDs user variable.
The steps :
# Stop dtgbot
sudo service dtgbot stop
sleep 60
# Send a telegram message to the bot
# Execute the script
chmod +x authorize.bash
./authorize.bash
# Restart dtgbot
sudo service dtgbot start
If you want to add the script to the git repository and the wiki page, you can do it.
The content of authorize.bash
The steps :
# Stop dtgbot
sudo service dtgbot stop
sleep 60
# Send a telegram message to the bot
# Execute the script
chmod +x authorize.bash
./authorize.bash
# Restart dtgbot
sudo service dtgbot start
If you want to add the script to the git repository and the wiki page, you can do it.
The content of authorize.bash
Code: Select all
#!/bin/bash
# Getting Domoticz user variables
JMESSAGES=$( curl -sS "https://api.telegram.org/bot$TelegramBotToken/getUpdates" )
# Getting Telegram Bot last messages
DOMOVAR=$( curl -sS "http://$DomoticzIP:$DomoticzPort/json.htm?type=command¶m=getuservariables")
# Parsing User variable "TelegramBotWhiteListedIDs" Value and IDX
DOMOVAR_VAL=$( echo $DOMOVAR | jq -c '.result[]|select(.Name == "TelegramBotWhiteListedIDs").Value' | sed "s/\"//g" )
DOMOVAR_IDX=$( echo $DOMOVAR | jq -c '.result[]|select(.Name == "TelegramBotWhiteListedIDs").idx' | sed "s/\"//g" )
# For each user or group chat
echo $JMESSAGES | jq -c .result[].message.chat | sort -u | while read line
do
FIRSTNAME=$( echo $line | jq -c .first_name | sed "s/\"//g" )
LASTNAME=$( echo $line | jq -c .last_name | sed "s/\"//g" )
USERNAME=$( echo $line | jq -c .username | sed "s/\"//g" )
GROUPTITLE=$( echo $line | jq -c .title | sed "s/\"//g" )
CHATID=$( echo $line | jq -c .id | sed "s/\"//g" )
# Gessing if it's a user or a group chat
if [[ $GROUPTITLE == "null" ]]
then
DESTNAME="user $FIRSTNAME $LASTNAME, $USERNAME with chat id : \"$CHATID\""
else
DESTNAME="group $GROUPTITLE with chat id : \"$CHATID\""
fi
# Is the CHATID already authorized?
if [ $( echo "|$DOMOVAR_VAL|" | sed "s/\"/\|/g" | grep "|$CHATID|" | wc -l ) -eq 1 ]
then
echo "The $DESTNAME is already authorized"
else
echo "Adding $DESTNAME to $DOMOVAR_VAL"
DOMOVAR_VAL="$DOMOVAR_VAL|$CHATID"
curl -sS "http://$DomoticzIP:$DomoticzPort/json.htm?type=command¶m=updateuservariable&idx=$DOMOVAR_IDX&vname=TelegramBotWhiteListedIDs&vtype=2&vvalue=$DOMOVAR_VAL" | jq -c .status
fi
done
-
- 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
All my temperature sensors return Humidity as well, so it always works for me, , obviously not all temperature sensors do, the code needs to check the type of the sensor and then only return humidity from ones that do. If you replace these routines in temperature.lua with the code below, then it should work ok:MacJL wrote:Hello,
I have this error when trying to obtain temperature :
Code: Select all
/usr/bin/lua5.2: /home/pi/dtgbot/lua//temperature.lua:31: attempt to concatenate global 'Humidity' (a nil value) stack traceback: /home/pi/dtgbot/lua//temperature.lua:31: in function 'temperature' /home/pi/dtgbot/lua//temperature.lua:44: in function 'handler' /home/pi/dtgbot/dtgbot.lua:293: in function 'HandleCommand' /home/pi/dtgbot/dtgbot.lua:400: in function 'on_msg_receive' /home/pi/dtgbot/dtgbot.lua:490: in main chunk [C]: in ?
Code: Select all
function get_temperature(DeviceName)
idx = idx_from_name(DeviceName,'devices')
if idx == nil then
return DeviceName, -999, -999, 0
end
-- Determine temperature
t = server_url.."/json.htm?type=devices&rid=" .. idx
print ("JSON request <"..t..">");
jresponse, status = http.request(t)
decoded_response = JSON:decode(jresponse)
result = decoded_response["result"]
record = result[1]
Temperature = record["Temp"]
if record["Type"] == "Temp + Humidity" then
Humidity = record["Humidity"]
else
Humidity = -999
end
LastUpdate = record["LastUpdate"]
DeviceName = record["Name"]
return DeviceName, Temperature, Humidity, LastUpdate;
end
function temperature(DeviceName)
local response = ""
DeviceName, Temperature, Humidity, LastUpdate = get_temperature(DeviceName)
if Temperature == -999 then
print(DeviceName..' does not exist')
return 1, DeviceName..' does not exist'
end
if Humidity ~= -999 then
print(DeviceName .. ' temperature is ' .. Temperature .. '°C and relative humidity is ' .. Humidity .. '%')
response = DeviceName.. ' ' .. Temperature .. '°C & ' .. Humidity .. '%'
else
print(DeviceName .. ' temperature is ' .. Temperature .. '°C')
response = DeviceName.. ' ' .. Temperature .. '°C'
end
return status, response;
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
-
- 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
Great piece of bashing, my only hesitation is that it adds another dependency to jq that I am sort of keen to remove just because it is not immediately available in Raspberry Pi repository, I am tempted to translate your code into Lua and include it as new command for the bot, i.e. if either you have no whitelisted ids or your id is already whitelisted, then command /whitelist 10 would whitelist any ids that have been recieved in the last 10 minutes.MacJL wrote:I have created a simple script that add the chat ids to telegram TelegramBotWhiteListedIDs user variable.
The steps :
- Spoiler: show
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
- bizziebis
- Posts: 182
- Joined: Saturday 19 October 2013 14:00
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 3.8805
- Location: The Netherlands
- Contact:
Re: dtgbot - Domoticz TeleGram BOT
Is dtgbot Raspberry only? I followed your steps but get :
Edit: Nevermind, I see I have to find them myself and compile. Maybe next time
Code: Select all
//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: cannot open shared object file: No such file or directory
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/pi/dtgbot/dtgbot.lua:65: in main chunk
[C]: in ?
-
- 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
What system are you on? You may find they are available to install from the system repository or compilation shouldn't be too difficult.bizziebis wrote:Is dtgbot Raspberry only? I followed your steps but get :Edit: Nevermind, I see I have to find them myself and compile. Maybe next time
- Spoiler: show
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: 51
- Joined: Tuesday 22 April 2014 22:17
- Target OS: OS X
- Domoticz version: Beta
- Location: France
- Contact:
Re: dtgbot - Domoticz TeleGram BOT
Still the same issue with this update. In fact, this sensor is a not a temperature only sensor, but a temperature + Humidity + barometer sensor. If you need more logs, I can provides them.simonrg wrote: All my temperature sensors return Humidity as well, so it always works for me, , obviously not all temperature sensors do, the code needs to check the type of the sensor and then only return humidity from ones that do. If you replace these routines in temperature.lua with the code below, then it should work ok:I have updated the master branch in github with these corrections, thanks.
- Spoiler: show
-
- 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
There is a new version on github now.MacJL wrote:Still the same issue with this update. In fact, this sensor is a not a temperature only sensor, but a temperature + Humidity + barometer sensor. If you need more logs, I can provides them.
- Spoiler: show
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: 51
- Joined: Tuesday 22 April 2014 22:17
- Target OS: OS X
- Domoticz version: Beta
- Location: France
- Contact:
Re: dtgbot - Domoticz TeleGram BOT
Thanks!
Ther is no mare crashes, but it reply 'Salon does not exist', even If ther is a Temp Sensor that is called 'Salon'.It seems to be the fact that I have two devices which are called Salon : A temperature Sensor, and a switch :
Maybe you should send a reply for each device with the same name, instead of just the last one?
Ther is no mare crashes, but it reply 'Salon does not exist', even If ther is a Temp Sensor that is called 'Salon'.It seems to be the fact that I have two devices which are called Salon : A temperature Sensor, and a switch :
Code: Select all
.{"ok":true,"result":[]}
.{"ok":true,"result":[{"update_id":726956523,
"message":{"message_id":249,"from":{"id":34862038,"first_name":"Jean-Laurent","last_name":"Girod","username":"macjl"},"chat":{"id":34862038,"first_name":"Jean-Laurent","last_name":"Girod","username":"macjl"},"date":1440071800,"text":"\/temperature Salon"}}]}
Message: 1
update_id 726956523
/temperature Salon
No on WhiteList: 2
WhiteList: xxxxxxxxxx
Handle command function started with /temperature Salon and xxxxxxxxxx
JSON request <http://127.0.0.1:8080/json.htm?type=devices&order=name>
25
58
JSON request <http://127.0.0.1:8080/json.htm?type=devices&rid=58>
Salon does not exist
https://api.telegram.org/botxxxxxx:xxxxxx/sendMessage?timeout=60&chat_id=xxxxxx&reply_to_message_id=249&text=Salon+does+not+exist
200
Succesfully handled incoming request
TelegramBotOffset 726956524
JSON request <http://127.0.0.1:8080/json.htm?type=command¶m=updateuservariable&idx=2&vname=TelegramBotOffset&vtype=integer&vvalue=726956524>
-
- 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
For time being if you change the name of the temperature sensor would be easiest.MacJL wrote:Thanks!
Ther is no mare crashes, but it reply 'Salon does not exist', even If ther is a Temp Sensor that is called 'Salon'.It seems to be the fact that I have two devices which are called Salon : A temperature Sensor, and a switch :
Maybe you should send a reply for each device with the same name, instead of just the last one?
- Spoiler: show
In the long term I should really make the logic deal with multiple names, but it has implications for other parts of the code, so needs a little bit of thought.
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
Can anyone help with this. A couple of days ago I installed the new TelegramBot from simonrg. Everything went very well and works fine now.
Now I tried to do the same for my parents, but the dtgbot doesn't start up. With the command: sudo service dtgbot start, it says: Starting Telegram....
But nothing happens. When I try: sudo service dtgbot status it says: dtgbot is not running.
This is my log fil:
What went wrong? I can send messages to the id's with http, so my bot is working, only the dtgbot isn't.
Thnx!
Now I tried to do the same for my parents, but the dtgbot doesn't start up. With the command: sudo service dtgbot start, it says: Starting Telegram....
But nothing happens. When I try: sudo service dtgbot status it says: dtgbot is not running.
This is my log fil:
Code: Select all
/usr/bin/lua5.2: /home/pi/dtgbot/dtgbot.lua:291: bad argument #1 to 'lower' (string expected, got nil)
stack traceback:
[C]: in function 'lower'
/home/pi/dtgbot/dtgbot.lua:291: in function 'HandleCommand'
/home/pi/dtgbot/dtgbot.lua:400: in function 'on_msg_receive'
/home/pi/dtgbot/dtgbot.lua:490: in main chunk
[C]: in ?
Thnx!
- G3rard
- Posts: 669
- Joined: Wednesday 04 March 2015 22:15
- Target OS: -
- Domoticz version: No
- Location: The Netherlands
- Contact:
Re: dtgbot - Domoticz TeleGram BOT
Did you try the chmod as described in this post http://www.domoticz.com/forum/viewtopic ... 279#p49972
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
Yes, everything has it's rights
-
- Posts: 29
- Joined: Wednesday 18 June 2014 23:57
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Netherlands
- Contact:
Re: dtgbot - Domoticz TeleGram BOT
Yep! And tried to remove everything and start over, but that also doesn't work.
Edit1:
I think it does have something to do with authorization. Check both images. One of them is mine and one of them are my parents. I don't know in which authorization I have to look.
Edit2: I think it works now. The uservariable in domoticz was set on 1. When I changed it to 2 it started. After that I've got a lot of messages till it crashed again. I requested the latest integer uservariable and changed it 1 higher. After that it's still working. Hope for a long time!
Thnx for thinking. Maybe it was helpful to other people.
Edit1:
I think it does have something to do with authorization. Check both images. One of them is mine and one of them are my parents. I don't know in which authorization I have to look.
Edit2: I think it works now. The uservariable in domoticz was set on 1. When I changed it to 2 it started. After that I've got a lot of messages till it crashed again. I requested the latest integer uservariable and changed it 1 higher. After that it's still working. Hope for a long time!
Thnx for thinking. Maybe it was helpful to other people.
- Attachments
-
- Knipsel1.PNG (10.97 KiB) Viewed 4143 times
-
- Knipsel.PNG (9.17 KiB) Viewed 4143 times
-
- 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
The message shows unauthorized response from Domoticz, it looks like your Domoticz needs authentication, so not really a Telegram issue.Slayer007 wrote:Yep! And tried to remove everything and start over, but that also doesn't work.
Edit1:
I think it does have something to do with authorization. Check both images. One of them is mine and one of them are my parents. I don't know in which authorization I have to look.
Edit2: I think it works now. The uservariable in domoticz was set on 1. When I changed it to 2 it started. After that I've got a lot of messages till it crashed again. I requested the latest integer uservariable and changed it 1 higher. After that it's still working. Hope for a long time!
Thnx for thinking. Maybe it was helpful to other people.
Which uservariable did you change?
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
Who is online
Users browsing this forum: No registered users and 0 guests