• Categories
  • Recent
  • Tags
  • Popular
  • Register
  • Login
  • Categories
  • Recent
  • Tags
  • Popular
  • Register
  • Login

Telegram notification

Scheduled Pinned Locked Moved Developers Zone
4 Posts 2 Posters 1.6k Views 2 Watching
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    cimba007
    last edited by cimba007 20 Oct 2017, 21:29

    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}}
    
    1 Reply Last reply Reply Quote 0
    • C Offline
      cimba007
      last edited by 22 Oct 2017, 15:28

      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!

      J 1 Reply Last reply 22 Oct 2017, 18:39 Reply Quote 0
      • J Offline
        jkandasa @cimba007
        last edited by 22 Oct 2017, 18:39

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

        1 Reply Last reply Reply Quote 0
        • J Offline
          jkandasa
          last edited by 7 Aug 2018, 02:12

          @cimba007 just updating this topic. now we have built-in support for the telegram notification.
          https://forum.mycontroller.org/topic/312/send-telegram-bot-message

          1 Reply Last reply Reply Quote 0
          • First post
            Last post

          0

          Online

          589

          Users

          529

          Topics

          3.4k

          Posts
          Copyright © 2015-2025 MyController.org | Contributors | Localization