Ok.
Same error.
Use Telegram for notifications
Ok.
Same error.
are you using commandline or have you created a rule in pimatic??
For commandline my previous post should work, if tokens are correct.
If you have created a rule you should escape the “” like so:
execute "python /pathtoscript/script.py \"Notification!!!!!\" "
At the moment I try at first the command line.
In Pimatic I have the same error.
But I give up with telegram and use Pushbullet for the message.
Do you run the telegram bot as normal user or root?
As normal “pi” user, without sudo.
I just moved from an RPI B+ to an RPi 3 and forgot some backups to make.
So from the top of my head: If you installed the telegram bot as root, you also need to execute the commands as root.
OK, now I found the mistake from me.
#!/usr/bin/python
import sys
import re
import telepot
message=(sys.argv)[1]
print message
#print "argumentlist: ",str(sys.argv)
bot=telepot.Bot(‘YOURBOTTOKEN’)
bot.sendMessage(YOURID,str(message))`
Make sure to edit the YOURBOTTOKEN and YOURID.
Is that right, BotFather tells you the YOURID:YOURBOTTOKEN (like 543211234:AAGFzMGmGC0Ho4jgxxxxxxxxJbEoWnkiPg)?
NO!!! This is wrong!
YOURBOTTOKEN is the complete Token, like:
543211234:AAGFzMGmGC0Ho4jgxxxxxxxxJbEoWnkiPg
YOURID is your chatroom ID!!!
That was my mistake.
btw, ist works without sudo or root.
python telegram.py test12234
I’m going to try this another way. I’m currently experimenting with Node-Red. The are telegram nodes for node-red available that make it possible to send and receive messages and act upon them. Communication from Node-Red to pimatic can be set up with mqqt (Mosquito).
Hi there,
i do it like you say and tested already to send me a messages it works, but if i use script i get a error:
pi@Leetwerkberry:~ $ python telepot_bot.py "test"
test
Traceback (most recent call last):
File “telepot_bot.py”, line 4, in <module>
import telepot
File “/home/pi/telepot.py”, line 8, in <module>
AttributeError: ‘module’ object has no attribute ‘Bot’
my Script (i anonymized my IDs):
#!/usr/bin/python
import sys
import re
import telepot
message=(sys.argv)[1]
print message
#print "argumentlist: ",str(sys.argv)
bot = telepot.Bot(‘MYBOT:ID’)
bot.sendMessage(MYID,str(message))
@tehmilcho did you install telepot?
sudo pip install telepot
Also interesting to know if the script runs from commandline?
@Stokstaart said in Use Telegram for notifications:
@tehmilcho did you install telepot?
sudo pip install telepot
Also interesting to know if the script runs from commandline?
oh i found the Problem from a frist test there wars a “telepot.pyc” in my folder “/home/pi” so he used this … i deleted now and now it works…
@tehmilcho Good to hear you got it working!
@Stokstaart :
Just as a remark: This is about the telegram bot system/api using the python telepot program on your system.
It does not require telegram itself at all on your raspberry pi. Of course you need telegram on your phone, pc or as webclient to inform all subscribed users.
Maybe it is good to mention this in the first topic as that starts with "For my system I use Telegram messenger for notifications."
Actually that is not correct. You use it to receive messages and you use a bot to send messages.
Another addition to your top mentioned script I made 2-3 weekends ago is the option to send a message to a variable number of users (and it will never be more than a few of course).
#!/usr/bin/python
import sys, re, telepot
message=(sys.argv)[1]
#print message
bot=telepot.Bot('MYBOT-ID')
for arg in sys.argv:
#print arg
if (arg == "Harry"):
# The 123456789 is my personal telegram id coupled to my mobile
bot.sendMessage(123456789,str(message))
if (arg == "Margreet"):
# The 987654321 is the personal telegram id coupled to wife's mobile
bot.sendMessage(987654321,str(message))
Of course the chat ids are fake.
The first argument is always the message. Other arguments are users. I named my script “telepot-send.py”.
I can send for example:
/usr/local/bin/telepot-send.py "Motion sensor triggered in garage" Harry Margreet
or
/usr/local/bin/telepot-send.py "Freezer too warm." Margreet
or
/usr/local/bin/telepot-send.py "Central heating espimatic seems off line." Harry
The script simply loops through the arguments. If it finds a user it sends the message to that user. If I use “harry” instead of “Harry” it will not send as linux is case-sensitive.
It is an extremely simple script which can easilby be extended with another if-statement.
Edit: What I forgot to mention, because I don’t use it, is the use of a channel as user. A channel is the telegram equivalent of a whatsapp group.
So something like:
if (arg == "MyBotChannel"):
bot.sendMessage(111111111,str(message))
Hi, you can also use MQTT Warn (not only for telegram) - https://github.com/jpmens/mqttwarn#telegram
http://jpmens.net/2014/02/17/introducing-mqttwarn-a-pluggable-mqtt-notifier/
Pimatic = Smart Home
That’s a nice one too, but not as simple as telepot. And I completely stopped using MQTT
hi,
just a litte Tipp… maybe all of you know this already but for me wars new.
If you want the send a Message like this:
Weather::
Temp: X c
Humdity x %
You can do this with the Script, you must use a “\n” in your Message.
Example:
execute "python /home/pi/YOURSCRIPT.py "Weather: \n Temp; $your_value \n Humdity: $your_value " "
Did anyone already discovered this library for the esp8266?
pimatic v0.9 has been released!
Support Pimatic and get some free stickers
Like us on Facebook
make it so !