New Telegram Binding - Tester and Feedback welcome

Is this binding available in M5 or is it going to be available in the upcoming final release?

See 58. in openHAB Milestone builds
It is available in M5.

1 Like

Hi!
openHAB 2.5.0 Build #1761
Installation for the first time, before this binding did not install. In paperUI click install ā€¦
log:

2019-11-21 19:59:48.501 [ERROR] [core.karaf.internal.FeatureInstaller] - Failed installing 'openhab-binding-telegram': Error:
	Error downloading wrap:file:/var/lib/openhab2/tmp/mvn/com/squareup/okio/okio/1.15.0/okio-1.15.0.jar
	Error downloading wrap:file:/var/lib/openhab2/tmp/mvn/com/squareup/okio/okio/1.15.0/okio-1.15.0.jar
	Error downloading wrap:file:/var/lib/openhab2/tmp/mvn/com/squareup/okhttp3/logging-interceptor/3.12.3/logging-interceptor-3.12.3.jar
	Error downloading wrap:file:/var/lib/openhab2/tmp/mvn/com/squareup/okhttp3/logging-interceptor/3.12.3/logging-interceptor-3.12.3.jar
	Error downloading wrap:file:/var/lib/openhab2/tmp/mvn/com/github/pengrad/java-telegram-bot-api/4.4.0/java-telegram-bot-api-4.4.0.jar
	Error downloading wrap:file:/var/lib/openhab2/tmp/mvn/com/github/pengrad/java-telegram-bot-api/4.4.0/java-telegram-bot-api-4.4.0.jar
	Error downloading wrap:file:/var/lib/openhab2/tmp/mvn/com/squareup/okhttp3/okhttp/3.12.3/okhttp-3.12.3.jar
	Error downloading wrap:file:/var/lib/openhab2/tmp/mvn/com/squareup/okhttp3/okhttp/3.12.3/okhttp-3.12.3.jar
	Error downloading wrap:file:/var/lib/openhab2/tmp/mvn/com/squareup/okio/okio/1.15.0/okio-1.15.0.jar
	Error downloading wrap:file:/var/lib/openhab2/tmp/mvn/com/squareup/okio/okio/1.15.0/okio-1.15.0.jar
	Error downloading wrap:file:/var/lib/openhab2/tmp/mvn/com/github/pengrad/java-telegram-bot-api/4.4.0/java-telegram-bot-api-4.4.0.jar
	Error downloading wrap:file:/var/lib/openhab2/tmp/mvn/com/github/pengrad/java-telegram-bot-api/4.4.0/java-telegram-bot-api-4.4.0.jar
	Error downloading wrap:file:/var/lib/openhab2/tmp/mvn/com/squareup/okhttp3/okhttp/3.12.3/okhttp-3.12.3.jar
	Error downloading wrap:file:/var/lib/openhab2/tmp/mvn/com/squareup/okhttp3/okhttp/3.12.3/okhttp-3.12.3.jar
	Error downloading wrap:file:/var/lib/openhab2/tmp/mvn/com/squareup/okhttp3/logging-interceptor/3.12.3/logging-interceptor-3.12.3.jar
	Error downloading wrap:file:/var/lib/openhab2/tmp/mvn/com/squareup/okhttp3/logging-interceptor/3.12.3/logging-interceptor-3.12.3.jar

and so every 4 minutes.
in papierUI:

\192.168.215.3\oh-userdata\config\org\openhab\addons.config:

:org.apache.felix.configadmin.revision:=L"20"
binding=",miio,exec,network,expire1,networkupstools,telegram"
package="standard"
persistence="influxdb,mapdb"
service.pid="org.openhab.addons"
transformation="jsonpath"
ui="basic,paper,habpanel"
voice="voicerss"

What am I doing wrong?
Thanks!

Hi @Olymp, did you notice my earlier post? I thought I was only one with the problem. As a short term workaround you can also try downloading the bundle from here,

https://openhab.jfrog.io/openhab/libs-pullrequest-local/org/openhab/addons/bundles/org.openhab.binding.telegram/2.5.0-SNAPSHOT/org.openhab.binding.telegram-2.5.0-SNAPSHOT.jar

and drop it in your addons folder.

Iā€™ll link our posts forward to the M5 problem topic :+1:

Hello! Yes, I saw the post, but it didnā€™t translate correctly, my English is very poor. I apologize. Thanks for the workaround, Iā€™ll try tomorrow.

Yes, thanks again! it works.
I just could not send the image. Who could do this, tell me how, please!

telegramAction.sendTelegramPhoto("file://192.168.215.3/oh-cfg/html/network.jpg", "sent from openHAB")

log:

2019-11-22 17:00:19.903 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Send telegram with Image Item image and caption': java.net.ConnectException: Failed to connect to api.telegram.org/2001:67c:4e8:f004:0:0:0:9:443

Thanks!

Hi. I met the same question with @gitMiguelā€¦ I added the jar file manually. However, I canā€™t add telegram bot through PAPER-UI.


Canā€™t click the blue button. Did I miss something?

Iā€™m using openhab2-2.5.0~M5 and here is my addons.config:

:org.apache.felix.configadmin.revision:=L"5"
binding="network,telegram"
package="standard"
service.pid="org.openhab.addons"
ui="basic,paper,habpanel,homebuilder"

By the way, I have tried restarted the openhab2, and it didnā€™t make any difference

Iā€™ve had the same issue.
Just type in your chatID and press enter.
A dropdown should appear, where you can activate the checkbox.

After Switching from Telegram action to the new Telegram binding I get a lot of messages in openhab.log:
2019-11-23 09:55:04.697 [WARN ] [ng.telegram.internal.TelegramHandler] - Telegram exception: GetUpdates failed with error_code 409 Conflict: terminated by other getUpdates request; make sure that only one bot instance is running

Sending telegram messages works though.
Anyone with the same issue?

EDIT:
I am running the latest 2.5M5

Hi,

Thanks for the great binding and all the work. In general it is working for me but does somebody has any hint how an jsr223 jython rule would look like which is using the action of this binding to send telegram messages? I have some trouble with getting the right thinks imported. Something like telegram = actions.get(ā€œtelegramā€, ā€œtelegrambot:uidā€) seems to be not working within some of the python files.

Thanks for the support!

Best regards, christian

I did have problems finding out as well.
My item:
String TelegrMess ā€œTelegram Messageā€ (G_jdbc) {channel=ā€œtelegram:telegramBot:MYBOT:lastMessageTextā€}

My rule:

val action = getActions("telegram","telegram:telegramBot:MYBOT")

rule "Lights Off"
when
    Item G_Lights changed to OFF
then
	action.sendTelegram("Das Licht wurde ausgeschaltet!")
end

Hi,

Thanks for the example. Unfortunately this dosenā€™t solve the issue.

For the standard rule engine it is working for me somehow. Also for a jython rule which is located in the openhab2/automation/jsr223/personal folder. So the below code is working fine:

from org.slf4j import LoggerFactory
from core.rules import rule
from core.triggers import when

@rule("Test rule for new telegram binding")
@when("Item presence changed")
def someFunction(event):

        telegram = actions.get("telegram","telegram:telegramBot:xxxxxxx")
        telegram.sendTelegram("Hello *World* " +  u"\U0001F44D")

But if I will use some functions from openhab2/automation/lib/python/personal were I have stored my common code - it is not working anymore with the same code like above (same imports). During runtime i will get a ā€œmodule actions has no attribute getā€ error which is not the case with the previous file location.

Any ideas?

EDIT:
Iā€™ve solved the problem. For guys with the same problem. You have to add

from core.jsr223 import scope
from core.jsr223.scope import actions

to the imports if you move the file to the lib subfolder. This was missing somehow.
br, christian

@mhilbush, @waitz_sebastian and @Olymp
I re-added the functionality to send pictures via http(s) that are only reachable from your local network.
Use the ā€œfile://ā€ protocol only for files on your local hard drive.

That usually means that you are alraedy running a bot for the same token. That can for example happen if you created two things with the same bot token or you have two different OH instances running in parallel. This is not allowed by the Telegram API. If you think you have only instance running, then please try to restart OH.

I get the same error message when Iā€™m trying to install the binding directly from the M5. Copying the JAR to the addons folder works however.

Can @Kai or @J-N-K have a look if this is related to the binding or something else is missing? Thank you!

For me the installation and the binding works great and I also have installed it the first time from 2.5 M5. Iā€™m running openhabian on a Pi3.
Perhaps this info will help. br, christian

Works for me. Hereā€™s my Network check rule that uses sendTelegram(String message) method:

from time import sleep
from core.rules import rule
from core.triggers import when

#Network
@rule("NetworkCheck")
@when("Time cron 0 0 21 * * ?")
@when("Time cron 0 0 12 * * ?")
@when("Member of GrNetwork changed")

# Import new Telegram action
telegram = actions.get("telegram", "telegram:telegramBot:xxxx")

def execute(event, log):
    telegram = actions.get("telegram", "telegram:telegramBot:lanteeBot")
    if ir.getItem("GrNetwork").state == ON:
        if event:
            message = "Network fully online"
            telegram.sendTelegram(message)
            log.info(message)    
    else:
        sleep(1)
        offlineMembers = sorted(member for member in ir.getItem("GrNetwork").getMembers() if member.state == OnOffType.OFF, key = lambda member: member.state)
        message = "Network devices offline:\n\n{}".format("\n".join(item.label for item in offlineMembers))
        telegram.sendTelegram(message)
        log.info(message)

Edit
I replied too fast, sorry. You were asking about personal libraries. But Iā€™ll leave this here as an example.

Thank you very much for the example looks very good. Iā€™ve edited my post above. To move the code to the tool lib you need some more imports. Perhaps this will also help you if you want to centralize your telegram code. I spent some time to figure this out :wink:

Thanks! br, christian

1 Like

I saw that your PR was merged. Thank you very much for adding this functionality!

Thanks for your response.

I use to have the Telegram action binding active (with telgram.cfg in place).
However, I deleted the telegram.cfg as well as uninstalled the telegram action binding.

Is there something else I could check (like a zombie item or something)?

One more question:
I have set up a Telebot Thing and set the items like
String TelegrMess "Telegram Message" (G_jdbc) {channel="telegram:telegramBot:MYBOT:lastMessageText"}

Does this interfere, if I send messages to OH on the same channel I receive messages from OH?

By the way: what is the wrap file I see in karaf?

openhab> bundle:list | grep elegr
260 x Active x  80 x 2.5.0.M5                x openHAB Add-ons :: Bundles :: Telegram Binding
300 x Active x  80 x 0                       x wrap_file__var_lib_openhab2_tmp_mvn_com_github_pengrad_java-telegram-bot-api_4.4.0_java-telegram-bot-api-4.4.0.jar