# Sending a Telegram Message from within a createTimer Interrupt

**URL:** <https://community.openhab.org/t/sending-a-telegram-message-from-within-a-createtimer-interrupt/136405>\
**Category:** Beginners\
**Tags:** jsr223-python\
**Created:** [June 3, 2022, 10:18pm UTC](https://community.openhab.org/t/sending-a-telegram-message-from-within-a-createtimer-interrupt/136405 "2022-06-03T22:18:09Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mr-JR](https://community.openhab.org/user_avatar/community.openhab.org/mr-jr/32/75347_2.png) [@Mr-JR](https://community.openhab.org/u/Mr-JR)\
**Post date:** [June 3, 2022, 10:18pm UTC](https://community.openhab.org/t/sending-a-telegram-message-from-within-a-createtimer-interrupt/136405/1 "2022-06-03T22:18:09Z")

</div>

Running Openhabian on pi 4  
openHAB 3.2.0.M4

I am monitoring temperature reports from my zigbee devices to watch for devices that stop reporting temperature in a period of time, which would then send a Telegram Chat notification (possibly the device battery is dead or the device is offline)

I am wondering how my code is causing Telegram to generate the following exception error …

```auto
2022-06-03 14:13:12.172 [WARN] [jsr223.jython.Battery Check] - Device report timeout for LaundryRoom_Temperature
2022-06-03 14:13:12.280 [INFO] [223.jython.Device Temperature Report] - Restarting timer for LaundryRoom_Temperature
2022-06-03 14:13:12.282 [WARN] [gram.internal.action.TelegramActions] - Exception occured whilst sending message:java.io.InterruptedIOException
2022-06-03 14:13:12.284 [WARN] [gram.internal.action.TelegramActions] - Exception occured whilst sending message:java.io.InterruptedIOException: interrupted
2022-06-03 14:13:12.286 [INFO] [jsr223.jython.Notifications] - Sent an Normal telegram: LaundryRoom_Temperature: No response in 1 minutes

```

The code is essentially:

```auto
tempReportTimers = {}
REPORT_TIMEOUT = 1 * 60 # seconds

@rule("Device Temperature Report", description="Monitors devices that stop reporting temperature changes, assume they are dead and report")
@when("Member of Temperature_Group changed")
def rTemperatureReport(event):
    global tempReportTimers

    device = event.itemName

    if(device in tempReportTimers): # Has this device reported previously? i.e. a timer already exists
        if (tempReportTimers[device] is not None):
            rTemperatureReport.log.info("Restarting timer for " + str(device))
            tempReportTimers[device].cancel()
    else:
        rTemperatureReport.log.info("Initializing 1st timer for " + str(device))
        pass

    tempReportTimers[device] = ScriptExecution.createTimer(ZonedDateTime.now().plusSeconds(REPORT_TIMEOUT), lambda: deviceWarning(device))

def deviceWarning(device):

    log.warn("Device report timeout for " + str(device))
    sendNotification(str(device) + ": No response in " + str(REPORT_TIMEOUT/60) + " minutes")

```

SendNotification is a wrapper for the Telegram that results in a telegramAction.sendTelegram(msg)

Question: Is there an issue with calling telegramAction.sendTelegram(msg) from within the Timer Interrupt function?

Code seems to work fine if I remove the SendNotification. I am purposely setting the REPORT\_TIMEOUT to 60 seconds while I am testing … I plan to normally have it in the 30-60 minute timeframe. The short timer might be problematic too since you can see in the log a Temp report from the device comes milliseconds after the timer expires (shouldn’t be an issue, but might be)

Any ideas?
