Telegram notification



  • Hello,

    as I am currently out of pushes on pushbullet .. I tried to implement Telegram-API with Telegram-Bot via python and scripting.

    • Step 1: Download jython-standalone from http://www.jython.org/downloads.html
    • Step 2: Place under /home/pi/mycontroller/lib/jython-standalone-2.7.0.jar
    • Step 3: Install "pip install python-telegram-bot" on your raspberrypi
    • Step 4: Sign up on Telegram (Android)
    • Step 5: Register your bot with Botfather (https://core.telegram.org/bots#)
    • Step 6: After registering with Botfather you get an API-Key (further here described as APIKEY)
    • Step 7: Place a file telegram_min.py anywhere (https://pastebin.com/v6gZJqEp) and replace APIKEY
    • Step 8: Go to the chat_id bot mentioned here (https://stackoverflow.com/a/37396871). You need the CHAT_ID for your account.
    • Step 9: Create a mycontroller-python-script under "Utilitys->Script". As I have no idea how to install python-telegram-bot with jython I got a workaround.
    import commands
    commands.getstatusoutput('/usr/bin/python /home/pi/mqtt/telegram_min.py -i **CHAT_ID** -m '+message+'Test')
    commands = None
    

    This is how far I got .. if I manually run the script manually with the binding:

    {"message":"Test1234"}
    

    I get following message on my Telegram Desktop client:

    0_1508534653162_86c91fbf-7d5f-44bd-8f40-89bf6b6981a1-image.png

    This is good so far!!!

    But now I need your help @jkandasa

    What I want to do ..

    • Depending on a sensor value a rule should be triggered
    • The rule will trigger an operation

    My problem is now, that I only can define a script-binding on the operation that is no related to the rule-paraeters.

    0_1508534816665_384f4a80-7e4e-4408-871b-dc2bb2493865-image.png

    In the script or binding I would like to use

    0_1508534964152_3938616e-422d-4a38-9a8b-778ba2845579-image.png

    Currently I dont know how to use them in jython-script .. any idea?

    I tried to use notification-varaible but it does not work:

    2017-10-20 23:34:28,096 ERROR [Thread-6] [org.mycontroller.standalone.operation.model.OperationExecuteScript:133] Exception on McScript(engineName=null, mimeType=null, extension=py, name=/home/pi/mycontroller/conf/resources/scripts/operations/telegram_bot.py, canonicalPath=null, type=OPERATION, size=0, lastModified=0, bindings={message=Test})
    javax.script.ScriptException: NameError: name 'notification' is not defined in <script> at line number 2
    

    I would like to use this on binding:

    {"message":${notification.actualValue}}
    


  • I have currently doployed a workaround:

    • For every sensor there is a rule to fire when an event occurs
    • For every rule there is one operation
    • Each operation calls the same script with different Script bindings

    There are still several timers to enable/disable the operation(s)

    Latest telegram_min.py (https://pastebin.com/2BfqnmU3)
    Latest telegrom_bot.py (scriopt for mycontroller):

    import commands
    if picture is not None:
       commands.getstatusoutput('/usr/bin/python /home/pi/mqtt/telegram_min.py -i CHAT_ID -m "' + message + ' " -p "' + picture + '" ' )
       commands = None
    else:
       commands.getstatusoutput('/usr/bin/python /home/pi/mqtt/telegram_min.py -i CHAT_ID  -m "' + message + '" ')
       commands = None
    

    With this solution I am able to send pictures too!


  • ADMIN

    @cimba007 Sorry for the late response. Kindly create an issue for this support.


 

10
Online

2.2k
Users

302
Topics

1.8k
Posts

Looks like your connection to MYCONTROLLER.ORG was lost, please wait while we try to reconnect.