Send notification from Python automation

  • Platform information:
    • Hardware: Intel core i3
    • OS: linux debian
    • Java Runtime Environment: 21
    • openHAB version:

Hello,

I’m writing a rule in python that send a notification. In documentation I can’t find detailed information.
I just find how to notify the app.

This is my import:
from openhab.actions import NotificationAction

then in the rule i use:

NotificationAction.sendNotification(“``test@test.org``”, “Window is open”)

But I got an error.

How can I send mail, xmmp or Telegram?

Thanks

What error? You’ve installed and configured the openHAB Cloud Connector add-on?

Install and configure the Mail binding and use the actions as described in the docs.

Same as for mail. Install the xmppClient (I assume xmpp is what you mean) add-on or Telegram add-on and configure and use them as covered in their docs.

Hi,

I’ve done some test.

For example this is my Mail configuration:

       mail = Mail.getActions("mail:smtp:samplesmtp")
       mail.sendMail(mail_address, obj, message)

and this is the error:

2025-10-24 16:39:27.145 [ERROR] [ting.notification.notification_mirko] - Rule execution failed:
Traceback (most recent call last):
File “/openhab/conf/automation/python/lib/openhab/helper.py”, line 208, in executeWrapper
status = rule_obj(module, input)
^^^^^^^^^^^^^^^^^^^^^^^
File “/openhab/conf/automation/python/notification.py”, line 280, in notification_mirko
mail = Mail.getActions(“mail:smtp:samplesmtp”)
^^^^
NameError: name ‘Mail’ is not defined

I’ve added this import:

from openhab.actions import NotificationAction, Mail

but is not correct

2025-10-24 16:44:41.701 [ERROR] [tion.pythonscripting.notification.py] - Traceback (most recent call last):2025-10-24 16:44:41.713 [ERROR] [tion.pythonscripting.notification.py] -   File “/openhab/conf/automation/python/notification.py”, line 7, in from openhab.actions import NotificationAction, Mail2025-10-24 16:44:41.715 [ERROR] [tion.pythonscripting.notification.py] - ImportError, cannot import name ‘Mail’ from ‘openhab.actions’ (/openhab/conf/automation/python/lib/openhab/actions.py)2025-10-24 16:44:41.716 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script ‘/openhab/conf/automation/python/notification.py’: null in /openhab/conf/automation/python/notification.py at line number 1 at column number 1

Thanks

You’ve installed the binding? You’ve configured an SNMP Thing?

All Thing Actions work the same way. You need to “get” them based on the Thing ID.

According to the docs,

The scope module encapsulates all default jsr223 objects/presents (opens new window)into a new object.

The ScriptThingActions Object is part of that preset under the variable name actions. So you need to import all the presets:

from scope import *

or just import actions:

from scope import actions

Once imported, all Thing Actions are acquired the same way:

mail = actions.get("name of binding", "UID of Thing")

Relevant docs:

Some actions are built in. See Python Scripting - Automation | openHAB and Actions | openHAB.

I don’t know how modules are imported and used in the new Python add-on. What ever you do for openhab.triggers, do the same for openhab.actions to use them.

only openHAB Core Actions are available via the actions module.

Binding related actions must be used via the scope.actions module.

I changed the README right now to make this more clear.

btw. if you use the marketplace pythonscripting next, which is a huge step forward, you should read the following documentations

Python Scripting API

Python Scripting Automation AddOn

1 Like

What’s the difference? Is the “next” version what’s currently in snapshot, but made avaiable for 5.0.x through the marketplace?

yes, the pythonscripting next is only available for openHAB >= 5.0.x and < 5.1.x

for openHAB >= 5.1.x, I will create a new marketplace version as soon as it is needed.

The idea of “pythonscripting next” is, that it contains all changes which are not merged yet, but stable enough for daily usage.

There is also a version for openHAB 4.3.x, based on the same codebase. But this is beta, because some changes in openHAB Core are missing, which are only available in openHAB >= 5.x.x

Thank you for the clear example.

So if i need Telegram notification I just do:

telegramAction = actions.get(“telegram”,“telegram:telegramBot:sampleTelegram_Bot”)

telegramAction.sendTelegram(message)

or for XMPP:

xmppAction = actions.get(“xmppclient”,“xmppclient:xmppBridge:xmpp”)

xmppAction.publishXMPP(“test@example.com”, message)

But how can I send a notification to openHab Android app?

Thanks

from openhab.actions import NotificationAction

NotificationAction.sendNotification("user@email.com", "testmessage")